syscalls.c 27 KB

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