syscalls.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Syscalls for uClibc
  4. *
  5. * Copyright (C) 2000, 2001 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. #if __UCLIBC_OLD_STYLE_MMAP__
  536. extern __ptr_t _mmap(unsigned long *buffer);
  537. _syscall1(__ptr_t, _mmap, unsigned long *, buffer);
  538. __ptr_t mmap(__ptr_t addr, size_t len, int prot,
  539. int flags, int fd, __off_t offset)
  540. {
  541. unsigned long buffer[6];
  542. buffer[0] = (unsigned long) addr;
  543. buffer[1] = (unsigned long) len;
  544. buffer[2] = (unsigned long) prot;
  545. buffer[3] = (unsigned long) flags;
  546. buffer[4] = (unsigned long) fd;
  547. buffer[5] = (unsigned long) offset;
  548. return (__ptr_t) _mmap(buffer);
  549. }
  550. #else /* !__UCLIBC_OLD_STYLE_MMAP__ */
  551. _syscall6(__ptr_t, mmap,
  552. __ptr_t, addr, size_t, len, int, prot,
  553. int, flags, int, fd, __off_t, offset);
  554. #endif /* __UCLIBC_OLD_STYLE_MMAP__ */
  555. #endif
  556. //#define __NR_munmap 91
  557. #ifdef L_munmap
  558. #include <unistd.h>
  559. #include <sys/mman.h>
  560. _syscall2(int, munmap, void *, start, size_t, length);
  561. #endif
  562. //#define __NR_truncate 92
  563. #ifdef L_truncate
  564. #include <unistd.h>
  565. _syscall2(int, truncate, const char *, path, off_t, length);
  566. #endif
  567. //#define __NR_ftruncate 93
  568. #ifdef L_ftruncate
  569. #include <unistd.h>
  570. _syscall2(int, ftruncate, int, fd, off_t, length);
  571. #endif
  572. //#define __NR_fchmod 94
  573. #ifdef L_fchmod
  574. #include <sys/stat.h>
  575. _syscall2(int, fchmod, int, fildes, mode_t, mode);
  576. #endif
  577. //#define __NR_fchown 95
  578. #ifdef L_fchown
  579. #include <unistd.h>
  580. _syscall3(int, fchown, int, fd, uid_t, owner, gid_t, group);
  581. #endif
  582. //#define __NR_getpriority 96
  583. #ifdef L_getpriority
  584. #include <sys/resource.h>
  585. _syscall2(int, getpriority, __priority_which_t, which, id_t, who);
  586. #endif
  587. //#define __NR_setpriority 97
  588. #ifdef L_setpriority
  589. #include <sys/resource.h>
  590. _syscall3(int, setpriority, __priority_which_t, which, id_t, who, int, prio);
  591. #endif
  592. //#define __NR_profil 98
  593. //#define __NR_statfs 99
  594. #ifdef L_statfs
  595. #include <sys/vfs.h>
  596. _syscall2(int, statfs, const char *, path, struct statfs *, buf);
  597. #endif
  598. //#define __NR_fstatfs 100
  599. #ifdef L_fstatfs
  600. #include <sys/vfs.h>
  601. _syscall2(int, fstatfs, int, fd, struct statfs *, buf);
  602. #endif
  603. //#define __NR_ioperm 101
  604. #ifdef L_ioperm
  605. #include <sys/io.h>
  606. # if defined __UCLIBC_HAS_MMU__ && defined __NR_ioperm
  607. _syscall3(int, ioperm, unsigned long, from, unsigned long, num, int, turn_on);
  608. # else
  609. int ioperm(unsigned long from, unsigned long num, int turn_on)
  610. {
  611. __set_errno(ENOSYS);
  612. return -1;
  613. }
  614. # endif
  615. #endif
  616. //#define __NR_socketcall 102
  617. #ifdef L_socketcall
  618. _syscall2(int, socketcall, int, call, unsigned long *, args);
  619. #endif
  620. //#define __NR_syslog 103
  621. #ifdef L__syslog
  622. #include <unistd.h>
  623. #define __NR__syslog __NR_syslog
  624. #ifdef __STR_NR_syslog
  625. #define __STR_NR__syslog __STR_NR_syslog
  626. #endif
  627. extern int _syslog(int type, char *buf, int len);
  628. _syscall3(int, _syslog, int, type, char *, buf, int, len);
  629. int klogctl(int type, char *buf, int len)
  630. {
  631. return (_syslog(type, buf, len));
  632. }
  633. #endif
  634. //#define __NR_setitimer 104
  635. #ifdef L_setitimer
  636. #include <sys/time.h>
  637. _syscall3(int, setitimer, __itimer_which_t, which,
  638. const struct itimerval *, new, struct itimerval *, old);
  639. #endif
  640. //#define __NR_getitimer 105
  641. #ifdef L_getitimer
  642. #include <sys/time.h>
  643. _syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value);
  644. #endif
  645. //#define __NR_stat 106
  646. #ifdef L___stat
  647. #include <unistd.h>
  648. #include "statfix.h"
  649. #define __NR___stat __NR_stat
  650. #ifdef __STR_NR_stat
  651. #define __STR_NR___stat __STR_NR_stat
  652. #endif
  653. extern int __stat(const char *file_name, struct kernel_stat *buf);
  654. _syscall2(int, __stat, const char *, file_name, struct kernel_stat *, buf);
  655. int __xstat(int version, const char * file_name, struct libc_stat * cstat)
  656. {
  657. struct kernel_stat kstat;
  658. int result = __stat(file_name, &kstat);
  659. if (result == 0) {
  660. statfix(cstat, &kstat);
  661. }
  662. return result;
  663. }
  664. int stat(const char *file_name, struct libc_stat *buf)
  665. {
  666. return(__xstat(0, file_name, buf));
  667. }
  668. #endif
  669. //#define __NR_lstat 107
  670. #ifdef L___lstat
  671. #include <unistd.h>
  672. #include "statfix.h"
  673. #define __NR___lstat __NR_lstat
  674. #ifdef __STR_NR_lstat
  675. #define __STR_NR___lstat __STR_NR_lstat
  676. #endif
  677. extern int __lstat(const char *file_name, struct kernel_stat *buf);
  678. _syscall2(int, __lstat, const char *, file_name, struct kernel_stat *, buf);
  679. int __lxstat(int version, const char * file_name, struct libc_stat * cstat)
  680. {
  681. struct kernel_stat kstat;
  682. int result = __lstat(file_name, &kstat);
  683. if (result == 0) {
  684. statfix(cstat, &kstat);
  685. }
  686. return result;
  687. }
  688. int lstat(const char *file_name, struct libc_stat *buf)
  689. {
  690. return(__lxstat(0, file_name, buf));
  691. }
  692. #endif
  693. //#define __NR_fstat 108
  694. #ifdef L___fstat
  695. #include <unistd.h>
  696. #include "statfix.h"
  697. #define __NR___fstat __NR_fstat
  698. #ifdef __STR_NR_fstat
  699. #define __STR_NR___fstat __STR_NR_fstat
  700. #endif
  701. extern int __fstat(int filedes, struct kernel_stat *buf);
  702. _syscall2(int, __fstat, int, filedes, struct kernel_stat *, buf);
  703. int __fxstat(int version, int fd, struct libc_stat * cstat)
  704. {
  705. struct kernel_stat kstat;
  706. int result = __fstat(fd, &kstat);
  707. if (result == 0) {
  708. statfix(cstat, &kstat);
  709. }
  710. return result;
  711. }
  712. int fstat(int filedes, struct libc_stat *buf)
  713. {
  714. return(__fxstat(0, filedes, buf));
  715. }
  716. #endif
  717. //#define __NR_olduname 109
  718. //#define __NR_iopl 110
  719. #ifdef L_iopl
  720. #include <sys/io.h>
  721. # if defined __UCLIBC_HAS_MMU__ && defined __NR_iopl
  722. _syscall1(int, iopl, int, level);
  723. # else
  724. int iopl(int level)
  725. {
  726. __set_errno(ENOSYS);
  727. return -1;
  728. }
  729. # endif
  730. #endif
  731. //#define __NR_vhangup 111
  732. #ifdef L_vhangup
  733. #include <unistd.h>
  734. _syscall0(int, vhangup);
  735. #endif
  736. //#define __NR_idle 112
  737. //int idle(void);
  738. //#define __NR_vm86old 113
  739. //#define __NR_wait4 114
  740. #ifdef L_wait4
  741. _syscall4(int, wait4, pid_t, pid, int *, status, int, opts, void *, rusage);
  742. #endif
  743. //#define __NR_swapoff 115
  744. #ifdef L_swapoff
  745. #include <sys/swap.h>
  746. _syscall1(int, swapoff, const char *, path);
  747. #endif
  748. //#define __NR_sysinfo 116
  749. #ifdef L_sysinfo
  750. #include <sys/sysinfo.h>
  751. _syscall1(int, sysinfo, struct sysinfo *, info);
  752. #endif
  753. //#define __NR_ipc 117
  754. #ifdef L___ipc
  755. #define __NR___ipc __NR_ipc
  756. #ifdef __STR_NR_ipc
  757. #define __STR_NR___ipc __STR_NR_ipc
  758. #endif
  759. _syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, third, void *, ptr);
  760. #endif
  761. //#define __NR_fsync 118
  762. #ifdef L_fsync
  763. #include <unistd.h>
  764. _syscall1(int, fsync, int, fd);
  765. #endif
  766. //#define __NR_sigreturn 119
  767. //int sigreturn(unsigned long __unused);
  768. //#define __NR_clone 120
  769. //See architecture specific implementation...
  770. //#define __NR_setdomainname 121
  771. #ifdef L_setdomainname
  772. #include <unistd.h>
  773. _syscall2(int, setdomainname, const char *, name, size_t, len);
  774. #endif
  775. //#define __NR_uname 122
  776. #ifdef L_uname
  777. #include <sys/utsname.h>
  778. _syscall1(int, uname, struct utsname *, buf);
  779. #endif
  780. //#define __NR_modify_ldt 123
  781. //#define __NR_adjtimex 124
  782. #ifdef L_adjtimex
  783. #include <sys/timex.h>
  784. _syscall1(int, adjtimex, struct timex *, buf);
  785. #endif
  786. //#define __NR_mprotect 125
  787. #ifdef L_mprotect
  788. #include <sys/mman.h>
  789. _syscall3(int, mprotect, void *, addr, size_t, len, int, prot);
  790. #endif
  791. //#define __NR_sigprocmask 126
  792. #ifdef L_sigprocmask
  793. #include <signal.h>
  794. #undef sigprocmask
  795. _syscall3(int, sigprocmask, int, how, const sigset_t *, set, sigset_t *,
  796. oldset);
  797. #endif
  798. //#define __NR_create_module 127
  799. //See sysdeps/linux/commom/create_module.c
  800. //#define __NR_init_module 128
  801. #ifdef L_init_module
  802. /* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
  803. * (for 2.2 and 2.4 kernels). Use the greatest common denominator,
  804. * and let the kernel cope with whatever it gets. It's good at that. */
  805. _syscall5(int, init_module, void *, first, void *, second, void *, third,
  806. void *, fourth, void *, fifth);
  807. #endif
  808. //#define __NR_delete_module 129
  809. #ifdef L_delete_module
  810. # ifdef __NR_delete_module
  811. _syscall1(int, delete_module, const char *, name);
  812. # else
  813. int delete_module(const char * name)
  814. {
  815. __set_errno(ENOSYS);
  816. return -1;
  817. }
  818. # endif
  819. #endif
  820. //#define __NR_get_kernel_syms 130
  821. //#define __NR_quotactl 131
  822. //#define __NR_getpgid 132
  823. #ifdef L_getpgid
  824. _syscall1(pid_t, getpgid, pid_t, pid);
  825. #endif
  826. //#define __NR_fchdir 133
  827. #ifdef L_fchdir
  828. #include <unistd.h>
  829. _syscall1(int, fchdir, int, fd);
  830. #endif
  831. //#define __NR_bdflush 134
  832. #ifdef L_bdflush
  833. #include <sys/kdaemon.h>
  834. _syscall2(int, bdflush, int, __func, long int, __data);
  835. #endif
  836. //#define __NR_sysfs 135
  837. //#define __NR_personality 136
  838. //#define __NR_afs_syscall 137
  839. //#define __NR_setfsuid 138
  840. //#define __NR_setfsgid 139
  841. //#define __NR__llseek 140
  842. #ifdef L__llseek
  843. extern int _llseek(int fd, off_t hoff, off_t loff, loff_t *res, int whence);
  844. _syscall5(int, _llseek, int, fd, off_t, hoff, off_t, loff, loff_t *, res,
  845. int, whence);
  846. loff_t llseek(int fd, loff_t offset, int whence)
  847. {
  848. int ret;
  849. loff_t result;
  850. ret = _llseek(fd, (off_t) (offset >> 32),
  851. (off_t) (offset & 0xffffffff), &result, whence);
  852. return ret ? (loff_t) ret : result;
  853. }
  854. #endif
  855. //#define __NR_getdents 141
  856. #ifdef L_getdents
  857. #include <unistd.h>
  858. #include <dirent.h>
  859. _syscall3(int, getdents, int, fd, char *, dirp, size_t, count);
  860. #endif
  861. //#define __NR__newselect 142
  862. #ifdef L__newselect
  863. #include <unistd.h>
  864. extern int _newselect(int n, fd_set *readfds, fd_set *writefds,
  865. fd_set *exceptfds, struct timeval *timeout);
  866. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  867. fd_set *, exceptfds, struct timeval *, timeout);
  868. int select(int n, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
  869. struct timeval *timeout)
  870. {
  871. return (_newselect(n, readfds, writefds, exceptfds, timeout));
  872. }
  873. #endif
  874. //#define __NR_flock 143
  875. #ifdef L_flock
  876. #include <sys/file.h>
  877. _syscall2(int,flock,int,fd, int,operation);
  878. #endif
  879. //#define __NR_msync 144
  880. //#define __NR_readv 145
  881. #ifdef L_readv
  882. #include <sys/uio.h>
  883. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  884. count);
  885. #endif
  886. //#define __NR_writev 146
  887. #ifdef L_writev
  888. #include <sys/uio.h>
  889. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  890. count);
  891. #endif
  892. //#define __NR_getsid 147
  893. #ifdef L_getsid
  894. #include <unistd.h>
  895. _syscall1(pid_t, getsid, pid_t, pid);
  896. #endif
  897. //#define __NR_fdatasync 148
  898. //#define __NR__sysctl 149
  899. //#define __NR_mlock 150
  900. #ifdef L_mlock
  901. #include <sys/mman.h>
  902. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlock
  903. _syscall2(int, mlock, const void *, addr, size_t, len);
  904. # endif
  905. #endif
  906. //#define __NR_munlock 151
  907. #ifdef L_munlock
  908. #include <sys/mman.h>
  909. # if defined __UCLIBC_HAS_MMU__ && defined __NR_munlock
  910. _syscall2(int, munlock, const void *, addr, size_t, len);
  911. # endif
  912. #endif
  913. //#define __NR_mlockall 152
  914. #ifdef L_mlockall
  915. #include <sys/mman.h>
  916. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlockall
  917. _syscall1(int, mlockall, int, flags);
  918. # endif
  919. #endif
  920. //#define __NR_munlockall 153
  921. #ifdef L_munlockall
  922. #include <sys/mman.h>
  923. # if defined __UCLIBC_HAS_MMU__ && defined L_munlockall
  924. _syscall0(int, munlockall);
  925. # endif
  926. #endif
  927. //#define __NR_sched_setparam 154
  928. //#define __NR_sched_getparam 155
  929. //#define __NR_sched_setscheduler 156
  930. //#define __NR_sched_getscheduler 157
  931. //#define __NR_sched_yield 158
  932. //#define __NR_sched_get_priority_max 159
  933. //#define __NR_sched_get_priority_min 160
  934. //#define __NR_sched_rr_get_interval 161
  935. //#define __NR_nanosleep 162
  936. #ifdef L_nanosleep
  937. #include <time.h>
  938. _syscall2(int, nanosleep, const struct timespec *, req, struct timespec *, rem);
  939. #endif
  940. //#define __NR_mremap 163
  941. #ifdef L_mremap
  942. #include <unistd.h>
  943. #include <sys/mman.h>
  944. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t,
  945. new_size, int, may_move);
  946. #endif
  947. //#define __NR_setresuid 164
  948. //#define __NR_getresuid 165
  949. //#define __NR_vm86 166
  950. //#define __NR_query_module 167
  951. #ifdef L_query_module
  952. # ifdef __NR_query_module
  953. _syscall5(int, query_module, const char *, name, int, which,
  954. void *, buf, size_t, bufsize, size_t*, ret);
  955. # else
  956. int query_module(const char * name, int which,
  957. void * buf, size_t bufsize, size_t* ret)
  958. {
  959. __set_errno(ENOSYS);
  960. return -1;
  961. }
  962. # endif
  963. #endif
  964. //#define __NR_poll 168
  965. #if defined(L_poll) && defined(__NR_poll) /* uClinux 2.0 doesn't have poll */
  966. #include <sys/poll.h>
  967. _syscall3(int, poll, struct pollfd *, fds, unsigned long int, nfds, int, timeout);
  968. #endif
  969. //#define __NR_nfsservctl 169
  970. //#define __NR_setresgid 170
  971. //#define __NR_getresgid 171
  972. //#define __NR_prctl 172
  973. //#define __NR_rt_sigreturn 173
  974. //#define __NR_rt_sigaction 174
  975. //#define __NR_rt_sigprocmask 175
  976. //#define __NR_rt_sigpending 176
  977. //#define __NR_rt_sigtimedwait 177
  978. //#define __NR_rt_sigqueueinfo 178
  979. //#define __NR_rt_sigsuspend 179
  980. //#define __NR_pread 180
  981. //#define __NR_pwrite 181
  982. //#define __NR_chown 182
  983. #ifdef L_chown
  984. #include <unistd.h>
  985. _syscall3(int, chown, const char *, path, uid_t, owner, gid_t, group);
  986. #endif
  987. //#define __NR_getcwd 183
  988. // See unistd/getcwd.c -- we don't use this syscall, even when it is available...
  989. //#define __NR_capget 184
  990. #ifdef L_capget
  991. # ifdef __NR_capget
  992. _syscall2(int, capget, void*, header, void*, data);
  993. # else
  994. int capget(void* header, void* data)
  995. {
  996. __set_errno(ENOSYS);
  997. return -1;
  998. }
  999. # endif
  1000. #endif
  1001. //#define __NR_capset 185
  1002. #ifdef L_capset
  1003. # ifdef __NR_capset
  1004. _syscall2(int, capset, void*, header, const void*, data);
  1005. # else
  1006. int capset(void* header, const void* data)
  1007. {
  1008. __set_errno(ENOSYS);
  1009. return -1;
  1010. }
  1011. # endif
  1012. #endif
  1013. //#define __NR_sigaltstack 186
  1014. //#define __NR_sendfile 187
  1015. //#define __NR_getpmsg 188
  1016. //#define __NR_putpmsg 189
  1017. //#define __NR_vfork 190
  1018. //See sysdeps/linux/<arch>vfork.[cS] for architecture specific implementation...