syscalls.c 30 KB

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