syscalls.c 23 KB

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