syscalls.c 43 KB

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