syscalls.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Syscalls for uClibc
  4. *
  5. * Copyright (C) 2000 by Lineo, inc. Written by Erik Andersen
  6. * <andersen@lineo.com>, <andersee@debian.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU Library General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <errno.h>
  24. #include <features.h>
  25. #include <sys/types.h>
  26. #include <sys/syscall.h>
  27. //#define __NR_exit 1
  28. #ifdef L__exit
  29. /* Do not include unistd.h, so gcc doesn't whine about
  30. * _exit returning. It really doesn't return... */
  31. #define __NR__exit __NR_exit
  32. _syscall1(void, _exit, int, status);
  33. #endif
  34. //#define __NR_fork 2
  35. //See architecture specific implementation...
  36. //#define __NR_read 3
  37. #ifdef L_read
  38. #include <unistd.h>
  39. _syscall3(ssize_t, read, int, fd, __ptr_t, buf, size_t, count);
  40. #endif
  41. //#define __NR_write 4
  42. #ifdef L_write
  43. #include <unistd.h>
  44. _syscall3(ssize_t, write, int, fd, const __ptr_t, buf, size_t, count);
  45. #endif
  46. //#define __NR_open 5
  47. #ifdef L___open
  48. #include <stdarg.h>
  49. #include <fcntl.h>
  50. #define __NR___open __NR_open
  51. _syscall3(int, __open, const char *, fn, int, flags, mode_t, mode);
  52. int open(const char *file, int oflag, ...)
  53. {
  54. int mode = 0;
  55. if (oflag & O_CREAT) {
  56. va_list args;
  57. va_start(args, oflag);
  58. mode = va_arg(args, int);
  59. va_end(args);
  60. }
  61. return __open(file, oflag, mode);
  62. }
  63. #endif
  64. //#define __NR_close 6
  65. #ifdef L_close
  66. #include <unistd.h>
  67. _syscall1(int, close, int, fd);
  68. #endif
  69. //#define __NR_waitpid 7
  70. #include <sys/wait.h>
  71. #ifdef L_waitpid
  72. _syscall3(pid_t, waitpid, pid_t, pid, int *, status, int, options);
  73. #endif
  74. //#define __NR_creat 8
  75. #ifdef L_creat
  76. #include <fcntl.h>
  77. _syscall2(int, creat, const char *, file, mode_t, mode);
  78. #endif
  79. //#define __NR_link 9
  80. #ifdef L_link
  81. #include <unistd.h>
  82. _syscall2(int, link, const char *, oldpath, const char *, newpath);
  83. #endif
  84. //#define __NR_unlink 10
  85. #ifdef L_unlink
  86. #include <unistd.h>
  87. _syscall1(int, unlink, const char *, pathname);
  88. #endif
  89. //#define __NR_execve 11
  90. #ifdef L_execve
  91. #include <unistd.h>
  92. _syscall3(int, execve, const char *, filename, char *const *, argv,
  93. char *const *, envp);
  94. #endif
  95. //#define __NR_chdir 12
  96. #ifdef L_chdir
  97. #include <unistd.h>
  98. _syscall1(int, chdir, const char *, path);
  99. #endif
  100. //#define __NR_time 13
  101. #ifdef L_time
  102. #include <time.h>
  103. _syscall1(time_t, time, time_t *, t);
  104. #endif
  105. //#define __NR_mknod 14
  106. #ifdef L_mknod
  107. #include <unistd.h>
  108. _syscall3(int, mknod, const char *, pathname, mode_t, mode, dev_t, dev);
  109. #endif
  110. //#define __NR_chmod 15
  111. #ifdef L_chmod
  112. #include <sys/stat.h>
  113. _syscall2(int, chmod, const char *, path, mode_t, mode);
  114. #endif
  115. /* Old kernels don't have lchown -- do chown instead. This
  116. * is sick and wrong, but at least things will compile.
  117. * They may not follow links when they should though... */
  118. #ifndef __NR_lchown
  119. #define __NR_lchown __NR_chown
  120. #endif
  121. //#define __NR_lchown 16
  122. #ifdef L_lchown
  123. #include <unistd.h>
  124. _syscall3(int, lchown, const char *, path, uid_t, owner, gid_t, group);
  125. #endif
  126. #endif
  127. //#define __NR_break 17
  128. //#define __NR_oldstat 18
  129. //#define __NR_lseek 19
  130. #ifdef L_lseek
  131. #include <unistd.h>
  132. _syscall3(off_t, lseek, int, fildes, off_t, offset, int, whence);
  133. #endif
  134. //#define __NR_getpid 20
  135. #ifdef L_getpid
  136. #include <unistd.h>
  137. _syscall0(pid_t, getpid);
  138. #endif
  139. //#define __NR_mount 21
  140. #ifdef L_mount
  141. #include <sys/mount.h>
  142. _syscall5(int, mount, const char *, specialfile, const char *, dir,
  143. const char *, filesystemtype, unsigned long, rwflag,
  144. const void *, data);
  145. #endif
  146. //#define __NR_umount 22
  147. #ifdef L_umount
  148. #include <sys/mount.h>
  149. _syscall1(int, umount, const char *, specialfile);
  150. #endif
  151. //#define __NR_setuid 23
  152. #ifdef L_setuid
  153. #include <unistd.h>
  154. _syscall1(int, setuid, uid_t, uid);
  155. #endif
  156. //#define __NR_getuid 24
  157. #ifdef L_getuid
  158. #include <unistd.h>
  159. _syscall0(gid_t, getuid);
  160. #endif
  161. //#define __NR_stime 25
  162. #ifdef L_stime
  163. #include <time.h>
  164. _syscall1(int, stime, time_t *, t);
  165. #endif
  166. //#define __NR_ptrace 26
  167. //#define __NR_alarm 27
  168. #ifdef L_alarm
  169. #include <unistd.h>
  170. _syscall1(unsigned int, alarm, unsigned int, seconds);
  171. #endif
  172. //#define __NR_oldfstat 28
  173. //#define __NR_pause 29
  174. #ifdef L_pause
  175. #include <unistd.h>
  176. _syscall0(int, pause);
  177. #endif
  178. //#define __NR_utime 30
  179. #ifdef L_utime
  180. #include <utime.h>
  181. _syscall2(int, utime, const char *, filename, struct utimbuf *, buf);
  182. #endif
  183. //#define __NR_stty 31
  184. //#define __NR_gtty 32
  185. //#define __NR_access 33
  186. #ifdef L_access
  187. #include <unistd.h>
  188. _syscall2(int, access, const char *, pathname, int, mode);
  189. #endif
  190. //#define __NR_nice 34
  191. #ifdef L_nice
  192. #include <unistd.h>
  193. _syscall1(int, nice, int, inc);
  194. #endif
  195. //#define __NR_ftime 35
  196. //#define __NR_sync 36
  197. #ifdef L_sync
  198. #include <unistd.h>
  199. _syscall0(int, sync);
  200. #endif
  201. //#define __NR_kill 37
  202. #ifdef L_kill
  203. #include <signal.h>
  204. _syscall2(int, kill, pid_t, pid, int, sig);
  205. #endif
  206. //#define __NR_rename 38
  207. #ifdef L_rename
  208. #include <stdio.h>
  209. _syscall2(int, rename, const char *, oldpath, const char *, newpath);
  210. #endif
  211. //#define __NR_mkdir 39
  212. #ifdef L_mkdir
  213. #include <sys/stat.h>
  214. _syscall2(int, mkdir, const char *, pathname, mode_t, mode);
  215. #endif
  216. //#define __NR_rmdir 40
  217. #ifdef L_rmdir
  218. #include <unistd.h>
  219. _syscall1(int, rmdir, const char *, pathname);
  220. #endif
  221. //#define __NR_dup 41
  222. #ifdef L_dup
  223. #include <unistd.h>
  224. _syscall1(int, dup, int, oldfd);
  225. #endif
  226. //#define __NR_pipe 42
  227. #ifdef L_pipe
  228. #include <unistd.h>
  229. _syscall1(int, pipe, int *, filedes);
  230. #endif
  231. //#define __NR_times 43
  232. #ifdef L_times
  233. #include <sys/times.h>
  234. _syscall1(clock_t, times, struct tms *, buf);
  235. #endif
  236. //#define __NR_prof 44
  237. //#define __NR_brk 45
  238. //#define __NR_setgid 46
  239. #ifdef L_setgid
  240. #include <unistd.h>
  241. _syscall1(int, setgid, gid_t, gid);
  242. #endif
  243. //#define __NR_getgid 47
  244. #ifdef L_getgid
  245. #include <unistd.h>
  246. _syscall0(gid_t, getgid);
  247. #endif
  248. //#define __NR_signal 48
  249. //#define __NR_geteuid 49
  250. #ifdef L_geteuid
  251. #ifdef SYS_geteuid
  252. #include <unistd.h>
  253. _syscall0(uid_t, geteuid);
  254. #else
  255. uid_t geteuid(void)
  256. {
  257. return (getuid());
  258. }
  259. #endif
  260. #endif
  261. //#define __NR_getegid 50
  262. #ifdef L_getegid
  263. #ifdef SYS_getegid
  264. #include <unistd.h>
  265. _syscall0(gid_t, getegid);
  266. #else
  267. gid_t getegid(void)
  268. {
  269. return (getgid());
  270. }
  271. #endif
  272. #endif
  273. //#define __NR_acct 51
  274. #ifdef __NR_umount2 /* Old kernels don't have umount2 */
  275. //#define __NR_umount2 52
  276. #ifdef L_umount2
  277. #include <sys/mount.h>
  278. _syscall2(int, umount2, const char *, special_file, int, flags);
  279. #endif
  280. #endif
  281. //#define __NR_lock 53
  282. //#define __NR_ioctl 54
  283. #ifdef L__ioctl
  284. #include <stdarg.h>
  285. #include <sys/ioctl.h>
  286. #define __NR__ioctl __NR_ioctl
  287. _syscall3(int, _ioctl, int, fd, int, request, void *, arg);
  288. int ioctl(int fd, unsigned long int request, ...)
  289. {
  290. void *arg;
  291. va_list list;
  292. va_start(list, request);
  293. arg = va_arg(list, void *);
  294. va_end(list);
  295. return _ioctl(fd, request, arg);
  296. }
  297. #endif
  298. //#define __NR_fcntl 55
  299. #ifdef L__fcntl
  300. #include <stdarg.h>
  301. #include <fcntl.h>
  302. #define __NR__fcntl __NR_fcntl
  303. _syscall3(int, _fcntl, int, fd, int, cmd, long, arg);
  304. int fcntl(int fd, int command, ...)
  305. {
  306. long arg;
  307. va_list list;
  308. va_start(list, command);
  309. arg = va_arg(list, long);
  310. va_end(list);
  311. return _fcntl(fd, command, arg);
  312. }
  313. #endif
  314. //#define __NR_mpx 56
  315. //#define __NR_setpgid 57
  316. #ifdef L_setpgid
  317. #include <unistd.h>
  318. _syscall2(int, setpgid, pid_t, pid, pid_t, pgid);
  319. #endif
  320. //#define __NR_ulimit 58
  321. //#define __NR_oldolduname 59
  322. //#define __NR_umask 60
  323. #ifdef L_umask
  324. #include <sys/stat.h>
  325. _syscall1(mode_t, umask, mode_t, mask);
  326. #endif
  327. //#define __NR_chroot 61
  328. #ifdef L_chroot
  329. #include <unistd.h>
  330. _syscall1(int, chroot, const char *, path);
  331. #endif
  332. //#define __NR_ustat 62
  333. //#define __NR_dup2 63
  334. #ifdef L_dup2
  335. #include <unistd.h>
  336. _syscall2(int, dup2, int, oldfd, int, newfd);
  337. #endif
  338. //#define __NR_getppid 64
  339. #ifdef L_getppid
  340. #include <unistd.h>
  341. #ifdef SYS_getppid
  342. _syscall0(pid_t, getppid);
  343. #else
  344. pid_t getppid(void)
  345. {
  346. return (getpid());
  347. }
  348. #endif
  349. #endif
  350. //#define __NR_getpgrp 65
  351. #ifdef L_getpgrp
  352. #include <unistd.h>
  353. _syscall0(pid_t, getpgrp);
  354. #endif
  355. //#define __NR_setsid 66
  356. #ifdef L_setsid
  357. #include <unistd.h>
  358. _syscall0(pid_t, setsid);
  359. #endif
  360. //#define __NR_sigaction 67
  361. #ifdef L_sigaction
  362. #include <signal.h>
  363. _syscall3(int, sigaction, int, signum, const struct sigaction *, act,
  364. struct sigaction *, oldact);
  365. #endif
  366. //#define __NR_sgetmask 68
  367. //#define __NR_ssetmask 69
  368. //#define __NR_setreuid 70
  369. #ifdef L_setreuid
  370. #include <unistd.h>
  371. _syscall2(int, setreuid, uid_t, ruid, uid_t, euid);
  372. #endif
  373. //#define __NR_setregid 71
  374. #ifdef L_setregid
  375. #include <unistd.h>
  376. _syscall2(int, setregid, gid_t, rgid, gid_t, egid);
  377. #endif
  378. //#define __NR_sigsuspend 72
  379. #ifdef L_sigsuspend
  380. #include <signal.h>
  381. _syscall1(int, sigsuspend, const sigset_t *, mask);
  382. #endif
  383. //#define __NR_sigpending 73
  384. #ifdef L_sigpending
  385. #include <signal.h>
  386. _syscall1(int, sigpending, sigset_t *, set);
  387. #endif
  388. //#define __NR_sethostname 74
  389. #ifdef L_sethostname
  390. #include <unistd.h>
  391. _syscall2(int, sethostname, const char *, name, size_t, len);
  392. #endif
  393. //#define __NR_setrlimit 75
  394. #ifdef L_setrlimit
  395. #include <unistd.h>
  396. #include <sys/resource.h>
  397. _syscall2(int, setrlimit, int, resource, const struct rlimit *, rlim);
  398. #endif
  399. //#define __NR_getrlimit 76
  400. #ifdef L_getrlimit
  401. #include <unistd.h>
  402. #include <sys/resource.h>
  403. _syscall2(int, getrlimit, int, resource, struct rlimit *, rlim);
  404. #endif
  405. //#define __NR_getrusage 77
  406. #ifdef L_getrusage
  407. #include <unistd.h>
  408. _syscall2(int, getrusage, int, who, struct rusage *, usage);
  409. #endif
  410. //#define __NR_gettimeofday 78
  411. #ifdef L_gettimeofday
  412. #include <unistd.h>
  413. _syscall2(int, gettimeofday, struct timeval *, tv, struct timezone *, tz);
  414. #endif
  415. //#define __NR_settimeofday 79
  416. #ifdef L_settimeofday
  417. #include <unistd.h>
  418. _syscall2(int, settimeofday, const struct timeval *, tv,
  419. const struct timezone *, tz);
  420. #endif
  421. //#define __NR_getgroups 80
  422. #ifdef L_getgroups
  423. #include <unistd.h>
  424. _syscall2(int, getgroups, int, size, gid_t *, list);
  425. #endif
  426. //#define __NR_setgroups 81
  427. #ifdef L_setgroups
  428. #include <unistd.h>
  429. #include <grp.h>
  430. _syscall2(int, setgroups, size_t, size, const gid_t *, list);
  431. #endif
  432. //#define __NR_select 82
  433. //#define __NR_symlink 83
  434. #ifdef L_symlink
  435. #include <unistd.h>
  436. _syscall2(int, symlink, const char *, oldpath, const char *, newpath);
  437. #endif
  438. //#define __NR_oldlstat 84
  439. //#define __NR_readlink 85
  440. #ifdef L_readlink
  441. #include <unistd.h>
  442. _syscall3(int, readlink, const char *, path, char *, buf, size_t, bufsiz);
  443. #endif
  444. //#define __NR_uselib 86
  445. #ifdef L_uselib
  446. #include <unistd.h>
  447. _syscall1(int, uselib, const char *, library);
  448. #endif
  449. //#define __NR_swapon 87
  450. #ifdef L_swapon
  451. #include <sys/swap.h>
  452. _syscall2(int, swapon, const char *, path, int, swapflags);
  453. #endif
  454. //#define __NR_reboot 88
  455. #ifdef L__reboot
  456. #define __NR__reboot __NR_reboot
  457. _syscall3(int, _reboot, int, magic, int, magic2, int, flag);
  458. int reboot(int flag)
  459. {
  460. return (_reboot((int) 0xfee1dead, 672274793, flag));
  461. }
  462. #endif
  463. //#define __NR_readdir 89
  464. //#define __NR_mmap 90
  465. #ifdef L__mmap
  466. #define __NR__mmap __NR_mmap
  467. #include <unistd.h>
  468. #include <sys/mman.h>
  469. _syscall1(__ptr_t, _mmap, unsigned long *, buffer);
  470. __ptr_t mmap(__ptr_t addr, size_t len, int prot,
  471. int flags, int fd, __off_t offset)
  472. {
  473. unsigned long buffer[6];
  474. buffer[0] = (unsigned long) addr;
  475. buffer[1] = (unsigned long) len;
  476. buffer[2] = (unsigned long) prot;
  477. buffer[3] = (unsigned long) flags;
  478. buffer[4] = (unsigned long) fd;
  479. buffer[5] = (unsigned long) offset;
  480. return (__ptr_t) _mmap(buffer);
  481. }
  482. #endif
  483. //#define __NR_munmap 91
  484. #ifdef L_munmap
  485. #include <unistd.h>
  486. #include <sys/mman.h>
  487. _syscall2(int, munmap, void *, start, size_t, length);
  488. #endif
  489. //#define __NR_truncate 92
  490. #ifdef L_truncate
  491. #include <unistd.h>
  492. _syscall2(int, truncate, const char *, path, off_t, length);
  493. #endif
  494. //#define __NR_ftruncate 93
  495. #ifdef L_ftruncate
  496. #include <unistd.h>
  497. _syscall2(int, ftruncate, int, fd, off_t, length);
  498. #endif
  499. //#define __NR_fchmod 94
  500. #ifdef L_fchmod
  501. #include <sys/stat.h>
  502. _syscall2(int, fchmod, int, fildes, mode_t, mode);
  503. #endif
  504. //#define __NR_fchown 95
  505. #ifdef L_fchown
  506. #include <unistd.h>
  507. _syscall3(int, fchown, int, fd, uid_t, owner, gid_t, group);
  508. #endif
  509. //#define __NR_getpriority 96
  510. #ifdef L_getpriority
  511. #include <sys/resource.h>
  512. _syscall2(int, getpriority, int, which, int, who);
  513. #endif
  514. //#define __NR_setpriority 97
  515. #ifdef L_setpriority
  516. #include <sys/resource.h>
  517. _syscall3(int, setpriority, int, which, int, who, int, prio);
  518. #endif
  519. //#define __NR_profil 98
  520. //#define __NR_statfs 99
  521. #ifdef L_statfs
  522. #include <sys/vfs.h>
  523. _syscall2(int, statfs, const char *, path, struct statfs *, buf);
  524. #endif
  525. //#define __NR_fstatfs 100
  526. #ifdef L_fstatfs
  527. #include <sys/vfs.h>
  528. _syscall2(int, fstatfs, int, fd, struct statfs *, buf);
  529. #endif
  530. #ifndef __HAS_NO_MMU__
  531. //#define __NR_ioperm 101
  532. #ifdef L_ioperm
  533. #include <sys/io.h>
  534. syscall3(int, ioperm, unsigned, long, from, unsigned long, num, int,
  535. turn_on);
  536. #endif
  537. #endif
  538. //#define __NR_socketcall 102
  539. #ifdef L_socketcall
  540. _syscall2(int, socketcall, int, call, unsigned long *, args);
  541. #endif
  542. //#define __NR_syslog 103
  543. #ifdef L__syslog
  544. #include <unistd.h>
  545. #define __NR__syslog __NR_syslog
  546. _syscall3(int, _syslog, int, type, char *, buf, int, len);
  547. int klogctl(int type, char *buf, int len)
  548. {
  549. return (_syslog(type, buf, len));
  550. }
  551. #endif
  552. //#define __NR_setitimer 104
  553. #ifdef L_setitimer
  554. #include <sys/time.h>
  555. _syscall3(int, setitimer, enum __itimer_which, which,
  556. const struct itimerval *, new, struct itimerval *, old);
  557. #endif
  558. //#define __NR_getitimer 105
  559. #ifdef L_getitimer
  560. #include <sys/time.h>
  561. _syscall2(int, getitimer, enum __itimer_which, which, struct itimerval *, value);
  562. #endif
  563. //#define __NR_stat 106
  564. #ifdef L__stat
  565. #define __NR__stat __NR_stat
  566. #include <unistd.h>
  567. #include "statfix.h"
  568. _syscall2(int, _stat, const char *, file_name, struct kernel_stat *, buf);
  569. int stat(const char * file_name, struct libc_stat * cstat)
  570. {
  571. struct kernel_stat kstat;
  572. int result = _stat(file_name, &kstat);
  573. if (result == 0) {
  574. statfix(cstat, &kstat);
  575. }
  576. return result;
  577. }
  578. #endif
  579. //#define __NR_lstat 107
  580. #ifdef L__lstat
  581. #define __NR__lstat __NR_lstat
  582. #include <unistd.h>
  583. #include "statfix.h"
  584. _syscall2(int, _lstat, const char *, file_name, struct kernel_stat *, buf);
  585. int lstat(const char * file_name, struct libc_stat * cstat)
  586. {
  587. struct kernel_stat kstat;
  588. int result = _lstat(file_name, &kstat);
  589. if (result == 0) {
  590. statfix(cstat, &kstat);
  591. }
  592. return result;
  593. }
  594. #endif
  595. //#define __NR_fstat 108
  596. #ifdef L__fstat
  597. #define __NR__fstat __NR_fstat
  598. #include <unistd.h>
  599. #include "statfix.h"
  600. _syscall2(int, _fstat, int, filedes, struct kernel_stat *, buf);
  601. int fstat(int fd, struct libc_stat *cstat)
  602. {
  603. struct kernel_stat kstat;
  604. int result = _fstat(fd, &kstat);
  605. if (result == 0) {
  606. statfix(cstat, &kstat);
  607. }
  608. return result;
  609. }
  610. #endif
  611. //#define __NR_olduname 109
  612. #ifndef __HAS_NO_MMU__
  613. //#define __NR_iopl 110
  614. #ifdef L_iopl
  615. #include <sys/io.h>
  616. _syscall1(int, iopl, int, level);
  617. #endif
  618. #endif
  619. //#define __NR_vhangup 111
  620. #ifdef L_vhangup
  621. #include <unistd.h>
  622. _syscall0(int, vhangup);
  623. #endif
  624. //#define __NR_idle 112
  625. //int idle(void);
  626. //#define __NR_vm86old 113
  627. //#define __NR_wait4 114
  628. #ifdef L_wait4
  629. #include <sys/wait.h>
  630. _syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options,
  631. struct rusage *, rusage);
  632. #endif
  633. //#define __NR_swapoff 115
  634. #ifdef L_swapoff
  635. #include <sys/swap.h>
  636. _syscall1(int, swapoff, const char *, path);
  637. #endif
  638. //#define __NR_sysinfo 116
  639. #ifdef L_sysinfo
  640. #include <sys/sysinfo.h>
  641. _sysinfo(int, sysinfo, struct sysinfo *, info);
  642. #endif
  643. //#define __NR_ipc 117
  644. #ifdef L_ipc
  645. //_syscall6(int,ipc,unsigned int,call, int,first, int,second, int,third, void *,ptr, long, fifth);
  646. #endif
  647. //#define __NR_fsync 118
  648. #ifdef L_fsync
  649. #include <unistd.h>
  650. _syscall1(int, fsync, int, fd);
  651. #endif
  652. //#define __NR_sigreturn 119
  653. //int sigreturn(unsigned long __unused);
  654. //#define __NR_clone 120
  655. //See architecture specific implementation...
  656. //#define __NR_setdomainname 121
  657. #ifdef L_setdomainname
  658. #include <unistd.h>
  659. _syscall2(int, setdomainname, const char *, name, size_t, len);
  660. #endif
  661. //#define __NR_uname 122
  662. #ifdef L_uname
  663. #include <sys/utsname.h>
  664. _syscall1(int, uname, struct utsname *, buf);
  665. #endif
  666. //#define __NR_modify_ldt 123
  667. //#define __NR_adjtimex 124
  668. #ifdef L_adjtimex
  669. #include <sys/timex.h>
  670. _syscall1(int, adjtimex, struct timex *, buf);
  671. #endif
  672. //#define __NR_mprotect 125
  673. #ifdef L_mprotect
  674. #include <sys/mman.h>
  675. _syscall3(int, mprotect, const void *, addr, size_t, len, int, prot);
  676. #endif
  677. //#define __NR_sigprocmask 126
  678. #ifdef L_sigprocmask
  679. #include <signal.h>
  680. _syscall3(int, sigprocmask, int, how, const sigset_t *, set, sigset_t *,
  681. oldset);
  682. #endif
  683. //#define __NR_create_module 127
  684. //#define __NR_init_module 128
  685. //#define __NR_delete_module 129
  686. //#define __NR_get_kernel_syms 130
  687. //#define __NR_quotactl 131
  688. //#define __NR_getpgid 132
  689. #ifdef L_getpgid
  690. _syscall1(pid_t, getpgid, pid_t, pid);
  691. #endif
  692. //#define __NR_fchdir 133
  693. #ifdef L_fchdir
  694. #include <unistd.h>
  695. _syscall1(int, fchdir, int, fd);
  696. #endif
  697. //#define __NR_bdflush 134
  698. //#define __NR_sysfs 135
  699. //#define __NR_personality 136
  700. //#define __NR_afs_syscall 137
  701. //#define __NR_setfsuid 138
  702. #ifdef L_setfsuid
  703. SYSCALL__(setfsuid, 1)
  704. ret
  705. #endif
  706. //#define __NR_setfsgid 139
  707. #ifdef L_setfsgid
  708. SYSCALL__(setfsgid, 1)
  709. ret
  710. #endif
  711. //#define __NR__llseek 140
  712. #ifdef L__llseek
  713. _syscall5(int, _llseek, int, fd, off_t, hoff, off_t, loff, loff_t *, res,
  714. int, whence);
  715. loff_t llseek(int fd, loff_t offset, int whence)
  716. {
  717. int ret;
  718. loff_t result;
  719. ret = _llseek(fd, (off_t) (offset >> 32),
  720. (off_t) (offset & 0xffffffff), &result, whence);
  721. return ret ? (loff_t) ret : result;
  722. }
  723. #endif
  724. //#define __NR_getdents 141
  725. #ifdef L__getdents
  726. #define __NR__getdents __NR_getdents
  727. #include <unistd.h>
  728. #include <dirent.h>
  729. _syscall3(int, _getdents, int, fd, char *, dirp, size_t, count);
  730. #endif
  731. //#define __NR__newselect 142
  732. #ifdef L__newselect
  733. #include <unistd.h>
  734. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  735. fd_set *, exceptfds, struct timeval *, timeout);
  736. int select(int n, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
  737. struct timeval *timeout)
  738. {
  739. return (_newselect(n, readfds, writefds, exceptfds, timeout));
  740. }
  741. #endif
  742. //#define __NR_flock 143
  743. #ifdef L_flock
  744. #include <sys/file.h>
  745. _syscall2(int,flock,int,fd, int,operation);
  746. #endif
  747. //#define __NR_msync 144
  748. #ifdef L_msync
  749. SYSCALL__(msync, 3)
  750. ret
  751. #endif
  752. //#define __NR_readv 145
  753. #ifdef L_readv
  754. #include <sys/uio.h>
  755. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  756. count);
  757. #endif
  758. //#define __NR_writev 146
  759. #ifdef L_writev
  760. #include <sys/uio.h>
  761. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  762. count);
  763. #endif
  764. //#define __NR_getsid 147
  765. #ifdef L_getsid
  766. SYSCALL__(getsid, 1)
  767. ret
  768. #endif
  769. //#define __NR_fdatasync 148
  770. #ifdef L_fdatasync
  771. SYSCALL__(fdatasync, 1)
  772. ret
  773. #endif
  774. //#define __NR__sysctl 149
  775. //#define __NR_mlock 150
  776. #ifdef L_mlock
  777. SYSCALL__(mlock, 2)
  778. ret
  779. #endif
  780. //#define __NR_munlock 151
  781. #ifdef L_munlock
  782. SYSCALL__(munlock, 2)
  783. ret
  784. #endif
  785. //#define __NR_mlockall 152
  786. #ifdef L_mlockall
  787. SYSCALL__(mlockall, 1)
  788. ret
  789. #endif
  790. //#define __NR_munlockall 153
  791. #ifdef L_munlockall
  792. SYSCALL__(munlockall, 0)
  793. ret
  794. #endif
  795. //#define __NR_sched_setparam 154
  796. #ifdef L_sched_setparam
  797. SYSCALL__(sched_setparam, 2)
  798. ret
  799. #endif
  800. //#define __NR_sched_getparam 155
  801. #ifdef L_sched_getparam
  802. SYSCALL__(sched_getparam, 2)
  803. ret
  804. #endif
  805. //#define __NR_sched_setscheduler 156
  806. #ifdef L_sched_setscheduler
  807. SYSCALL__(sched_setscheduler, 3)
  808. ret
  809. #endif
  810. //#define __NR_sched_getscheduler 157
  811. #ifdef L_sched_getscheduler
  812. SYSCALL__(sched_getscheduler, 1)
  813. ret
  814. #endif
  815. //#define __NR_sched_yield 158
  816. #ifdef L_sched_yield
  817. SYSCALL__(sched_yield, 0)
  818. ret
  819. #endif
  820. //#define __NR_sched_get_priority_max 159
  821. #ifdef L_sched_get_priority_max
  822. SYSCALL__(sched_get_priority_max, 1)
  823. ret
  824. #endif
  825. //#define __NR_sched_get_priority_min 160
  826. #ifdef L_sched_get_priority_min
  827. SYSCALL__(sched_get_priority_min, 1)
  828. ret
  829. #endif
  830. //#define __NR_sched_rr_get_interval 161
  831. #ifdef L_sched_rr_get_interval
  832. SYSCALL__(sched_rr_get_interval, 2)
  833. ret
  834. #endif
  835. //#define __NR_nanosleep 162
  836. #ifdef L_nanosleep
  837. SYSCALL__(nanosleep, 2)
  838. ret
  839. #endif
  840. //#define __NR_mremap 163
  841. #ifdef L_mremap
  842. #include <unistd.h>
  843. #include <sys/mman.h>
  844. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t,
  845. new_size, int, may_move);
  846. #endif
  847. //#define __NR_setresuid 164
  848. //#define __NR_getresuid 165
  849. //#define __NR_vm86 166
  850. //#define __NR_query_module 167
  851. //#define __NR_poll 168
  852. #ifdef L_poll
  853. SYSCALL__(poll, 3)
  854. ret
  855. #endif
  856. //#define __NR_nfsservctl 169
  857. //#define __NR_setresgid 170
  858. //#define __NR_getresgid 171
  859. //#define __NR_prctl 172
  860. //#define __NR_rt_sigreturn 173
  861. //#define __NR_rt_sigaction 174
  862. //#define __NR_rt_sigprocmask 175
  863. //#define __NR_rt_sigpending 176
  864. //#define __NR_rt_sigtimedwait 177
  865. //#define __NR_rt_sigqueueinfo 178
  866. //#define __NR_rt_sigsuspend 179
  867. //#define __NR_pread 180
  868. //#define __NR_pwrite 181
  869. //#define __NR_chown 182
  870. #ifdef L_chown
  871. #include <unistd.h>
  872. _syscall3(int, chown, const char *, path, uid_t, owner, gid_t, group);
  873. #endif
  874. //#define __NR_getcwd 183
  875. //#define __NR_capget 184
  876. //#define __NR_capset 185
  877. //#define __NR_sigaltstack 186
  878. //#define __NR_sendfile 187
  879. //#define __NR_getpmsg 188
  880. //#define __NR_putpmsg 189
  881. //#define __NR_vfork 190
  882. //See architecture specific implementation...