syscalls.c 28 KB

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