syscalls.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Syscalls for uClibc
  4. *
  5. * Copyright (C) 2000 by Lineo, inc
  6. * Copyright (C) 2001, 2002 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 <features.h>
  25. #include <errno.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. _syscall1(void, _exit, int, status);
  34. #endif
  35. //#define __NR_fork 2
  36. #ifdef L___libc_fork
  37. #include <unistd.h>
  38. # ifdef __UCLIBC_HAS_MMU__
  39. #define __NR___libc_fork __NR_fork
  40. _syscall0(pid_t, __libc_fork);
  41. weak_alias (__libc_fork, 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___libc_read
  52. #include <unistd.h>
  53. #define __NR___libc_read __NR_read
  54. _syscall3(ssize_t, __libc_read, int, fd, __ptr_t, buf, size_t, count);
  55. weak_alias(__libc_read, read)
  56. #endif
  57. //#define __NR_write 4
  58. #ifdef L___libc_write
  59. #include <unistd.h>
  60. #define __NR___libc_write __NR_write
  61. _syscall3(ssize_t, __libc_write, int, fd, const __ptr_t, buf, size_t, count);
  62. weak_alias(__libc_write, write)
  63. /* Stupid libgcc.a from gcc 2.95.x uses __write in pure.o
  64. * which is a blatent GNU libc-ism... */
  65. weak_alias (__libc_write, __write)
  66. #endif
  67. //#define __NR_open 5
  68. #ifdef L___libc_open
  69. #include <stdarg.h>
  70. /* Do not include fcntl.h, so gcc doesn't whine the prototype */
  71. #define __NR___libc_open __NR_open
  72. _syscall3(int, __libc_open, const char *, fn, int, flags, mode_t, mode);
  73. weak_alias(__libc_open, open)
  74. #endif
  75. //#define __NR_close 6
  76. #ifdef L___libc_close
  77. #include <unistd.h>
  78. #define __NR___libc_close __NR_close
  79. _syscall1(int, __libc_close, int, fd);
  80. weak_alias(__libc_close, close)
  81. #endif
  82. //#define __NR_waitpid 7
  83. // Implemented using wait4
  84. //#define __NR_creat 8
  85. #ifdef L_creat
  86. #include <fcntl.h>
  87. #ifdef __NR_creat
  88. _syscall2(int, creat, const char *, file, mode_t, mode);
  89. #else
  90. extern int __libc_open (const char *file, int flags, mode_t mode);
  91. int creat (const char *file, mode_t mode)
  92. {
  93. return __libc_open (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
  94. }
  95. #endif
  96. #endif
  97. //#define __NR_link 9
  98. #ifdef L_link
  99. #include <unistd.h>
  100. _syscall2(int, link, const char *, oldpath, const char *, newpath);
  101. #endif
  102. //#define __NR_unlink 10
  103. #ifdef L_unlink
  104. #include <unistd.h>
  105. _syscall1(int, unlink, const char *, pathname);
  106. #endif
  107. //#define __NR_execve 11
  108. #ifdef L_execve
  109. #include <unistd.h>
  110. _syscall3(int, execve, const char *, filename, char *const *, argv,
  111. char *const *, envp);
  112. #endif
  113. //#define __NR_chdir 12
  114. #ifdef L_chdir
  115. #include <unistd.h>
  116. _syscall1(int, chdir, const char *, path);
  117. #endif
  118. //#define __NR_time 13
  119. #ifdef L_time
  120. #include <time.h>
  121. #include <sys/time.h>
  122. #ifdef __NR_time
  123. _syscall1(time_t, time, time_t *, t);
  124. #else
  125. time_t time (time_t *t)
  126. {
  127. time_t result;
  128. struct timeval tv;
  129. if (gettimeofday (&tv, (struct timezone *) NULL)) {
  130. result = (time_t) -1;
  131. } else { result = (time_t) tv.tv_sec; }
  132. if (t != NULL) { *t = result; }
  133. return result;
  134. }
  135. #endif
  136. #endif
  137. //#define __NR_mknod 14
  138. #ifdef L_mknod
  139. #include <unistd.h>
  140. extern int mknod(const char *pathname, mode_t mode, dev_t dev);
  141. _syscall3(int, mknod, const char *, pathname, mode_t, mode, dev_t, dev);
  142. int __xmknod (int version, const char * path, mode_t mode, dev_t *dev)
  143. {
  144. switch(version)
  145. {
  146. case 1:
  147. return mknod (path, mode, *dev);
  148. default:
  149. __set_errno(EINVAL);
  150. return -1;
  151. }
  152. }
  153. #endif
  154. //#define __NR_chmod 15
  155. #ifdef L_chmod
  156. #include <sys/stat.h>
  157. _syscall2(int, chmod, const char *, path, mode_t, mode);
  158. #endif
  159. /* Old kernels don't have lchown -- do chown instead. This
  160. * is sick and wrong, but at least things will compile.
  161. * They may not follow links when they should though... */
  162. #ifndef __NR_lchown
  163. #define __NR_lchown __NR_chown
  164. #endif
  165. //#define __NR_lchown 16
  166. #ifdef L_lchown
  167. #include <unistd.h>
  168. _syscall3(int, lchown, const char *, path, uid_t, owner, gid_t, group);
  169. #endif
  170. //#define __NR_break 17
  171. //#define __NR_oldstat 18
  172. //#define __NR_lseek 19
  173. #ifdef L___libc_lseek
  174. #include <unistd.h>
  175. #define __NR___libc_lseek __NR_lseek
  176. _syscall3(__off_t, __libc_lseek, int, fildes, __off_t, offset, int, whence);
  177. weak_alias(__libc_lseek, lseek)
  178. #ifndef __NR__llseek
  179. weak_alias(__libc_lseek, llseek)
  180. weak_alias(__libc_lseek, lseek64)
  181. #endif
  182. #endif
  183. //#define __NR_getpid 20
  184. #ifdef L___libc_getpid
  185. #include <unistd.h>
  186. #if defined (__alpha__)
  187. #define __NR_getpid __NR_getxpid
  188. #endif
  189. #define __NR___libc_getpid __NR_getpid
  190. _syscall0(pid_t, __libc_getpid);
  191. weak_alias(__libc_getpid, getpid)
  192. weak_alias(__libc_getpid, __getpid)
  193. #endif
  194. //#define __NR_mount 21
  195. #ifdef L_mount
  196. #include <sys/mount.h>
  197. _syscall5(int, mount, const char *, specialfile, const char *, dir,
  198. const char *, filesystemtype, unsigned long, rwflag,
  199. const void *, data);
  200. #endif
  201. //#define __NR_umount 22
  202. #ifdef L_umount
  203. #include <sys/mount.h>
  204. _syscall1(int, umount, const char *, specialfile);
  205. #endif
  206. //#define __NR_setuid 23
  207. #ifdef L___setuid
  208. #define __NR___setuid __NR_setuid
  209. #include <unistd.h>
  210. static inline
  211. _syscall1(int, __setuid, uid_t, uid);
  212. int setuid(uid_t uid)
  213. {
  214. if (uid == (uid_t) ~0) {
  215. __set_errno (EINVAL);
  216. return -1;
  217. }
  218. return(__setuid(uid));
  219. }
  220. #endif
  221. //#define __NR_getuid 24
  222. #ifdef L_getuid
  223. #include <unistd.h>
  224. #if defined (__alpha__)
  225. #define __NR_getuid __NR_getxuid
  226. #endif
  227. _syscall0(uid_t, getuid);
  228. #endif
  229. //#define __NR_stime 25
  230. #ifdef L_stime
  231. #include <time.h>
  232. #include <sys/time.h>
  233. #ifdef _NR_stime
  234. _syscall1(int, stime, const time_t *, t);
  235. #else
  236. int stime(const time_t *when)
  237. {
  238. struct timeval tv;
  239. if (when == NULL) { __set_errno (EINVAL); return -1; }
  240. tv.tv_sec = *when;
  241. tv.tv_usec = 0;
  242. return settimeofday (&tv, (struct timezone *) 0);
  243. }
  244. #endif
  245. #endif
  246. //#define __NR_ptrace 26
  247. #ifdef L___ptrace
  248. #include <sys/ptrace.h>
  249. #define __NR___ptrace __NR_ptrace
  250. _syscall4(long, __ptrace, enum __ptrace_request, request, pid_t, pid,
  251. void*, addr, void*, data);
  252. #endif
  253. //#define __NR_alarm 27
  254. #ifdef L_alarm
  255. #include <unistd.h>
  256. #ifdef __NR_alarm
  257. _syscall1(unsigned int, alarm, unsigned int, seconds);
  258. #else
  259. #include <sys/time.h>
  260. unsigned int alarm (unsigned int seconds)
  261. {
  262. struct itimerval old, new;
  263. unsigned int retval;
  264. new.it_value.tv_usec = 0;
  265. new.it_interval.tv_sec = 0;
  266. new.it_interval.tv_usec = 0;
  267. new.it_value.tv_sec = (long int) seconds;
  268. if (setitimer (ITIMER_REAL, &new, &old) < 0) { return 0; }
  269. retval = old.it_value.tv_sec;
  270. if (old.it_value.tv_usec) { ++retval; }
  271. return retval;
  272. }
  273. #endif
  274. #endif
  275. //#define __NR_oldfstat 28
  276. //#define __NR_pause 29
  277. #ifdef L___libc_pause
  278. #include <unistd.h>
  279. #ifdef __NR_pause
  280. #define __NR___libc_pause __NR_pause
  281. _syscall0(int, __libc_pause);
  282. weak_alias(__libc_pause, pause)
  283. #else
  284. #include <signal.h>
  285. int __libc_pause (void)
  286. {
  287. return(__sigpause(sigblock(0), 0));
  288. }
  289. weak_alias(__libc_pause, pause)
  290. #endif
  291. #endif
  292. //#define __NR_utime 30
  293. #ifdef L_utime
  294. #include <utime.h>
  295. #ifdef __NR_utime
  296. _syscall2(int, utime, const char *, file, const struct utimbuf *, times);
  297. #else
  298. #include <stdlib.h>
  299. #include <sys/time.h>
  300. int utime(const char *file, const struct utimbuf *times)
  301. {
  302. struct timeval timevals[2];
  303. if (times != NULL) {
  304. timevals[0].tv_usec = 0L;
  305. timevals[1].tv_usec = 0L;
  306. timevals[0].tv_sec = (long int) times->actime;
  307. timevals[1].tv_sec = (long int) times->modtime;
  308. } else {
  309. if (gettimeofday (&timevals[0], NULL) < 0) { return -1; }
  310. timevals[1] = timevals[0];
  311. }
  312. return utimes(file, timevals);
  313. }
  314. #endif
  315. #endif
  316. //#define __NR_utimed
  317. #ifdef L_utimes
  318. #include <utime.h>
  319. #ifdef __NR_utimes
  320. _syscall2(int, utimes, const char *, file, const struct timeval *, tvp);
  321. #else
  322. #include <stdlib.h>
  323. #include <sys/time.h>
  324. int utimes (const char *file, const struct timeval tvp[2])
  325. {
  326. struct utimbuf buf, *times;
  327. if (tvp) {
  328. times = &buf;
  329. times->actime = tvp[0].tv_sec;
  330. times->modtime = tvp[1].tv_sec;
  331. } else { times = NULL; }
  332. return utime(file, times);
  333. }
  334. #endif
  335. #endif
  336. //#define __NR_stty 31
  337. #ifdef L_stty
  338. #include <sgtty.h>
  339. int stty (int __fd, __const struct sgttyb *__params);
  340. {
  341. __set_errno(ENOSYS);
  342. return -1;
  343. }
  344. #endif
  345. //#define __NR_gtty 32
  346. #ifdef L_gtty
  347. #include <sgtty.h>
  348. int gtty (int __fd, struct sgttyb *__params)
  349. {
  350. __set_errno(ENOSYS);
  351. return -1;
  352. }
  353. #endif
  354. //#define __NR_access 33
  355. #ifdef L_access
  356. #include <unistd.h>
  357. _syscall2(int, access, const char *, pathname, int, mode);
  358. #endif
  359. //#define __NR_nice 34
  360. #ifdef L_nice
  361. #include <unistd.h>
  362. #ifdef __NR_nice
  363. _syscall1(int, nice, int, inc);
  364. #else
  365. #include <sys/resource.h>
  366. int nice (int incr)
  367. {
  368. int save, prio, result;
  369. save = errno;
  370. __set_errno (0);
  371. prio = getpriority (PRIO_PROCESS, 0);
  372. if (prio == -1) {
  373. if (errno != 0) { return -1; }
  374. else { __set_errno (save); }
  375. }
  376. result = setpriority (PRIO_PROCESS, 0, prio + incr);
  377. if (result != -1) { return prio + incr; } else { return -1; }
  378. }
  379. #endif
  380. #endif
  381. //#define __NR_ftime 35
  382. //#define __NR_sync 36
  383. #ifdef L_sync
  384. #include <unistd.h>
  385. _syscall0(void, sync);
  386. #endif
  387. //#define __NR_kill 37
  388. #ifdef L_kill
  389. #include <signal.h>
  390. #undef kill
  391. _syscall2(int, kill, pid_t, pid, int, sig);
  392. #endif
  393. //#define __NR_rename 38
  394. #ifdef L_rename
  395. #include <stdio.h>
  396. _syscall2(int, rename, const char *, oldpath, const char *, newpath);
  397. #endif
  398. //#define __NR_mkdir 39
  399. #ifdef L_mkdir
  400. #include <sys/stat.h>
  401. _syscall2(int, mkdir, const char *, pathname, mode_t, mode);
  402. #endif
  403. //#define __NR_rmdir 40
  404. #ifdef L_rmdir
  405. #include <unistd.h>
  406. _syscall1(int, rmdir, const char *, pathname);
  407. #endif
  408. //#define __NR_dup 41
  409. #ifdef L_dup
  410. #include <unistd.h>
  411. _syscall1(int, dup, int, oldfd);
  412. #endif
  413. //#define __NR_pipe 42
  414. #ifdef L_pipe
  415. #include <unistd.h>
  416. _syscall1(int, pipe, int *, filedes);
  417. #endif
  418. //#define __NR_times 43
  419. #ifdef L_times
  420. #include <sys/times.h>
  421. _syscall1(clock_t, times, struct tms *, buf);
  422. #endif
  423. //#define __NR_prof 44
  424. //#define __NR_brk 45
  425. //#define __NR_setgid 46
  426. #ifdef L_setgid
  427. #include <unistd.h>
  428. _syscall1(int, setgid, gid_t, gid);
  429. #endif
  430. //#define __NR_getgid 47
  431. #ifdef L_getgid
  432. #include <unistd.h>
  433. #if defined (__alpha__)
  434. #define __NR_getgid __NR_getxgid
  435. #endif
  436. _syscall0(gid_t, getgid);
  437. #endif
  438. //#define __NR_signal 48
  439. //#define __NR_geteuid 49
  440. #ifdef L_geteuid
  441. #include <unistd.h>
  442. # ifdef __NR_geteuid
  443. _syscall0(uid_t, geteuid);
  444. # else
  445. uid_t geteuid(void)
  446. {
  447. return (getuid());
  448. }
  449. # endif
  450. #endif
  451. //#define __NR_getegid 50
  452. #ifdef L_getegid
  453. #include <unistd.h>
  454. # ifdef __NR_getegid
  455. _syscall0(gid_t, getegid);
  456. # else
  457. gid_t getegid(void)
  458. {
  459. return (getgid());
  460. }
  461. # endif
  462. #endif
  463. //#define __NR_acct 51
  464. #ifdef L_acct
  465. #include <unistd.h>
  466. _syscall1(int, acct, const char *, filename);
  467. #endif
  468. //#define __NR_umount2 52
  469. #ifdef L_umount2
  470. # ifdef __NR_umount2 /* Old kernels don't have umount2 */
  471. # include <sys/mount.h>
  472. _syscall2(int, umount2, const char *, special_file, int, flags);
  473. # else
  474. int umount2(const char * special_file, int flags)
  475. {
  476. __set_errno(ENOSYS);
  477. return -1;
  478. }
  479. # endif
  480. #endif
  481. //#define __NR_lock 53
  482. //#define __NR_ioctl 54
  483. #ifdef L__ioctl
  484. #include <stdarg.h>
  485. #include <sys/ioctl.h>
  486. #define __NR__ioctl __NR_ioctl
  487. extern int _ioctl(int fd, int request, void *arg);
  488. _syscall3(int, _ioctl, int, fd, int, request, void *, arg);
  489. int ioctl(int fd, unsigned long int request, ...)
  490. {
  491. void *arg;
  492. va_list list;
  493. va_start(list, request);
  494. arg = va_arg(list, void *);
  495. va_end(list);
  496. return _ioctl(fd, request, arg);
  497. }
  498. #endif
  499. //#define __NR_fcntl 55
  500. #ifdef L__fcntl
  501. #include <stdarg.h>
  502. #include <fcntl.h>
  503. #define __NR__fcntl __NR_fcntl
  504. extern int _fcntl(int fd, int cmd, long arg);
  505. _syscall3(int, _fcntl, int, fd, int, cmd, long, arg);
  506. int __libc_fcntl(int fd, int command, ...)
  507. {
  508. long arg;
  509. va_list list;
  510. va_start(list, command);
  511. arg = va_arg(list, long);
  512. va_end(list);
  513. return _fcntl(fd, command, arg);
  514. }
  515. weak_alias(__libc_fcntl, fcntl)
  516. #endif
  517. //#define __NR_mpx 56
  518. //#define __NR_setpgid 57
  519. #ifdef L_setpgid
  520. #include <unistd.h>
  521. _syscall2(int, setpgid, pid_t, pid, pid_t, pgid);
  522. #endif
  523. //#define __NR_ulimit 58
  524. //#define __NR_oldolduname 59
  525. //#define __NR_umask 60
  526. #ifdef L_umask
  527. #include <sys/stat.h>
  528. _syscall1(mode_t, umask, mode_t, mask);
  529. #endif
  530. //#define __NR_chroot 61
  531. #ifdef L_chroot
  532. #include <unistd.h>
  533. _syscall1(int, chroot, const char *, path);
  534. #endif
  535. //#define __NR_ustat 62
  536. //#define __NR_dup2 63
  537. #ifdef L_dup2
  538. #include <unistd.h>
  539. _syscall2(int, dup2, int, oldfd, int, newfd);
  540. #endif
  541. //#define __NR_getppid 64
  542. #ifdef L_getppid
  543. # include <unistd.h>
  544. # ifdef __NR_getppid
  545. _syscall0(pid_t, getppid);
  546. # else
  547. pid_t getppid(void)
  548. {
  549. return (getpid());
  550. }
  551. # endif
  552. #endif
  553. //#define __NR_getpgrp 65
  554. #ifdef L_getpgrp
  555. #include <unistd.h>
  556. _syscall0(pid_t, getpgrp);
  557. #endif
  558. //#define __NR_setsid 66
  559. #ifdef L_setsid
  560. #include <unistd.h>
  561. _syscall0(pid_t, setsid);
  562. #endif
  563. //#define __NR_sigaction 67
  564. #ifndef __NR_rt_sigaction
  565. #define __NR___sigaction __NR_sigaction
  566. #ifdef L___sigaction
  567. #include <signal.h>
  568. #undef sigaction
  569. _syscall3(int, __sigaction, int, signum, const struct sigaction *, act,
  570. struct sigaction *, oldact);
  571. #endif
  572. #endif
  573. //#define __NR_sgetmask 68
  574. //#define __NR_ssetmask 69
  575. //#define __NR_setreuid 70
  576. #ifdef L_setreuid
  577. #include <unistd.h>
  578. _syscall2(int, setreuid, uid_t, ruid, uid_t, euid);
  579. #endif
  580. //#define __NR_setregid 71
  581. #ifdef L_setregid
  582. #include <unistd.h>
  583. _syscall2(int, setregid, gid_t, rgid, gid_t, egid);
  584. #endif
  585. //#define __NR_sigsuspend 72
  586. #ifndef __NR_rt_sigsuspend
  587. #define __NR___sigsuspend __NR_sigsuspend
  588. #ifdef L___sigsuspend
  589. #include <signal.h>
  590. #undef sigsuspend
  591. _syscall3(int, __sigsuspend, int, a, unsigned long int, b, unsigned long int, c);
  592. int sigsuspend (const sigset_t *set)
  593. {
  594. return __sigsuspend(0, 0, set->__val[0]);
  595. }
  596. #endif
  597. #endif
  598. //#define __NR_sigpending 73
  599. #ifndef __NR_rt_sigpending
  600. #ifdef L_sigpending
  601. #include <signal.h>
  602. #undef sigpending
  603. _syscall1(int, sigpending, sigset_t *, set);
  604. #endif
  605. #endif
  606. //#define __NR_sethostname 74
  607. #ifdef L_sethostname
  608. #include <unistd.h>
  609. _syscall2(int, sethostname, const char *, name, size_t, len);
  610. #endif
  611. //#define __NR_setrlimit 75
  612. #ifndef __NR_ugetrlimit
  613. /* Only wrap setrlimit if the new ugetrlimit is not present */
  614. #ifdef L___setrlimit
  615. #define __NR___setrlimit __NR_setrlimit
  616. #include <unistd.h>
  617. #include <sys/resource.h>
  618. #define RMIN(x, y) ((x) < (y) ? (x) : (y))
  619. _syscall2(int, __setrlimit, int, resource, const struct rlimit *, rlim);
  620. int setrlimit (__rlimit_resource_t resource, const struct rlimit *rlimits)
  621. {
  622. struct rlimit rlimits_small;
  623. /* We might have to correct the limits values. Since the old values
  624. * were signed the new values might be too large. */
  625. rlimits_small.rlim_cur = RMIN ((unsigned long int) rlimits->rlim_cur,
  626. RLIM_INFINITY >> 1);
  627. rlimits_small.rlim_max = RMIN ((unsigned long int) rlimits->rlim_max,
  628. RLIM_INFINITY >> 1);
  629. return(__setrlimit(resource, &rlimits_small));
  630. }
  631. #undef RMIN
  632. #endif
  633. #else /* We don't need to wrap setrlimit */
  634. #ifdef L_setrlimit
  635. #include <unistd.h>
  636. #include <sys/resource.h>
  637. _syscall2(int, setrlimit, int, resource, const struct rlimit *, rlim);
  638. #endif
  639. #endif /* __NR_setrlimit */
  640. //#define __NR_getrlimit 76
  641. #ifdef L___getrlimit
  642. /* Only include the old getrlimit if the new one (ugetrlimit) is not around */
  643. #ifndef __NR_ugetrlimit
  644. #define __NR___getrlimit __NR_getrlimit
  645. #include <unistd.h>
  646. #include <sys/resource.h>
  647. _syscall2(int, __getrlimit, int, resource, struct rlimit *, rlim);
  648. int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
  649. {
  650. int result;
  651. result = __getrlimit(resource, rlimits);
  652. if (result == -1)
  653. return result;
  654. /* We might have to correct the limits values. Since the old values
  655. * were signed the infinity value is too small. */
  656. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  657. rlimits->rlim_cur = RLIM_INFINITY;
  658. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  659. rlimits->rlim_max = RLIM_INFINITY;
  660. return result;
  661. }
  662. #endif
  663. #endif /* __NR_getrlimit */
  664. //#define __NR_getrusage 77
  665. #ifdef L_getrusage
  666. #include <unistd.h>
  667. #include <wait.h>
  668. _syscall2(int, getrusage, int, who, struct rusage *, usage);
  669. #endif
  670. //#define __NR_gettimeofday 78
  671. #ifdef L_gettimeofday
  672. #include <sys/time.h>
  673. _syscall2(int, gettimeofday, struct timeval *, tv, struct timezone *, tz);
  674. #endif
  675. //#define __NR_settimeofday 79
  676. #ifdef L_settimeofday
  677. #include <sys/time.h>
  678. _syscall2(int, settimeofday, const struct timeval *, tv,
  679. const struct timezone *, tz);
  680. #endif
  681. //#define __NR_getgroups 80
  682. #ifdef L_getgroups
  683. #include <unistd.h>
  684. _syscall2(int, getgroups, int, size, gid_t *, list);
  685. #endif
  686. //#define __NR_setgroups 81
  687. #ifdef L_setgroups
  688. #include <unistd.h>
  689. #include <grp.h>
  690. _syscall2(int, setgroups, size_t, size, const gid_t *, list);
  691. #endif
  692. //#define __NR_select 82
  693. #ifdef L_select
  694. //Used as a fallback if _newselect isn't available...
  695. #ifndef __NR__newselect
  696. #include <unistd.h>
  697. extern int select(int n, fd_set *readfds, fd_set *writefds,
  698. fd_set *exceptfds, struct timeval *timeout);
  699. _syscall5(int, select, int, n, fd_set *, readfds, fd_set *, writefds,
  700. fd_set *, exceptfds, struct timeval *, timeout);
  701. #endif
  702. #endif
  703. //#define __NR_symlink 83
  704. #ifdef L_symlink
  705. #include <unistd.h>
  706. _syscall2(int, symlink, const char *, oldpath, const char *, newpath);
  707. #endif
  708. //#define __NR_oldlstat 84
  709. //#define __NR_readlink 85
  710. #ifdef L_readlink
  711. #include <unistd.h>
  712. _syscall3(int, readlink, const char *, path, char *, buf, size_t, bufsiz);
  713. #endif
  714. //#define __NR_uselib 86
  715. #ifdef L_uselib
  716. #include <unistd.h>
  717. _syscall1(int, uselib, const char *, library);
  718. #endif
  719. //#define __NR_swapon 87
  720. #ifdef L_swapon
  721. #include <sys/swap.h>
  722. _syscall2(int, swapon, const char *, path, int, swapflags);
  723. #endif
  724. //#define __NR_reboot 88
  725. #ifdef L__reboot
  726. #define __NR__reboot __NR_reboot
  727. extern int _reboot(int magic, int magic2, int flag);
  728. _syscall3(int, _reboot, int, magic, int, magic2, int, flag);
  729. int reboot(int flag)
  730. {
  731. return (_reboot((int) 0xfee1dead, 672274793, flag));
  732. }
  733. #endif
  734. //#define __NR_readdir 89
  735. //#define __NR_mmap 90
  736. #ifdef L__mmap
  737. #define __NR__mmap __NR_mmap
  738. #include <unistd.h>
  739. #include <sys/mman.h>
  740. extern __ptr_t _mmap(unsigned long *buffer);
  741. _syscall1(__ptr_t, _mmap, unsigned long *, buffer);
  742. __ptr_t mmap(__ptr_t addr, size_t len, int prot,
  743. int flags, int fd, __off_t offset)
  744. {
  745. unsigned long buffer[6];
  746. buffer[0] = (unsigned long) addr;
  747. buffer[1] = (unsigned long) len;
  748. buffer[2] = (unsigned long) prot;
  749. buffer[3] = (unsigned long) flags;
  750. buffer[4] = (unsigned long) fd;
  751. buffer[5] = (unsigned long) offset;
  752. return (__ptr_t) _mmap(buffer);
  753. }
  754. #endif
  755. //#define __NR_munmap 91
  756. #ifdef L_munmap
  757. #include <unistd.h>
  758. #include <sys/mman.h>
  759. _syscall2(int, munmap, void *, start, size_t, length);
  760. #endif
  761. //#define __NR_truncate 92
  762. #ifdef L_truncate
  763. #include <unistd.h>
  764. _syscall2(int, truncate, const char *, path, __off_t, length);
  765. #endif
  766. //#define __NR_ftruncate 93
  767. #ifdef L_ftruncate
  768. #include <unistd.h>
  769. _syscall2(int, ftruncate, int, fd, __off_t, length);
  770. #endif
  771. //#define __NR_fchmod 94
  772. #ifdef L_fchmod
  773. #include <sys/stat.h>
  774. _syscall2(int, fchmod, int, fildes, mode_t, mode);
  775. #endif
  776. //#define __NR_fchown 95
  777. #ifdef L_fchown
  778. #include <unistd.h>
  779. _syscall3(int, fchown, int, fd, uid_t, owner, gid_t, group);
  780. #endif
  781. //#define __NR_getpriority 96
  782. #ifdef L_getpriority
  783. #include <sys/resource.h>
  784. _syscall2(int, getpriority, __priority_which_t, which, id_t, who);
  785. #endif
  786. //#define __NR_setpriority 97
  787. #ifdef L_setpriority
  788. #include <sys/resource.h>
  789. _syscall3(int, setpriority, __priority_which_t, which, id_t, who, int, prio);
  790. #endif
  791. //#define __NR_profil 98
  792. //#define __NR_statfs 99
  793. #ifdef L_statfs
  794. #include <sys/vfs.h>
  795. _syscall2(int, statfs, const char *, path, struct statfs *, buf);
  796. #endif
  797. //#define __NR_fstatfs 100
  798. #ifdef L_fstatfs
  799. #include <sys/vfs.h>
  800. _syscall2(int, fstatfs, int, fd, struct statfs *, buf);
  801. #endif
  802. //#define __NR_ioperm 101
  803. #ifdef L_ioperm
  804. # if defined __UCLIBC_HAS_MMU__ && defined __NR_ioperm
  805. _syscall3(int, ioperm, unsigned long, from, unsigned long, num, int, turn_on);
  806. # else
  807. int ioperm(unsigned long from, unsigned long num, int turn_on)
  808. {
  809. __set_errno(ENOSYS);
  810. return -1;
  811. }
  812. # endif
  813. #endif
  814. //#define __NR_socketcall 102
  815. #ifdef L_socketcall
  816. #ifdef __NR_socketcall
  817. _syscall2(int, socketcall, int, call, unsigned long *, args);
  818. #endif
  819. #endif
  820. //#define __NR_syslog 103
  821. #ifdef L__syslog
  822. #include <unistd.h>
  823. #define __NR__syslog __NR_syslog
  824. extern int _syslog(int type, char *buf, int len);
  825. _syscall3(int, _syslog, int, type, char *, buf, int, len);
  826. int klogctl(int type, char *buf, int len)
  827. {
  828. return (_syslog(type, buf, len));
  829. }
  830. #endif
  831. //#define __NR_setitimer 104
  832. #ifdef L_setitimer
  833. #include <sys/time.h>
  834. _syscall3(int, setitimer, __itimer_which_t, which,
  835. const struct itimerval *, new, struct itimerval *, old);
  836. #endif
  837. //#define __NR_getitimer 105
  838. #ifdef L_getitimer
  839. #include <sys/time.h>
  840. _syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value);
  841. #endif
  842. //#define __NR_stat 106
  843. #ifdef L___stat
  844. #include <unistd.h>
  845. #include "statfix.h"
  846. #define __NR___stat __NR_stat
  847. extern int __stat(const char *file_name, struct kernel_stat *buf);
  848. _syscall2(int, __stat, const char *, file_name, struct kernel_stat *, buf);
  849. int __xstat(int version, const char * file_name, struct libc_stat * cstat)
  850. {
  851. struct kernel_stat kstat;
  852. int result = __stat(file_name, &kstat);
  853. if (result == 0) {
  854. statfix(cstat, &kstat);
  855. }
  856. return result;
  857. }
  858. int stat(const char *file_name, struct libc_stat *buf)
  859. {
  860. return(__xstat(0, file_name, buf));
  861. }
  862. #if ! defined __NR_stat64 && defined __UCLIBC_HAVE_LFS__
  863. weak_alias(stat, stat64);
  864. weak_alias(__xstat, __xstat64);
  865. #endif
  866. #endif
  867. //#define __NR_lstat 107
  868. #ifdef L___lstat
  869. #include <unistd.h>
  870. #include "statfix.h"
  871. #define __NR___lstat __NR_lstat
  872. extern int __lstat(const char *file_name, struct kernel_stat *buf);
  873. _syscall2(int, __lstat, const char *, file_name, struct kernel_stat *, buf);
  874. int __lxstat(int version, const char * file_name, struct libc_stat * cstat)
  875. {
  876. struct kernel_stat kstat;
  877. int result = __lstat(file_name, &kstat);
  878. if (result == 0) {
  879. statfix(cstat, &kstat);
  880. }
  881. return result;
  882. }
  883. int lstat(const char *file_name, struct libc_stat *buf)
  884. {
  885. return(__lxstat(0, file_name, buf));
  886. }
  887. #if ! defined __NR_lstat64 && defined __UCLIBC_HAVE_LFS__
  888. weak_alias(lstat, lstat64);
  889. weak_alias(__lxstat, __lxstat64);
  890. #endif
  891. #endif
  892. //#define __NR_fstat 108
  893. #ifdef L___fstat
  894. #include <unistd.h>
  895. #include "statfix.h"
  896. #define __NR___fstat __NR_fstat
  897. extern int __fstat(int filedes, struct kernel_stat *buf);
  898. _syscall2(int, __fstat, int, filedes, struct kernel_stat *, buf);
  899. int __fxstat(int version, int fd, struct libc_stat * cstat)
  900. {
  901. struct kernel_stat kstat;
  902. int result = __fstat(fd, &kstat);
  903. if (result == 0) {
  904. statfix(cstat, &kstat);
  905. }
  906. return result;
  907. }
  908. int fstat(int filedes, struct libc_stat *buf)
  909. {
  910. return(__fxstat(0, filedes, buf));
  911. }
  912. #if ! defined __NR_fstat64 && defined __UCLIBC_HAVE_LFS__
  913. weak_alias(fstat, fstat64);
  914. weak_alias(__fxstat, __fxstat64);
  915. #endif
  916. #endif
  917. //#define __NR_olduname 109
  918. //#define __NR_iopl 110
  919. #ifdef L_iopl
  920. /* Tuns out the m68k unistd.h kernel header is broken */
  921. # if defined __UCLIBC_HAS_MMU__ && defined __NR_iopl && ! defined(__mc68000__)
  922. _syscall1(int, iopl, int, level);
  923. # else
  924. int iopl(int level)
  925. {
  926. __set_errno(ENOSYS);
  927. return -1;
  928. }
  929. # endif
  930. #endif
  931. //#define __NR_vhangup 111
  932. #ifdef L_vhangup
  933. #include <unistd.h>
  934. _syscall0(int, vhangup);
  935. #endif
  936. //#define __NR_idle 112
  937. //int idle(void);
  938. //#define __NR_vm86old 113
  939. //#define __NR_wait4 114
  940. #ifdef L_wait4
  941. _syscall4(int, wait4, pid_t, pid, int *, status, int, opts, void *, rusage);
  942. #endif
  943. //#define __NR_swapoff 115
  944. #ifdef L_swapoff
  945. #include <sys/swap.h>
  946. _syscall1(int, swapoff, const char *, path);
  947. #endif
  948. //#define __NR_sysinfo 116
  949. #ifdef L_sysinfo
  950. #include <sys/sysinfo.h>
  951. _syscall1(int, sysinfo, struct sysinfo *, info);
  952. #endif
  953. //#define __NR_ipc 117
  954. #ifdef L___ipc
  955. #ifdef __NR_ipc
  956. #define __NR___ipc __NR_ipc
  957. _syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, third, void *, ptr);
  958. #endif
  959. #endif
  960. //#define __NR_fsync 118
  961. #ifdef L___libc_fsync
  962. #include <unistd.h>
  963. #define __NR___libc_fsync __NR_fsync
  964. _syscall1(int, __libc_fsync, int, fd);
  965. weak_alias(__libc_fsync, fsync)
  966. #endif
  967. //#define __NR_sigreturn 119
  968. //int sigreturn(unsigned long __unused);
  969. //#define __NR_clone 120
  970. //See architecture specific implementation...
  971. //#define __NR_setdomainname 121
  972. #ifdef L_setdomainname
  973. #include <unistd.h>
  974. _syscall2(int, setdomainname, const char *, name, size_t, len);
  975. #endif
  976. //#define __NR_uname 122
  977. #ifdef L_uname
  978. #include <sys/utsname.h>
  979. _syscall1(int, uname, struct utsname *, buf);
  980. #endif
  981. //#define __NR_modify_ldt 123
  982. //#define __NR_adjtimex 124
  983. #ifdef L_adjtimex
  984. #include <sys/timex.h>
  985. _syscall1(int, adjtimex, struct timex *, buf);
  986. weak_alias(adjtimex, __adjtimex);
  987. #endif
  988. //#define __NR_mprotect 125
  989. #ifdef L_mprotect
  990. #include <sys/mman.h>
  991. _syscall3(int, mprotect, void *, addr, size_t, len, int, prot);
  992. #endif
  993. //#define __NR_sigprocmask 126
  994. #ifndef __NR_rt_sigprocmask
  995. #ifdef L_sigprocmask
  996. #include <signal.h>
  997. #undef sigprocmask
  998. _syscall3(int, sigprocmask, int, how, const sigset_t *, set,
  999. sigset_t *, oldset);
  1000. #endif
  1001. #endif
  1002. //#define __NR_create_module 127
  1003. //See sysdeps/linux/commom/create_module.c
  1004. //#define __NR_init_module 128
  1005. #ifdef L_init_module
  1006. /* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
  1007. * (for 2.2 and 2.4 kernels). Use the greatest common denominator,
  1008. * and let the kernel cope with whatever it gets. It's good at that. */
  1009. _syscall5(int, init_module, void *, first, void *, second, void *, third,
  1010. void *, fourth, void *, fifth);
  1011. #endif
  1012. //#define __NR_delete_module 129
  1013. #ifdef L_delete_module
  1014. # ifdef __NR_delete_module
  1015. _syscall1(int, delete_module, const char *, name);
  1016. # else
  1017. int delete_module(const char * name)
  1018. {
  1019. __set_errno(ENOSYS);
  1020. return -1;
  1021. }
  1022. # endif
  1023. #endif
  1024. //#define __NR_get_kernel_syms 130
  1025. #ifdef L_get_kernel_syms
  1026. struct kernel_sym;
  1027. _syscall1(int, get_kernel_syms, struct kernel_sym *, table);
  1028. #endif
  1029. //#define __NR_quotactl 131
  1030. #ifdef __NR_quotactl
  1031. #ifdef L_quotactl
  1032. #include <sys/quota.h>
  1033. _syscall4(int, quotactl, int, cmd, const char *, special , int, id, caddr_t, addr);
  1034. #endif
  1035. #endif
  1036. //#define __NR_getpgid 132
  1037. #ifdef L_getpgid
  1038. _syscall1(pid_t, getpgid, pid_t, pid);
  1039. #endif
  1040. //#define __NR_fchdir 133
  1041. #ifdef L_fchdir
  1042. #include <unistd.h>
  1043. _syscall1(int, fchdir, int, fd);
  1044. #endif
  1045. //#define __NR_bdflush 134
  1046. #ifdef L_bdflush
  1047. #include <sys/kdaemon.h>
  1048. _syscall2(int, bdflush, int, __func, long int, __data);
  1049. #endif
  1050. //#define __NR_sysfs 135
  1051. //#define __NR_personality 136
  1052. //#define __NR_afs_syscall 137
  1053. //#define __NR_setfsuid 138
  1054. #ifdef __NR_setfsuid
  1055. #ifdef L_setfsuid
  1056. #include <sys/fsuid.h>
  1057. _syscall1(int, setfsuid, uid_t, uid);
  1058. #endif
  1059. #endif
  1060. //#define __NR_setfsgid 139
  1061. #ifdef __NR_setfsgid
  1062. #ifdef L_setfsgid
  1063. #include <sys/fsuid.h>
  1064. _syscall1(int, setfsgid, gid_t, gid);
  1065. #endif
  1066. #endif
  1067. //#define __NR__llseek 140
  1068. #ifdef L__llseek
  1069. #ifdef __UCLIBC_HAVE_LFS__
  1070. #ifdef __NR__llseek
  1071. extern int _llseek(int fd, __off_t offset_hi, __off_t offset_lo,
  1072. __loff_t *result, int whence);
  1073. _syscall5(int, _llseek, int, fd, __off_t, offset_hi, __off_t, offset_lo,
  1074. __loff_t *, result, int, whence);
  1075. __loff_t __libc_lseek64(int fd, __loff_t offset, int whence)
  1076. {
  1077. int ret;
  1078. __loff_t result;
  1079. ret = _llseek(fd, (__off_t) (offset >> 32),
  1080. (__off_t) (offset & 0xffffffff), &result, whence);
  1081. return ret ? (__loff_t) ret : result;
  1082. }
  1083. weak_alias(__libc_lseek64, llseek);
  1084. weak_alias(__libc_lseek64, lseek64);
  1085. #endif
  1086. #endif
  1087. #endif
  1088. //#define __NR_getdents 141
  1089. #ifdef L_getdents
  1090. #include <unistd.h>
  1091. #include <dirent.h>
  1092. _syscall3(int, getdents, int, fd, char *, dirp, size_t, count);
  1093. #endif
  1094. //#define __NR__newselect 142
  1095. #ifdef L__newselect
  1096. //Used in preference to select when available...
  1097. #ifdef __NR__newselect
  1098. #include <unistd.h>
  1099. extern int _newselect(int n, fd_set *readfds, fd_set *writefds,
  1100. fd_set *exceptfds, struct timeval *timeout);
  1101. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  1102. fd_set *, exceptfds, struct timeval *, timeout);
  1103. weak_alias(_newselect, select);
  1104. #endif
  1105. #endif
  1106. //#define __NR_flock 143
  1107. #ifdef L_flock
  1108. #include <sys/file.h>
  1109. _syscall2(int,flock,int,fd, int,operation);
  1110. #endif
  1111. //#define __NR_msync 144
  1112. #ifdef L___libc_msync
  1113. #include <unistd.h>
  1114. #include <sys/mman.h>
  1115. #define __NR___libc_msync __NR_msync
  1116. _syscall3(int, __libc_msync, void *, addr, size_t, length, int, flags);
  1117. weak_alias(__libc_msync, msync);
  1118. #endif
  1119. //#define __NR_readv 145
  1120. #ifdef L_readv
  1121. #include <sys/uio.h>
  1122. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  1123. count);
  1124. #endif
  1125. //#define __NR_writev 146
  1126. #ifdef L_writev
  1127. #include <sys/uio.h>
  1128. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  1129. count);
  1130. #endif
  1131. //#define __NR_getsid 147
  1132. #ifdef L_getsid
  1133. #include <unistd.h>
  1134. _syscall1(pid_t, getsid, pid_t, pid);
  1135. #endif
  1136. //#define __NR_fdatasync 148
  1137. #ifdef __NR_fdatasync
  1138. #ifdef L_fdatasync
  1139. #include <unistd.h>
  1140. _syscall1(int, fdatasync, int, fd);
  1141. #endif
  1142. #endif
  1143. //#define __NR__sysctl 149
  1144. //#define __NR_mlock 150
  1145. #ifdef L_mlock
  1146. #include <sys/mman.h>
  1147. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlock
  1148. _syscall2(int, mlock, const void *, addr, size_t, len);
  1149. # endif
  1150. #endif
  1151. //#define __NR_munlock 151
  1152. #ifdef L_munlock
  1153. #include <sys/mman.h>
  1154. # if defined __UCLIBC_HAS_MMU__ && defined __NR_munlock
  1155. _syscall2(int, munlock, const void *, addr, size_t, len);
  1156. # endif
  1157. #endif
  1158. //#define __NR_mlockall 152
  1159. #ifdef L_mlockall
  1160. #include <sys/mman.h>
  1161. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlockall
  1162. _syscall1(int, mlockall, int, flags);
  1163. # endif
  1164. #endif
  1165. //#define __NR_munlockall 153
  1166. #ifdef L_munlockall
  1167. #include <sys/mman.h>
  1168. # if defined __UCLIBC_HAS_MMU__ && defined L_munlockall
  1169. _syscall0(int, munlockall);
  1170. # endif
  1171. #endif
  1172. //#define __NR_sched_setparam 154
  1173. #ifdef __NR_sched_setparam
  1174. #ifdef L_sched_setparam
  1175. #include <sched.h>
  1176. _syscall2(int, sched_setparam, pid_t, pid, const struct sched_param *, p);
  1177. #endif
  1178. #endif
  1179. //#define __NR_sched_getparam 155
  1180. #ifdef __NR_sched_getparam
  1181. #ifdef L_sched_getparam
  1182. #include <sched.h>
  1183. _syscall2(int, sched_getparam, pid_t, pid, struct sched_param *, p);
  1184. #endif
  1185. #endif
  1186. //#define __NR_sched_setscheduler 156
  1187. #ifdef __NR_sched_setscheduler
  1188. #ifdef L_sched_setscheduler
  1189. #include <sched.h>
  1190. _syscall3(int, sched_setscheduler, pid_t, pid, int, policy, const struct sched_param *, p);
  1191. #endif
  1192. #endif
  1193. //#define __NR_sched_getscheduler 157
  1194. #ifdef __NR_sched_getscheduler
  1195. #ifdef L_sched_getscheduler
  1196. #include <sched.h>
  1197. _syscall1(int, sched_getscheduler, pid_t, pid);
  1198. #endif
  1199. #endif
  1200. //#define __NR_sched_yield 158
  1201. #ifdef __NR_sched_yield
  1202. #ifdef L_sched_yield
  1203. #include <sched.h>
  1204. _syscall0(int, sched_yield);
  1205. #endif
  1206. #endif
  1207. //#define __NR_sched_get_priority_max 159
  1208. #ifdef __NR_sched_get_priority_max
  1209. #ifdef L_sched_get_priority_max
  1210. #include <sched.h>
  1211. _syscall1(int, sched_get_priority_max, int, policy);
  1212. #endif
  1213. #endif
  1214. //#define __NR_sched_get_priority_min 160
  1215. #ifdef __NR_sched_get_priority_min
  1216. #ifdef L_sched_get_priority_min
  1217. #include <sched.h>
  1218. _syscall1(int, sched_get_priority_min, int, policy);
  1219. #endif
  1220. #endif
  1221. //#define __NR_sched_rr_get_interval 161
  1222. #ifdef __NR_sched_rr_get_interval
  1223. #ifdef L_sched_rr_get_interval
  1224. #include <sched.h>
  1225. _syscall2(int, sched_rr_get_interval, pid_t, pid, struct timespec *, tp);
  1226. #endif
  1227. #endif
  1228. //#define __NR_nanosleep 162
  1229. #ifdef L___libc_nanosleep
  1230. #include <time.h>
  1231. #define __NR___libc_nanosleep __NR_nanosleep
  1232. _syscall2(int, __libc_nanosleep, const struct timespec *, req, struct timespec *, rem);
  1233. weak_alias(__libc_nanosleep, nanosleep)
  1234. #endif
  1235. //#define __NR_mremap 163
  1236. #ifdef L_mremap
  1237. #include <unistd.h>
  1238. #include <sys/mman.h>
  1239. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t, new_size, int, may_move);
  1240. #endif
  1241. //#define __NR_setresuid 164
  1242. //#define __NR_getresuid 165
  1243. //#define __NR_vm86 166
  1244. //#define __NR_query_module 167
  1245. #ifdef L_query_module
  1246. # ifdef __NR_query_module
  1247. _syscall5(int, query_module, const char *, name, int, which,
  1248. void *, buf, size_t, bufsize, size_t*, ret);
  1249. # else
  1250. int query_module(const char * name, int which,
  1251. void * buf, size_t bufsize, size_t* ret)
  1252. {
  1253. __set_errno(ENOSYS);
  1254. return -1;
  1255. }
  1256. # endif
  1257. #endif
  1258. //#define __NR_poll 168
  1259. #if defined(L_poll) && defined(__NR_poll) /* uClinux 2.0 doesn't have poll */
  1260. #include <sys/poll.h>
  1261. _syscall3(int, poll, struct pollfd *, fds, unsigned long int, nfds, int, timeout);
  1262. #endif
  1263. //#define __NR_nfsservctl 169
  1264. //nfsservctl EXTRA nfsservctl i:ipp nfsservctl
  1265. //#define __NR_setresgid 170
  1266. //#define __NR_getresgid 171
  1267. //#define __NR_prctl 172
  1268. //#define __NR_rt_sigreturn 173
  1269. //#define __NR_rt_sigaction 174
  1270. #ifdef __NR_rt_sigaction
  1271. #define __NR___rt_sigaction __NR_rt_sigaction
  1272. #ifdef L___rt_sigaction
  1273. #include <signal.h>
  1274. #undef sigaction
  1275. _syscall4(int, __rt_sigaction, int, signum, const struct sigaction *, act,
  1276. struct sigaction *, oldact, size_t, size);
  1277. #endif
  1278. #endif
  1279. //#define __NR_rt_sigprocmask 175
  1280. #ifdef __NR_rt_sigprocmask
  1281. #define __NR___rt_sigprocmask __NR_rt_sigprocmask
  1282. #ifdef L___rt_sigprocmask
  1283. #include <signal.h>
  1284. #undef sigprocmask
  1285. _syscall4(int, __rt_sigprocmask, int, how, const sigset_t *, set,
  1286. sigset_t *, oldset, size_t, size);
  1287. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
  1288. {
  1289. return __rt_sigprocmask(how, set, oldset, _NSIG/8);
  1290. }
  1291. #endif
  1292. #endif
  1293. //#define __NR_rt_sigpending 176
  1294. #ifdef __NR_rt_sigpending
  1295. #define __NR___rt_sigpending __NR_rt_sigpending
  1296. #ifdef L___rt_sigpending
  1297. #include <signal.h>
  1298. #undef sigpending
  1299. _syscall2(int, __rt_sigpending, sigset_t *, set, size_t, size);
  1300. int sigpending(sigset_t *set)
  1301. {
  1302. return __rt_sigpending(set, _NSIG/8);
  1303. }
  1304. #endif
  1305. #endif
  1306. //#define __NR_rt_sigtimedwait 177
  1307. #ifdef L___rt_sigtimedwait
  1308. #ifdef __NR_rt_sigtimedwait
  1309. #define __NR___rt_sigtimedwait __NR_rt_sigtimedwait
  1310. #include <signal.h>
  1311. #define __need_NULL
  1312. #include <stddef.h>
  1313. _syscall4(int, __rt_sigtimedwait, const sigset_t *, set, siginfo_t *, info,
  1314. const struct timespec *, timeout, size_t, setsize);
  1315. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1316. {
  1317. return __rt_sigtimedwait (set, info, NULL, _NSIG/8);
  1318. }
  1319. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1320. {
  1321. return __rt_sigtimedwait (set, info, timeout, _NSIG/8);
  1322. }
  1323. #else
  1324. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1325. {
  1326. if (set==NULL)
  1327. __set_errno (EINVAL);
  1328. else
  1329. __set_errno (ENOSYS);
  1330. return -1;
  1331. }
  1332. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1333. {
  1334. if (set==NULL)
  1335. __set_errno (EINVAL);
  1336. else
  1337. __set_errno (ENOSYS);
  1338. return -1;
  1339. }
  1340. #endif
  1341. #endif
  1342. //#define __NR_rt_sigqueueinfo 178
  1343. //#define __NR_rt_sigsuspend 179
  1344. #ifdef __NR_rt_sigsuspend
  1345. #define __NR___rt_sigsuspend __NR_rt_sigsuspend
  1346. #ifdef L___rt_sigsuspend
  1347. #include <signal.h>
  1348. #undef _sigsuspend
  1349. _syscall2(int, __rt_sigsuspend, const sigset_t *, mask, size_t, size);
  1350. int sigsuspend (const sigset_t *mask)
  1351. {
  1352. return __rt_sigsuspend(mask, _NSIG/8);
  1353. }
  1354. #endif
  1355. #endif
  1356. //#define __NR_pread 180
  1357. #ifdef L___libc_pread
  1358. #ifdef __NR_pread
  1359. #define _XOPEN_SOURCE 500
  1360. #include <unistd.h>
  1361. #define __NR___libc_pread __NR_pread
  1362. _syscall4(ssize_t, __libc_pread, int, fd, void *, buf, size_t, count, __off_t, offset);
  1363. weak_alias (__libc_pread, pread)
  1364. #else
  1365. ssize_t pread(int fd, void *buf, size_t count, off_t offset)
  1366. {
  1367. __set_errno(ENOSYS);
  1368. return -1;
  1369. }
  1370. #endif
  1371. #endif
  1372. //#define __NR_pwrite 181
  1373. #ifdef L___libc_pwrite
  1374. #ifdef __NR_pwrite
  1375. #define _XOPEN_SOURCE 500
  1376. #include <unistd.h>
  1377. #define __NR___libc_pwrite __NR_pwrite
  1378. _syscall4(ssize_t, __libc_pwrite, int, fd, const void *, buf, size_t, count, __off_t, offset);
  1379. weak_alias (__libc_pwrite, pwrite)
  1380. #else
  1381. ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
  1382. {
  1383. __set_errno(ENOSYS);
  1384. return -1;
  1385. }
  1386. #endif
  1387. #endif
  1388. //#define __NR_chown 182
  1389. #ifdef L_chown
  1390. #include <unistd.h>
  1391. _syscall3(int, chown, const char *, path, uid_t, owner, gid_t, group);
  1392. #endif
  1393. //#define __NR_getcwd 183
  1394. // See getcwd.c in this directory
  1395. //#define __NR_capget 184
  1396. #ifdef L_capget
  1397. # ifdef __NR_capget
  1398. _syscall2(int, capget, void*, header, void*, data);
  1399. # else
  1400. int capget(void* header, void* data)
  1401. {
  1402. __set_errno(ENOSYS);
  1403. return -1;
  1404. }
  1405. # endif
  1406. #endif
  1407. //#define __NR_capset 185
  1408. #ifdef L_capset
  1409. # ifdef __NR_capset
  1410. _syscall2(int, capset, void*, header, const void*, data);
  1411. # else
  1412. int capset(void* header, const void* data)
  1413. {
  1414. __set_errno(ENOSYS);
  1415. return -1;
  1416. }
  1417. # endif
  1418. #endif
  1419. //#define __NR_sigaltstack 186
  1420. #ifdef __NR_sigaltstack
  1421. #ifdef L_sigaltstack
  1422. #include <signal.h>
  1423. _syscall2(int, sigaltstack, const struct sigaltstack *, ss, struct sigaltstack *, oss);
  1424. #endif
  1425. #endif
  1426. //#define __NR_sendfile 187
  1427. #ifdef __NR_sendfile
  1428. #ifdef L_sendfile
  1429. #include <unistd.h>
  1430. #include <sys/sendfile.h>
  1431. _syscall4(ssize_t,sendfile, int, out_fd, int, in_fd, __off_t *, offset, size_t, count)
  1432. #endif
  1433. #endif
  1434. //#define __NR_getpmsg 188
  1435. //#define __NR_putpmsg 189
  1436. //#define __NR_vfork 190
  1437. //See sysdeps/linux/<arch>vfork.[cS] for architecture specific implementation...
  1438. //#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
  1439. #ifdef L___ugetrlimit
  1440. #ifdef __NR_ugetrlimit
  1441. #define __NR___ugetrlimit __NR_ugetrlimit
  1442. #include <unistd.h>
  1443. #include <sys/resource.h>
  1444. _syscall2(int, __ugetrlimit, enum __rlimit_resource, resource, struct rlimit *, rlim);
  1445. int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
  1446. {
  1447. return(__ugetrlimit(resource, rlimits));
  1448. }
  1449. #endif /* __NR_ugetrlimit */
  1450. #endif
  1451. //#define __NR_mmap2 192
  1452. //#define __NR_truncate64 193
  1453. //See libc/sysdeps/linux/common/truncate64.c
  1454. //#define __NR_ftruncate64 194
  1455. //See libc/sysdeps/linux/common/ftruncate64.c
  1456. //#define __NR_stat64 195
  1457. #ifdef L___stat64
  1458. #if defined __NR_stat64 && defined __UCLIBC_HAVE_LFS__
  1459. #include <unistd.h>
  1460. #include "statfix64.h"
  1461. #define __NR___stat64 __NR_stat64
  1462. extern int __stat64(const char *file_name, struct kernel_stat64 *buf);
  1463. _syscall2(int, __stat64, const char *, file_name, struct kernel_stat64 *, buf);
  1464. int __xstat64(int version, const char * file_name, struct libc_stat64 * cstat)
  1465. {
  1466. struct kernel_stat64 kstat;
  1467. int result = __stat64(file_name, &kstat);
  1468. if (result == 0) {
  1469. statfix64(cstat, &kstat);
  1470. }
  1471. return result;
  1472. }
  1473. int stat64(const char *file_name, struct libc_stat64 *buf)
  1474. {
  1475. return(__xstat64(0, file_name, buf));
  1476. }
  1477. #endif /* __UCLIBC_HAVE_LFS__ */
  1478. #endif
  1479. //#define __NR_lstat64 196
  1480. #ifdef L___lstat64
  1481. #if defined __NR_lstat64 && defined __UCLIBC_HAVE_LFS__
  1482. #include <unistd.h>
  1483. #include "statfix64.h"
  1484. #define __NR___lstat64 __NR_lstat64
  1485. extern int __lstat64(const char *file_name, struct kernel_stat64 *buf);
  1486. _syscall2(int, __lstat64, const char *, file_name, struct kernel_stat64 *, buf);
  1487. int __lxstat64(int version, const char * file_name, struct libc_stat64 * cstat)
  1488. {
  1489. struct kernel_stat64 kstat;
  1490. int result = __lstat64(file_name, &kstat);
  1491. if (result == 0) {
  1492. statfix64(cstat, &kstat);
  1493. }
  1494. return result;
  1495. }
  1496. int lstat64(const char *file_name, struct libc_stat64 *buf)
  1497. {
  1498. return(__lxstat64(0, file_name, buf));
  1499. }
  1500. #endif /* __UCLIBC_HAVE_LFS__ */
  1501. #endif
  1502. //#define __NR_fstat64 197
  1503. #ifdef L___fstat64
  1504. #if defined __NR_fstat64 && defined __UCLIBC_HAVE_LFS__
  1505. #include <unistd.h>
  1506. #include "statfix64.h"
  1507. #define __NR___fstat64 __NR_fstat64
  1508. extern int __fstat64(int filedes, struct kernel_stat64 *buf);
  1509. _syscall2(int, __fstat64, int, filedes, struct kernel_stat64 *, buf);
  1510. int __fxstat64(int version, int fd, struct libc_stat64 * cstat)
  1511. {
  1512. struct kernel_stat64 kstat;
  1513. int result = __fstat64(fd, &kstat);
  1514. if (result == 0) {
  1515. statfix64(cstat, &kstat);
  1516. }
  1517. return result;
  1518. }
  1519. int fstat64(int filedes, struct libc_stat64 *buf)
  1520. {
  1521. return(__fxstat64(0, filedes, buf));
  1522. }
  1523. #endif /* __UCLIBC_HAVE_LFS__ */
  1524. #endif
  1525. //#define __NR_lchown32 198
  1526. //#define __NR_getuid32 199
  1527. //#define __NR_getgid32 200
  1528. //#define __NR_geteuid32 201
  1529. //#define __NR_getegid32 202
  1530. //#define __NR_setreuid32 203
  1531. //#define __NR_setregid32 204
  1532. //#define __NR_getgroups32 205
  1533. //#define __NR_setgroups32 206
  1534. //#define __NR_fchown32 207
  1535. //#define __NR_setresuid32 208
  1536. //#define __NR_getresuid32 209
  1537. //#define __NR_setresgid32 210
  1538. //#define __NR_getresgid32 211
  1539. //#define __NR_chown32 212
  1540. //#define __NR_setuid32 213
  1541. //#define __NR_setgid32 214
  1542. //#define __NR_setfsuid32 215
  1543. //#define __NR_setfsgid32 216
  1544. //#define __NR_pivot_root 217
  1545. #ifdef __NR_pivot_root
  1546. #ifdef L_pivot_root
  1547. _syscall2(int, pivot_root, const char *, new_root, const char *, put_old)
  1548. #endif
  1549. #endif
  1550. //#define __NR_mincore 218
  1551. //#define __NR_madvise 219
  1552. //#define __NR_madvise1 219 /* delete when C lib stub is removed */
  1553. //#define __NR_getdents64 220
  1554. #ifdef L_getdents64
  1555. #ifdef __UCLIBC_HAVE_LFS__
  1556. #include <unistd.h>
  1557. #include <dirent.h>
  1558. _syscall3(int, getdents64, int, fd, char *, dirp, size_t, count);
  1559. #endif /* __UCLIBC_HAVE_LFS__ */
  1560. #endif
  1561. //#define __NR_fcntl64 221
  1562. #ifdef L__fcntl64
  1563. #ifdef __UCLIBC_HAVE_LFS__
  1564. #ifdef __NR_fcntl64
  1565. #define __NR__fcntl64 __NR_fcntl64
  1566. #include <stdarg.h>
  1567. #include <fcntl.h>
  1568. extern int _fcntl64(int fd, int cmd, long arg);
  1569. _syscall3(int, _fcntl64, int, fd, int, cmd, long, arg);
  1570. int fcntl64(int fd, int command, ...)
  1571. {
  1572. long arg;
  1573. va_list list;
  1574. va_start(list, command);
  1575. arg = va_arg(list, long);
  1576. va_end(list);
  1577. return _fcntl64(fd, command, arg);
  1578. }
  1579. #else
  1580. extern int __libc_fcntl(int fd, int command, ...);
  1581. weak_alias(__libc_fcntl, fcntl64)
  1582. #endif
  1583. #endif
  1584. #endif
  1585. //#define __NR_security 223 /* syscall for security modules */
  1586. //#define __NR_gettid 224
  1587. //#define __NR_readahead 225