syscalls.c 23 KB

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