syscalls.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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. //#define __NR_sysfs 135
  711. //#define __NR_personality 136
  712. //#define __NR_afs_syscall 137
  713. //#define __NR_setfsuid 138
  714. //#define __NR_setfsgid 139
  715. //#define __NR__llseek 140
  716. #ifdef L__llseek
  717. extern int _llseek(int fd, off_t hoff, off_t loff, loff_t *res, int whence);
  718. _syscall5(int, _llseek, int, fd, off_t, hoff, off_t, loff, loff_t *, res,
  719. int, whence);
  720. loff_t llseek(int fd, loff_t offset, int whence)
  721. {
  722. int ret;
  723. loff_t result;
  724. ret = _llseek(fd, (off_t) (offset >> 32),
  725. (off_t) (offset & 0xffffffff), &result, whence);
  726. return ret ? (loff_t) ret : result;
  727. }
  728. #endif
  729. //#define __NR_getdents 141
  730. #ifdef L__getdents
  731. #define __NR__getdents __NR_getdents
  732. #include <unistd.h>
  733. #include <dirent.h>
  734. _syscall3(int, _getdents, int, fd, char *, dirp, size_t, count);
  735. #endif
  736. //#define __NR__newselect 142
  737. #ifdef L__newselect
  738. #include <unistd.h>
  739. extern int _newselect(int n, fd_set *readfds, fd_set *writefds,
  740. fd_set *exceptfds, struct timeval *timeout);
  741. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  742. fd_set *, exceptfds, struct timeval *, timeout);
  743. int select(int n, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
  744. struct timeval *timeout)
  745. {
  746. return (_newselect(n, readfds, writefds, exceptfds, timeout));
  747. }
  748. #endif
  749. //#define __NR_flock 143
  750. #ifdef L_flock
  751. #include <sys/file.h>
  752. _syscall2(int,flock,int,fd, int,operation);
  753. #endif
  754. //#define __NR_msync 144
  755. //#define __NR_readv 145
  756. #ifdef L_readv
  757. #include <sys/uio.h>
  758. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  759. count);
  760. #endif
  761. //#define __NR_writev 146
  762. #ifdef L_writev
  763. #include <sys/uio.h>
  764. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  765. count);
  766. #endif
  767. //#define __NR_getsid 147
  768. #ifdef L_getsid
  769. #include <unistd.h>
  770. _syscall1(pid_t, getsid, pid_t, pid);
  771. #endif
  772. //#define __NR_fdatasync 148
  773. //#define __NR__sysctl 149
  774. //#define __NR_mlock 150
  775. //#define __NR_munlock 151
  776. //#define __NR_mlockall 152
  777. //#define __NR_munlockall 153
  778. //#define __NR_sched_setparam 154
  779. //#define __NR_sched_getparam 155
  780. //#define __NR_sched_setscheduler 156
  781. //#define __NR_sched_getscheduler 157
  782. //#define __NR_sched_yield 158
  783. //#define __NR_sched_get_priority_max 159
  784. //#define __NR_sched_get_priority_min 160
  785. //#define __NR_sched_rr_get_interval 161
  786. //#define __NR_nanosleep 162
  787. #ifdef L_nanosleep
  788. #include <time.h>
  789. _syscall2(int, nanosleep, const struct timespec *, req, struct timespec *, rem);
  790. #endif
  791. //#define __NR_mremap 163
  792. #ifdef L_mremap
  793. #include <unistd.h>
  794. #include <sys/mman.h>
  795. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t,
  796. new_size, int, may_move);
  797. #endif
  798. //#define __NR_setresuid 164
  799. //#define __NR_getresuid 165
  800. //#define __NR_vm86 166
  801. //#define __NR_query_module 167
  802. #ifdef L_query_module
  803. # ifdef __NR_query_module
  804. _syscall5(int, query_module, const char *, name, int, which,
  805. void *, buf, size_t, bufsize, size_t*, ret);
  806. # endif
  807. #endif
  808. //#define __NR_poll 168
  809. #if defined(L_poll) && defined(__NR_poll) /* uClinux 2.0 doesn't have poll */
  810. #include <sys/poll.h>
  811. _syscall3(int, poll, struct pollfd *, fds, unsigned long int, nfds, int, timeout);
  812. #endif
  813. //#define __NR_nfsservctl 169
  814. //#define __NR_setresgid 170
  815. //#define __NR_getresgid 171
  816. //#define __NR_prctl 172
  817. //#define __NR_rt_sigreturn 173
  818. //#define __NR_rt_sigaction 174
  819. //#define __NR_rt_sigprocmask 175
  820. //#define __NR_rt_sigpending 176
  821. //#define __NR_rt_sigtimedwait 177
  822. //#define __NR_rt_sigqueueinfo 178
  823. //#define __NR_rt_sigsuspend 179
  824. //#define __NR_pread 180
  825. //#define __NR_pwrite 181
  826. //#define __NR_chown 182
  827. #ifdef L_chown
  828. #include <unistd.h>
  829. _syscall3(int, chown, const char *, path, uid_t, owner, gid_t, group);
  830. #endif
  831. //#define __NR_getcwd 183
  832. // See unistd/getcwd.c -- we don't use the syscall, even when it is available...
  833. //#define __NR_capget 184
  834. //#define __NR_capset 185
  835. //#define __NR_sigaltstack 186
  836. //#define __NR_sendfile 187
  837. //#define __NR_getpmsg 188
  838. //#define __NR_putpmsg 189
  839. //#define __NR_vfork 190
  840. //See sysdeps/linux/<arch>vfork.[cS] for architecture specific implementation...