syscalls.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  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. _syscall3(int, sigaction, int, signum, const struct sigaction *, act,
  418. struct sigaction *, oldact);
  419. #endif
  420. //#define __NR_sgetmask 68
  421. //#define __NR_ssetmask 69
  422. //#define __NR_setreuid 70
  423. #ifdef L_setreuid
  424. #include <unistd.h>
  425. _syscall2(int, setreuid, uid_t, ruid, uid_t, euid);
  426. #endif
  427. //#define __NR_setregid 71
  428. #ifdef L_setregid
  429. #include <unistd.h>
  430. _syscall2(int, setregid, gid_t, rgid, gid_t, egid);
  431. #endif
  432. //#define __NR_sigsuspend 72
  433. #ifdef L_sigsuspend
  434. #include <signal.h>
  435. _syscall1(int, sigsuspend, const sigset_t *, mask);
  436. #endif
  437. //#define __NR_sigpending 73
  438. #ifdef L_sigpending
  439. #include <signal.h>
  440. _syscall1(int, sigpending, sigset_t *, set);
  441. #endif
  442. //#define __NR_sethostname 74
  443. #ifdef L_sethostname
  444. #include <unistd.h>
  445. _syscall2(int, sethostname, const char *, name, size_t, len);
  446. #endif
  447. //#define __NR_setrlimit 75
  448. #ifdef L_setrlimit
  449. #include <unistd.h>
  450. #include <sys/resource.h>
  451. _syscall2(int, setrlimit, int, resource, const struct rlimit *, rlim);
  452. #endif
  453. //#define __NR_getrlimit 76
  454. #ifdef L_getrlimit
  455. #include <unistd.h>
  456. #include <sys/resource.h>
  457. _syscall2(int, getrlimit, int, resource, struct rlimit *, rlim);
  458. #endif
  459. //#define __NR_getrusage 77
  460. #ifdef L_getrusage
  461. #include <unistd.h>
  462. #include <wait.h>
  463. _syscall2(int, getrusage, int, who, struct rusage *, usage);
  464. #endif
  465. //#define __NR_gettimeofday 78
  466. #ifdef L_gettimeofday
  467. #include <sys/time.h>
  468. _syscall2(int, gettimeofday, struct timeval *, tv, struct timezone *, tz);
  469. #endif
  470. //#define __NR_settimeofday 79
  471. #ifdef L_settimeofday
  472. #include <sys/time.h>
  473. _syscall2(int, settimeofday, const struct timeval *, tv,
  474. const struct timezone *, tz);
  475. #endif
  476. //#define __NR_getgroups 80
  477. #ifdef L_getgroups
  478. #include <unistd.h>
  479. _syscall2(int, getgroups, int, size, gid_t *, list);
  480. #endif
  481. //#define __NR_setgroups 81
  482. #ifdef L_setgroups
  483. #include <unistd.h>
  484. #include <grp.h>
  485. _syscall2(int, setgroups, size_t, size, const gid_t *, list);
  486. #endif
  487. //#define __NR_select 82
  488. //#define __NR_symlink 83
  489. #ifdef L_symlink
  490. #include <unistd.h>
  491. _syscall2(int, symlink, const char *, oldpath, const char *, newpath);
  492. #endif
  493. //#define __NR_oldlstat 84
  494. //#define __NR_readlink 85
  495. #ifdef L_readlink
  496. #include <unistd.h>
  497. _syscall3(int, readlink, const char *, path, char *, buf, size_t, bufsiz);
  498. #endif
  499. //#define __NR_uselib 86
  500. #ifdef L_uselib
  501. #include <unistd.h>
  502. _syscall1(int, uselib, const char *, library);
  503. #endif
  504. //#define __NR_swapon 87
  505. #ifdef L_swapon
  506. #include <sys/swap.h>
  507. _syscall2(int, swapon, const char *, path, int, swapflags);
  508. #endif
  509. //#define __NR_reboot 88
  510. #ifdef L__reboot
  511. #define __NR__reboot __NR_reboot
  512. #ifdef __STR_NR_reboot
  513. #define __STR_NR__reboot __STR_NR_reboot
  514. #endif
  515. extern int _reboot(int magic, int magic2, int flag);
  516. _syscall3(int, _reboot, int, magic, int, magic2, int, flag);
  517. int reboot(int flag)
  518. {
  519. return (_reboot((int) 0xfee1dead, 672274793, flag));
  520. }
  521. #endif
  522. //#define __NR_readdir 89
  523. //#define __NR_mmap 90
  524. #ifdef L__mmap
  525. #define __NR__mmap __NR_mmap
  526. #ifdef __STR_NR_mmap
  527. #define __STR_NR__mmap __STR_NR_mmap
  528. #endif
  529. #include <unistd.h>
  530. #include <sys/mman.h>
  531. extern __ptr_t _mmap(unsigned long *buffer);
  532. _syscall1(__ptr_t, _mmap, unsigned long *, buffer);
  533. __ptr_t mmap(__ptr_t addr, size_t len, int prot,
  534. int flags, int fd, __off_t offset)
  535. {
  536. unsigned long buffer[6];
  537. buffer[0] = (unsigned long) addr;
  538. buffer[1] = (unsigned long) len;
  539. buffer[2] = (unsigned long) prot;
  540. buffer[3] = (unsigned long) flags;
  541. buffer[4] = (unsigned long) fd;
  542. buffer[5] = (unsigned long) offset;
  543. return (__ptr_t) _mmap(buffer);
  544. }
  545. #endif
  546. //#define __NR_munmap 91
  547. #ifdef L_munmap
  548. #include <unistd.h>
  549. #include <sys/mman.h>
  550. _syscall2(int, munmap, void *, start, size_t, length);
  551. #endif
  552. //#define __NR_truncate 92
  553. #ifdef L_truncate
  554. #include <unistd.h>
  555. _syscall2(int, truncate, const char *, path, off_t, length);
  556. #endif
  557. //#define __NR_ftruncate 93
  558. #ifdef L_ftruncate
  559. #include <unistd.h>
  560. _syscall2(int, ftruncate, int, fd, off_t, length);
  561. #endif
  562. //#define __NR_fchmod 94
  563. #ifdef L_fchmod
  564. #include <sys/stat.h>
  565. _syscall2(int, fchmod, int, fildes, mode_t, mode);
  566. #endif
  567. //#define __NR_fchown 95
  568. #ifdef L_fchown
  569. #include <unistd.h>
  570. _syscall3(int, fchown, int, fd, uid_t, owner, gid_t, group);
  571. #endif
  572. //#define __NR_getpriority 96
  573. #ifdef L_getpriority
  574. #include <sys/resource.h>
  575. _syscall2(int, getpriority, __priority_which_t, which, id_t, who);
  576. #endif
  577. //#define __NR_setpriority 97
  578. #ifdef L_setpriority
  579. #include <sys/resource.h>
  580. _syscall3(int, setpriority, __priority_which_t, which, id_t, who, int, prio);
  581. #endif
  582. //#define __NR_profil 98
  583. //#define __NR_statfs 99
  584. #ifdef L_statfs
  585. #include <sys/vfs.h>
  586. _syscall2(int, statfs, const char *, path, struct statfs *, buf);
  587. #endif
  588. //#define __NR_fstatfs 100
  589. #ifdef L_fstatfs
  590. #include <sys/vfs.h>
  591. _syscall2(int, fstatfs, int, fd, struct statfs *, buf);
  592. #endif
  593. //#define __NR_ioperm 101
  594. #ifdef L_ioperm
  595. #include <sys/io.h>
  596. # if defined __UCLIBC_HAS_MMU__ && defined __NR_ioperm
  597. _syscall3(int, ioperm, unsigned long, from, unsigned long, num, int, turn_on);
  598. # else
  599. int ioperm(unsigned long from, unsigned long num, int turn_on)
  600. {
  601. __set_errno(ENOSYS);
  602. return -1;
  603. }
  604. # endif
  605. #endif
  606. //#define __NR_socketcall 102
  607. #ifdef L_socketcall
  608. _syscall2(int, socketcall, int, call, unsigned long *, args);
  609. #endif
  610. //#define __NR_syslog 103
  611. #ifdef L__syslog
  612. #include <unistd.h>
  613. #define __NR__syslog __NR_syslog
  614. #ifdef __STR_NR_syslog
  615. #define __STR_NR__syslog __STR_NR_syslog
  616. #endif
  617. extern int _syslog(int type, char *buf, int len);
  618. _syscall3(int, _syslog, int, type, char *, buf, int, len);
  619. int klogctl(int type, char *buf, int len)
  620. {
  621. return (_syslog(type, buf, len));
  622. }
  623. #endif
  624. //#define __NR_setitimer 104
  625. #ifdef L_setitimer
  626. #include <sys/time.h>
  627. _syscall3(int, setitimer, __itimer_which_t, which,
  628. const struct itimerval *, new, struct itimerval *, old);
  629. #endif
  630. //#define __NR_getitimer 105
  631. #ifdef L_getitimer
  632. #include <sys/time.h>
  633. _syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value);
  634. #endif
  635. //#define __NR_stat 106
  636. #ifdef L___stat
  637. #include <unistd.h>
  638. #include "statfix.h"
  639. #define __NR___stat __NR_stat
  640. #ifdef __STR_NR_stat
  641. #define __STR_NR___stat __STR_NR_stat
  642. #endif
  643. extern int __stat(const char *file_name, struct kernel_stat *buf);
  644. _syscall2(int, __stat, const char *, file_name, struct kernel_stat *, buf);
  645. int __xstat(int version, const char * file_name, struct libc_stat * cstat)
  646. {
  647. struct kernel_stat kstat;
  648. int result = __stat(file_name, &kstat);
  649. if (result == 0) {
  650. statfix(cstat, &kstat);
  651. }
  652. return result;
  653. }
  654. int stat(const char *file_name, struct libc_stat *buf)
  655. {
  656. return(__xstat(0, file_name, buf));
  657. }
  658. #endif
  659. //#define __NR_lstat 107
  660. #ifdef L___lstat
  661. #include <unistd.h>
  662. #include "statfix.h"
  663. #define __NR___lstat __NR_lstat
  664. #ifdef __STR_NR_lstat
  665. #define __STR_NR___lstat __STR_NR_lstat
  666. #endif
  667. extern int __lstat(const char *file_name, struct kernel_stat *buf);
  668. _syscall2(int, __lstat, const char *, file_name, struct kernel_stat *, buf);
  669. int __lxstat(int version, const char * file_name, struct libc_stat * cstat)
  670. {
  671. struct kernel_stat kstat;
  672. int result = __lstat(file_name, &kstat);
  673. if (result == 0) {
  674. statfix(cstat, &kstat);
  675. }
  676. return result;
  677. }
  678. int lstat(const char *file_name, struct libc_stat *buf)
  679. {
  680. return(__lxstat(0, file_name, buf));
  681. }
  682. #endif
  683. //#define __NR_fstat 108
  684. #ifdef L___fstat
  685. #include <unistd.h>
  686. #include "statfix.h"
  687. #define __NR___fstat __NR_fstat
  688. #ifdef __STR_NR_fstat
  689. #define __STR_NR___fstat __STR_NR_fstat
  690. #endif
  691. extern int __fstat(int filedes, struct kernel_stat *buf);
  692. _syscall2(int, __fstat, int, filedes, struct kernel_stat *, buf);
  693. int __fxstat(int version, int fd, struct libc_stat * cstat)
  694. {
  695. struct kernel_stat kstat;
  696. int result = __fstat(fd, &kstat);
  697. if (result == 0) {
  698. statfix(cstat, &kstat);
  699. }
  700. return result;
  701. }
  702. int fstat(int filedes, struct libc_stat *buf)
  703. {
  704. return(__fxstat(0, filedes, buf));
  705. }
  706. #endif
  707. //#define __NR_olduname 109
  708. //#define __NR_iopl 110
  709. #ifdef L_iopl
  710. #include <sys/io.h>
  711. # if defined __UCLIBC_HAS_MMU__ && defined __NR_iopl
  712. _syscall1(int, iopl, int, level);
  713. # else
  714. int iopl(int level)
  715. {
  716. __set_errno(ENOSYS);
  717. return -1;
  718. }
  719. # endif
  720. #endif
  721. //#define __NR_vhangup 111
  722. #ifdef L_vhangup
  723. #include <unistd.h>
  724. _syscall0(int, vhangup);
  725. #endif
  726. //#define __NR_idle 112
  727. //int idle(void);
  728. //#define __NR_vm86old 113
  729. //#define __NR_wait4 114
  730. #ifdef L_wait4
  731. _syscall4(int, wait4, pid_t, pid, int *, status, int, opts, void *, rusage);
  732. #endif
  733. //#define __NR_swapoff 115
  734. #ifdef L_swapoff
  735. #include <sys/swap.h>
  736. _syscall1(int, swapoff, const char *, path);
  737. #endif
  738. //#define __NR_sysinfo 116
  739. #ifdef L_sysinfo
  740. #include <sys/sysinfo.h>
  741. _syscall1(int, sysinfo, struct sysinfo *, info);
  742. #endif
  743. //#define __NR_ipc 117
  744. #ifdef L___ipc
  745. #define __NR___ipc __NR_ipc
  746. #ifdef __STR_NR_ipc
  747. #define __STR_NR___ipc __STR_NR_ipc
  748. #endif
  749. _syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, third, void *, ptr);
  750. #endif
  751. //#define __NR_fsync 118
  752. #ifdef L_fsync
  753. #include <unistd.h>
  754. _syscall1(int, fsync, int, fd);
  755. #endif
  756. //#define __NR_sigreturn 119
  757. //int sigreturn(unsigned long __unused);
  758. //#define __NR_clone 120
  759. //See architecture specific implementation...
  760. //#define __NR_setdomainname 121
  761. #ifdef L_setdomainname
  762. #include <unistd.h>
  763. _syscall2(int, setdomainname, const char *, name, size_t, len);
  764. #endif
  765. //#define __NR_uname 122
  766. #ifdef L_uname
  767. #include <sys/utsname.h>
  768. _syscall1(int, uname, struct utsname *, buf);
  769. #endif
  770. //#define __NR_modify_ldt 123
  771. //#define __NR_adjtimex 124
  772. #ifdef L_adjtimex
  773. #include <sys/timex.h>
  774. _syscall1(int, adjtimex, struct timex *, buf);
  775. #endif
  776. //#define __NR_mprotect 125
  777. #ifdef L_mprotect
  778. #include <sys/mman.h>
  779. _syscall3(int, mprotect, void *, addr, size_t, len, int, prot);
  780. #endif
  781. //#define __NR_sigprocmask 126
  782. #ifdef L_sigprocmask
  783. #include <signal.h>
  784. _syscall3(int, sigprocmask, int, how, const sigset_t *, set, sigset_t *,
  785. oldset);
  786. #endif
  787. //#define __NR_create_module 127
  788. //See sysdeps/linux/commom/create_module.c
  789. //#define __NR_init_module 128
  790. #ifdef L_init_module
  791. /* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
  792. * (for 2.2 and 2.4 kernels). Use the greatest common denominator,
  793. * and let the kernel cope with whatever it gets. It's good at that. */
  794. _syscall5(int, init_module, void *, first, void *, second, void *, third,
  795. void *, fourth, void *, fifth);
  796. #endif
  797. //#define __NR_delete_module 129
  798. #ifdef L_delete_module
  799. # ifdef __NR_delete_module
  800. _syscall1(int, delete_module, const char *, name);
  801. # else
  802. int delete_module(const char * name)
  803. {
  804. __set_errno(ENOSYS);
  805. return -1;
  806. }
  807. # endif
  808. #endif
  809. //#define __NR_get_kernel_syms 130
  810. //#define __NR_quotactl 131
  811. //#define __NR_getpgid 132
  812. #ifdef L_getpgid
  813. _syscall1(pid_t, getpgid, pid_t, pid);
  814. #endif
  815. //#define __NR_fchdir 133
  816. #ifdef L_fchdir
  817. #include <unistd.h>
  818. _syscall1(int, fchdir, int, fd);
  819. #endif
  820. //#define __NR_bdflush 134
  821. #ifdef L_bdflush
  822. #include <sys/kdaemon.h>
  823. _syscall2(int, bdflush, int, __func, long int, __data);
  824. #endif
  825. //#define __NR_sysfs 135
  826. //#define __NR_personality 136
  827. //#define __NR_afs_syscall 137
  828. //#define __NR_setfsuid 138
  829. //#define __NR_setfsgid 139
  830. //#define __NR__llseek 140
  831. #ifdef L__llseek
  832. extern int _llseek(int fd, off_t hoff, off_t loff, loff_t *res, int whence);
  833. _syscall5(int, _llseek, int, fd, off_t, hoff, off_t, loff, loff_t *, res,
  834. int, whence);
  835. loff_t llseek(int fd, loff_t offset, int whence)
  836. {
  837. int ret;
  838. loff_t result;
  839. ret = _llseek(fd, (off_t) (offset >> 32),
  840. (off_t) (offset & 0xffffffff), &result, whence);
  841. return ret ? (loff_t) ret : result;
  842. }
  843. #endif
  844. //#define __NR_getdents 141
  845. #ifdef L_getdents
  846. #include <unistd.h>
  847. #include <dirent.h>
  848. _syscall3(int, getdents, int, fd, char *, dirp, size_t, count);
  849. #endif
  850. //#define __NR__newselect 142
  851. #ifdef L__newselect
  852. #include <unistd.h>
  853. extern int _newselect(int n, fd_set *readfds, fd_set *writefds,
  854. fd_set *exceptfds, struct timeval *timeout);
  855. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  856. fd_set *, exceptfds, struct timeval *, timeout);
  857. int select(int n, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
  858. struct timeval *timeout)
  859. {
  860. return (_newselect(n, readfds, writefds, exceptfds, timeout));
  861. }
  862. #endif
  863. //#define __NR_flock 143
  864. #ifdef L_flock
  865. #include <sys/file.h>
  866. _syscall2(int,flock,int,fd, int,operation);
  867. #endif
  868. //#define __NR_msync 144
  869. //#define __NR_readv 145
  870. #ifdef L_readv
  871. #include <sys/uio.h>
  872. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  873. count);
  874. #endif
  875. //#define __NR_writev 146
  876. #ifdef L_writev
  877. #include <sys/uio.h>
  878. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  879. count);
  880. #endif
  881. //#define __NR_getsid 147
  882. #ifdef L_getsid
  883. #include <unistd.h>
  884. _syscall1(pid_t, getsid, pid_t, pid);
  885. #endif
  886. //#define __NR_fdatasync 148
  887. //#define __NR__sysctl 149
  888. //#define __NR_mlock 150
  889. #ifdef L_mlock
  890. #include <sys/mman.h>
  891. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlock
  892. _syscall2(int, mlock, const void *, addr, size_t, len);
  893. # endif
  894. #endif
  895. //#define __NR_munlock 151
  896. #ifdef L_munlock
  897. #include <sys/mman.h>
  898. # if defined __UCLIBC_HAS_MMU__ && defined __NR_munlock
  899. _syscall2(int, munlock, const void *, addr, size_t, len);
  900. # endif
  901. #endif
  902. //#define __NR_mlockall 152
  903. #ifdef L_mlockall
  904. #include <sys/mman.h>
  905. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlockall
  906. _syscall1(int, mlockall, int, flags);
  907. # endif
  908. #endif
  909. //#define __NR_munlockall 153
  910. #ifdef L_munlockall
  911. #include <sys/mman.h>
  912. # if defined __UCLIBC_HAS_MMU__ && defined L_munlockall
  913. _syscall0(int, munlockall);
  914. # endif
  915. #endif
  916. //#define __NR_sched_setparam 154
  917. //#define __NR_sched_getparam 155
  918. //#define __NR_sched_setscheduler 156
  919. //#define __NR_sched_getscheduler 157
  920. //#define __NR_sched_yield 158
  921. //#define __NR_sched_get_priority_max 159
  922. //#define __NR_sched_get_priority_min 160
  923. //#define __NR_sched_rr_get_interval 161
  924. //#define __NR_nanosleep 162
  925. #ifdef L_nanosleep
  926. #include <time.h>
  927. _syscall2(int, nanosleep, const struct timespec *, req, struct timespec *, rem);
  928. #endif
  929. //#define __NR_mremap 163
  930. #ifdef L_mremap
  931. #include <unistd.h>
  932. #include <sys/mman.h>
  933. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t,
  934. new_size, int, may_move);
  935. #endif
  936. //#define __NR_setresuid 164
  937. //#define __NR_getresuid 165
  938. //#define __NR_vm86 166
  939. //#define __NR_query_module 167
  940. #ifdef L_query_module
  941. # ifdef __NR_query_module
  942. _syscall5(int, query_module, const char *, name, int, which,
  943. void *, buf, size_t, bufsize, size_t*, ret);
  944. # else
  945. int query_module(const char * name, int which,
  946. void * buf, size_t bufsize, size_t* ret)
  947. {
  948. __set_errno(ENOSYS);
  949. return -1;
  950. }
  951. # endif
  952. #endif
  953. //#define __NR_poll 168
  954. #if defined(L_poll) && defined(__NR_poll) /* uClinux 2.0 doesn't have poll */
  955. #include <sys/poll.h>
  956. _syscall3(int, poll, struct pollfd *, fds, unsigned long int, nfds, int, timeout);
  957. #endif
  958. //#define __NR_nfsservctl 169
  959. //#define __NR_setresgid 170
  960. //#define __NR_getresgid 171
  961. //#define __NR_prctl 172
  962. //#define __NR_rt_sigreturn 173
  963. //#define __NR_rt_sigaction 174
  964. //#define __NR_rt_sigprocmask 175
  965. //#define __NR_rt_sigpending 176
  966. //#define __NR_rt_sigtimedwait 177
  967. //#define __NR_rt_sigqueueinfo 178
  968. //#define __NR_rt_sigsuspend 179
  969. //#define __NR_pread 180
  970. //#define __NR_pwrite 181
  971. //#define __NR_chown 182
  972. #ifdef L_chown
  973. #include <unistd.h>
  974. _syscall3(int, chown, const char *, path, uid_t, owner, gid_t, group);
  975. #endif
  976. //#define __NR_getcwd 183
  977. // See unistd/getcwd.c -- we don't use this syscall, even when it is available...
  978. //#define __NR_capget 184
  979. #ifdef L_capget
  980. # ifdef __NR_capget
  981. _syscall2(int, capget, void*, header, void*, data);
  982. # else
  983. int capget(void* header, void* data)
  984. {
  985. __set_errno(ENOSYS);
  986. return -1;
  987. }
  988. # endif
  989. #endif
  990. //#define __NR_capset 185
  991. #ifdef L_capset
  992. # ifdef __NR_capset
  993. _syscall2(int, capset, void*, header, const void*, data);
  994. # else
  995. int capset(void* header, const void* data)
  996. {
  997. __set_errno(ENOSYS);
  998. return -1;
  999. }
  1000. # endif
  1001. #endif
  1002. //#define __NR_sigaltstack 186
  1003. //#define __NR_sendfile 187
  1004. //#define __NR_getpmsg 188
  1005. //#define __NR_putpmsg 189
  1006. //#define __NR_vfork 190
  1007. //See sysdeps/linux/<arch>vfork.[cS] for architecture specific implementation...