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