syscalls.c 27 KB

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