syscalls.c 27 KB

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