syscalls.c 24 KB

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