syscalls.c 27 KB

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