syscalls.c 24 KB

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