syscalls.c 24 KB

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