syscalls.c 24 KB

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