syscalls.c 24 KB

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