syscalls.c 26 KB

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