syscalls.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Syscalls for uClibc
  4. *
  5. * Copyright (C) 2001-2003 by Erik Andersen
  6. * Written by Erik Andersen <andersen@codpoet.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU Library General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #define _GNU_SOURCE
  24. #define _LARGEFILE64_SOURCE
  25. #include <features.h>
  26. #undef __OPTIMIZE__
  27. /* We absolutely do _NOT_ want interfaces silently
  28. * * * renamed under us or very bad things will happen... */
  29. #ifdef __USE_FILE_OFFSET64
  30. # undef __USE_FILE_OFFSET64
  31. #endif
  32. #include <errno.h>
  33. #include <sys/types.h>
  34. #include <sys/syscall.h>
  35. #include <endian.h>
  36. //#define __NR_exit 1
  37. //See _exit.c
  38. //#define __NR_fork 2
  39. #ifdef L___libc_fork
  40. #include <unistd.h>
  41. # ifdef __ARCH_HAS_MMU__
  42. #define __NR___libc_fork __NR_fork
  43. _syscall0(pid_t, __libc_fork);
  44. # else
  45. pid_t __libc_fork(void)
  46. {
  47. __set_errno(ENOSYS);
  48. return -1;
  49. }
  50. # endif
  51. weak_alias (__libc_fork, fork)
  52. #endif
  53. //#define __NR_read 3
  54. #ifdef L___libc_read
  55. #include <unistd.h>
  56. #define __NR___libc_read __NR_read
  57. _syscall3(ssize_t, __libc_read, int, fd, __ptr_t, buf, size_t, count);
  58. weak_alias(__libc_read, read)
  59. #endif
  60. //#define __NR_write 4
  61. #ifdef L___libc_write
  62. #include <unistd.h>
  63. #define __NR___libc_write __NR_write
  64. _syscall3(ssize_t, __libc_write, int, fd, const __ptr_t, buf, size_t, count);
  65. weak_alias(__libc_write, write)
  66. /* Stupid libgcc.a from gcc 2.95.x uses __write in pure.o
  67. * which is a blatent GNU libc-ism... */
  68. weak_alias (__libc_write, __write)
  69. #endif
  70. //#define __NR_open 5
  71. #ifdef L___syscall_open
  72. #define __NR___syscall_open __NR_open
  73. #include <stdlib.h>
  74. #include <stdarg.h>
  75. #include <fcntl.h>
  76. #include <string.h>
  77. #include <sys/param.h>
  78. static inline
  79. _syscall3(int, __syscall_open, const char *, file, int, flags, __kernel_mode_t, mode);
  80. int __libc_open (const char * file, int flags, ...)
  81. {
  82. mode_t mode;
  83. if (flags & O_CREAT) {
  84. va_list ap;
  85. va_start(ap, flags);
  86. mode = va_arg(ap, mode_t);
  87. va_end(ap);
  88. }
  89. return __syscall_open(file, flags, mode);
  90. }
  91. weak_alias(__libc_open, open)
  92. int creat(const char *file, mode_t mode)
  93. {
  94. return __libc_open (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
  95. }
  96. #endif
  97. //#define __NR_close 6
  98. #ifdef L___libc_close
  99. #include <unistd.h>
  100. #define __NR___libc_close __NR_close
  101. _syscall1(int, __libc_close, int, fd);
  102. weak_alias(__libc_close, close)
  103. #endif
  104. //#define __NR_waitpid 7
  105. // Implemented using wait4
  106. //#define __NR_creat 8
  107. // Implemented using open
  108. //#define __NR_link 9
  109. #ifdef L_link
  110. #include <unistd.h>
  111. _syscall2(int, link, const char *, oldpath, const char *, newpath);
  112. #endif
  113. //#define __NR_unlink 10
  114. #ifdef L_unlink
  115. #include <unistd.h>
  116. _syscall1(int, unlink, const char *, pathname);
  117. #endif
  118. //#define __NR_execve 11
  119. #ifdef L___syscall_execve
  120. #define __NR___syscall_execve __NR_execve
  121. #include <unistd.h>
  122. #include <string.h>
  123. #include <sys/param.h>
  124. static inline
  125. _syscall3(int, __syscall_execve, const char *, filename,
  126. char *const *, argv, char *const *, envp);
  127. weak_alias(__syscall_execve, execve)
  128. #endif
  129. //#define __NR_chdir 12
  130. #ifdef L___syscall_chdir
  131. #define __NR___syscall_chdir __NR_chdir
  132. #include <string.h>
  133. #include <sys/param.h>
  134. static inline
  135. _syscall1(int, __syscall_chdir, const char *, path);
  136. weak_alias(__syscall_chdir, chdir)
  137. #endif
  138. //#define __NR_time 13
  139. #ifdef L_time
  140. #include <time.h>
  141. #include <sys/time.h>
  142. #ifdef __NR_time
  143. _syscall1(time_t, time, time_t *, t);
  144. #else
  145. time_t time (time_t *t)
  146. {
  147. time_t result;
  148. struct timeval tv;
  149. if (gettimeofday (&tv, (struct timezone *) NULL)) {
  150. result = (time_t) -1;
  151. } else { result = (time_t) tv.tv_sec; }
  152. if (t != NULL) { *t = result; }
  153. return result;
  154. }
  155. #endif
  156. #endif
  157. //#define __NR_mknod 14
  158. #ifdef L___syscall_mknod
  159. #define __NR___syscall_mknod __NR_mknod
  160. #include <sys/stat.h>
  161. _syscall3(int, __syscall_mknod, const char *, path, __kernel_mode_t, mode, __kernel_dev_t, dev);
  162. int mknod(const char *path, mode_t mode, dev_t dev)
  163. {
  164. /* We must convert the dev_t value to a __kernel_dev_t */
  165. __kernel_dev_t k_dev;
  166. k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff);
  167. return __syscall_mknod(path, mode, k_dev);
  168. }
  169. #endif
  170. //#define __NR_chmod 15
  171. #ifdef L___syscall_chmod
  172. #include <sys/stat.h>
  173. #define __NR___syscall_chmod __NR_chmod
  174. static inline
  175. _syscall2(int, __syscall_chmod, const char *, path, __kernel_mode_t, mode);
  176. int chmod(const char *path, mode_t mode)
  177. {
  178. return __syscall_chmod(path, mode);
  179. }
  180. #endif
  181. /* Old kernels don't have lchown -- do chown instead. This
  182. * is sick and wrong, but at least things will compile.
  183. * They may not follow links when they should though... */
  184. #ifndef __NR_lchown
  185. #define __NR_lchown __NR_chown
  186. #endif
  187. //#define __NR_lchown 16
  188. #ifdef L___syscall_lchown
  189. #include <unistd.h>
  190. #define __NR___syscall_lchown __NR_lchown
  191. static inline
  192. _syscall3(int, __syscall_lchown, const char *, path, __kernel_uid_t, owner, __kernel_gid_t, group);
  193. int lchown(const char *path, uid_t owner, gid_t group)
  194. {
  195. if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
  196. || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  197. {
  198. __set_errno (EINVAL);
  199. return -1;
  200. }
  201. return __syscall_lchown(path, owner, group);
  202. }
  203. #endif
  204. //#define __NR_break 17
  205. //#define __NR_oldstat 18
  206. //#define __NR_lseek 19
  207. #ifdef L___libc_lseek
  208. #include <unistd.h>
  209. #define __NR___libc_lseek __NR_lseek
  210. _syscall3(__off_t, __libc_lseek, int, fildes, __off_t, offset, int, whence);
  211. weak_alias(__libc_lseek, lseek)
  212. #endif
  213. //#define __NR_getpid 20
  214. #ifdef L___libc_getpid
  215. #include <unistd.h>
  216. #if defined (__alpha__)
  217. #define __NR_getpid __NR_getxpid
  218. #endif
  219. #define __NR___libc_getpid __NR_getpid
  220. _syscall0(pid_t, __libc_getpid);
  221. weak_alias(__libc_getpid, getpid)
  222. weak_alias(__libc_getpid, __getpid)
  223. #endif
  224. //#define __NR_mount 21
  225. #ifdef L_mount
  226. #include <sys/mount.h>
  227. _syscall5(int, mount, const char *, specialfile, const char *, dir,
  228. const char *, filesystemtype, unsigned long, rwflag,
  229. const void *, data);
  230. #endif
  231. //#define __NR_umount 22
  232. #ifdef L_umount
  233. #include <sys/mount.h>
  234. _syscall1(int, umount, const char *, specialfile);
  235. #endif
  236. //#define __NR_setuid 23
  237. #ifdef L___syscall_setuid
  238. #define __NR___syscall_setuid __NR_setuid
  239. #include <unistd.h>
  240. static inline
  241. _syscall1(int, __syscall_setuid, __kernel_uid_t, uid);
  242. int setuid(uid_t uid)
  243. {
  244. if (uid == (uid_t) ~0 || uid != (uid_t) ((__kernel_uid_t) uid)) {
  245. __set_errno (EINVAL);
  246. return -1;
  247. }
  248. return(__syscall_setuid(uid));
  249. }
  250. #endif
  251. //#define __NR_getuid 24
  252. #ifdef L___syscall_getuid
  253. #include <unistd.h>
  254. #if defined (__alpha__)
  255. #define __NR_getuid __NR_getxuid
  256. #endif
  257. #define __NR___syscall_getuid __NR_getuid
  258. static inline
  259. _syscall0(int, __syscall_getuid);
  260. uid_t getuid(void)
  261. {
  262. return(__syscall_getuid());
  263. }
  264. #endif
  265. //#define __NR_stime 25
  266. #ifdef L_stime
  267. #include <time.h>
  268. #include <sys/time.h>
  269. #ifdef __NR_stime
  270. _syscall1(int, stime, const time_t *, t);
  271. #else
  272. int stime(const time_t *when)
  273. {
  274. struct timeval tv;
  275. if (when == NULL) { __set_errno (EINVAL); return -1; }
  276. tv.tv_sec = *when;
  277. tv.tv_usec = 0;
  278. return settimeofday (&tv, (struct timezone *) 0);
  279. }
  280. #endif
  281. #endif
  282. //#define __NR_ptrace 26
  283. //See ptrace.c
  284. //#define __NR_alarm 27
  285. #ifdef L_alarm
  286. #include <unistd.h>
  287. #ifdef __NR_alarm
  288. _syscall1(unsigned int, alarm, unsigned int, seconds);
  289. #else
  290. #include <sys/time.h>
  291. unsigned int alarm (unsigned int seconds)
  292. {
  293. struct itimerval old, new;
  294. unsigned int retval;
  295. new.it_value.tv_usec = 0;
  296. new.it_interval.tv_sec = 0;
  297. new.it_interval.tv_usec = 0;
  298. new.it_value.tv_sec = (long int) seconds;
  299. if (setitimer (ITIMER_REAL, &new, &old) < 0) { return 0; }
  300. retval = old.it_value.tv_sec;
  301. if (old.it_value.tv_usec) { ++retval; }
  302. return retval;
  303. }
  304. #endif
  305. #endif
  306. //#define __NR_oldfstat 28
  307. //#define __NR_pause 29
  308. #ifdef L___libc_pause
  309. #include <unistd.h>
  310. #ifdef __NR_pause
  311. #define __NR___libc_pause __NR_pause
  312. _syscall0(int, __libc_pause);
  313. weak_alias(__libc_pause, pause)
  314. #else
  315. #include <signal.h>
  316. int __libc_pause (void)
  317. {
  318. return(__sigpause(sigblock(0), 0));
  319. }
  320. weak_alias(__libc_pause, pause)
  321. #endif
  322. #endif
  323. //#define __NR_utime 30
  324. #ifdef L_utime
  325. #include <utime.h>
  326. #ifdef __NR_utime
  327. _syscall2(int, utime, const char *, file, const struct utimbuf *, times);
  328. #else
  329. #include <stdlib.h>
  330. #include <sys/time.h>
  331. int utime(const char *file, const struct utimbuf *times)
  332. {
  333. struct timeval timevals[2];
  334. if (times != NULL) {
  335. timevals[0].tv_usec = 0L;
  336. timevals[1].tv_usec = 0L;
  337. timevals[0].tv_sec = (long int) times->actime;
  338. timevals[1].tv_sec = (long int) times->modtime;
  339. } else {
  340. if (gettimeofday (&timevals[0], NULL) < 0) { return -1; }
  341. timevals[1] = timevals[0];
  342. }
  343. return utimes(file, timevals);
  344. }
  345. #endif
  346. #endif
  347. //#define __NR_utimed
  348. #ifdef L_utimes
  349. #include <utime.h>
  350. #ifdef __NR_utimes
  351. _syscall2(int, utimes, const char *, file, const struct timeval *, tvp);
  352. #else
  353. #include <stdlib.h>
  354. #include <sys/time.h>
  355. int utimes (const char *file, const struct timeval tvp[2])
  356. {
  357. struct utimbuf buf, *times;
  358. if (tvp) {
  359. times = &buf;
  360. times->actime = tvp[0].tv_sec;
  361. times->modtime = tvp[1].tv_sec;
  362. } else { times = NULL; }
  363. return utime(file, times);
  364. }
  365. #endif
  366. #endif
  367. //#define __NR_stty 31
  368. #ifdef L_stty
  369. #include <sgtty.h>
  370. int stty (int __fd, __const struct sgttyb *__params);
  371. {
  372. __set_errno(ENOSYS);
  373. return -1;
  374. }
  375. #endif
  376. //#define __NR_gtty 32
  377. #ifdef L_gtty
  378. #include <sgtty.h>
  379. int gtty (int __fd, struct sgttyb *__params)
  380. {
  381. __set_errno(ENOSYS);
  382. return -1;
  383. }
  384. #endif
  385. //#define __NR_access 33
  386. #ifdef L_access
  387. #include <unistd.h>
  388. _syscall2(int, access, const char *, pathname, int, mode);
  389. #endif
  390. //#define __NR_nice 34
  391. #ifdef L_nice
  392. #include <unistd.h>
  393. #ifdef __NR_nice
  394. _syscall1(int, nice, int, inc);
  395. #else
  396. #include <sys/resource.h>
  397. int nice (int incr)
  398. {
  399. int save, prio, result;
  400. save = errno;
  401. __set_errno (0);
  402. prio = getpriority (PRIO_PROCESS, 0);
  403. if (prio == -1) {
  404. if (errno != 0) { return -1; }
  405. else { __set_errno (save); }
  406. }
  407. result = setpriority (PRIO_PROCESS, 0, prio + incr);
  408. if (result != -1) { return prio + incr; } else { return -1; }
  409. }
  410. #endif
  411. #endif
  412. //#define __NR_ftime 35
  413. //#define __NR_sync 36
  414. //See sync.c
  415. //#define __NR_kill 37
  416. #ifdef L___syscall_kill
  417. #include <signal.h>
  418. #undef kill
  419. #define __NR___syscall_kill __NR_kill
  420. static inline
  421. _syscall2(int, __syscall_kill, __kernel_pid_t, pid, int, sig);
  422. int kill(pid_t pid, int sig)
  423. {
  424. return(__syscall_kill(pid, sig));
  425. }
  426. #endif
  427. //#define __NR_rename 38
  428. #ifdef L___syscall_rename
  429. #define __NR___syscall_rename __NR_rename
  430. #include <unistd.h>
  431. #include <string.h>
  432. #include <sys/param.h>
  433. #include <stdio.h>
  434. static inline
  435. _syscall2(int, __syscall_rename, const char *, oldpath, const char *, newpath);
  436. weak_alias(__syscall_rename, rename)
  437. #endif
  438. //#define __NR_mkdir 39
  439. #ifdef L___syscall_mkdir
  440. #include <sys/stat.h>
  441. #define __NR___syscall_mkdir __NR_mkdir
  442. static inline
  443. _syscall2(int, __syscall_mkdir, const char *, pathname, __kernel_mode_t, mode);
  444. int mkdir(const char * pathname, mode_t mode)
  445. {
  446. return(__syscall_mkdir(pathname, mode));
  447. }
  448. #endif
  449. //#define __NR_rmdir 40
  450. #ifdef L_rmdir
  451. #include <unistd.h>
  452. _syscall1(int, rmdir, const char *, pathname);
  453. #endif
  454. //#define __NR_dup 41
  455. #ifdef L_dup
  456. #include <unistd.h>
  457. _syscall1(int, dup, int, oldfd);
  458. #endif
  459. //#define __NR_pipe 42
  460. #ifdef L_pipe
  461. #include <unistd.h>
  462. _syscall1(int, pipe, int *, filedes);
  463. #endif
  464. //#define __NR_times 43
  465. #ifdef L_times
  466. #include <sys/times.h>
  467. _syscall1(clock_t, times, struct tms *, buf);
  468. #endif
  469. //#define __NR_prof 44
  470. //#define __NR_brk 45
  471. //#define __NR_setgid 46
  472. #ifdef L___syscall_setgid
  473. #include <unistd.h>
  474. #define __NR___syscall_setgid __NR_setgid
  475. static inline
  476. _syscall1(int, __syscall_setgid, __kernel_gid_t, gid);
  477. int setgid(gid_t gid)
  478. {
  479. if (gid == (gid_t) ~0
  480. || gid != (gid_t) ((__kernel_gid_t) gid))
  481. {
  482. __set_errno (EINVAL);
  483. return -1;
  484. }
  485. return(__syscall_setgid(gid));
  486. }
  487. #endif
  488. //#define __NR_getgid 47
  489. #ifdef L___syscall_getgid
  490. #include <unistd.h>
  491. #define __NR___syscall_getgid __NR_getgid
  492. #if defined (__alpha__)
  493. #define __NR_getgid __NR_getxgid
  494. #endif
  495. static inline
  496. _syscall0(int, __syscall_getgid);
  497. gid_t getgid(void)
  498. {
  499. return(__syscall_getgid());
  500. }
  501. #endif
  502. //#define __NR_signal 48
  503. //#define __NR_geteuid 49
  504. #ifdef L___syscall_geteuid
  505. #include <unistd.h>
  506. # ifdef __NR_geteuid
  507. #define __NR___syscall_geteuid __NR_geteuid
  508. static inline
  509. _syscall0(int, __syscall_geteuid);
  510. uid_t geteuid(void)
  511. {
  512. return(__syscall_geteuid());
  513. }
  514. # else
  515. uid_t geteuid(void)
  516. {
  517. return (getuid());
  518. }
  519. # endif
  520. #endif
  521. //#define __NR_getegid 50
  522. #ifdef L___syscall_getegid
  523. #include <unistd.h>
  524. # ifdef __NR_getegid
  525. #define __NR___syscall_getegid __NR_getegid
  526. static inline
  527. _syscall0(int, __syscall_getegid);
  528. gid_t getegid(void)
  529. {
  530. return(__syscall_getegid());
  531. }
  532. # else
  533. gid_t getegid(void)
  534. {
  535. return (getgid());
  536. }
  537. # endif
  538. #endif
  539. //#define __NR_acct 51
  540. #ifdef L_acct
  541. #include <unistd.h>
  542. _syscall1(int, acct, const char *, filename);
  543. #endif
  544. //#define __NR_umount2 52
  545. #ifdef L_umount2
  546. # ifdef __NR_umount2 /* Old kernels don't have umount2 */
  547. # include <sys/mount.h>
  548. _syscall2(int, umount2, const char *, special_file, int, flags);
  549. # else
  550. int umount2(const char * special_file, int flags)
  551. {
  552. __set_errno(ENOSYS);
  553. return -1;
  554. }
  555. # endif
  556. #endif
  557. //#define __NR_lock 53
  558. //#define __NR_ioctl 54
  559. #ifdef L___syscall_ioctl
  560. #include <stdarg.h>
  561. #include <sys/ioctl.h>
  562. #define __NR___syscall_ioctl __NR_ioctl
  563. extern int __syscall_ioctl(int fd, int request, void *arg);
  564. _syscall3(int, __syscall_ioctl, int, fd, int, request, void *, arg);
  565. #if !defined (__powerpc__)
  566. #include "ioctl.c"
  567. /* Also see ioctl.c and powerpc/ioctl.c */
  568. #endif
  569. #endif
  570. //#define __NR_fcntl 55
  571. #ifdef L___syscall_fcntl
  572. #include <stdarg.h>
  573. #include <fcntl.h>
  574. #define __NR___syscall_fcntl __NR_fcntl
  575. #ifdef __UCLIBC_HAS_LFS__
  576. static inline
  577. #endif
  578. _syscall3(int, __syscall_fcntl, int, fd, int, cmd, long, arg);
  579. int __libc_fcntl(int fd, int cmd, ...)
  580. {
  581. long arg;
  582. va_list list;
  583. if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64)
  584. {
  585. __set_errno(ENOSYS);
  586. return -1;
  587. }
  588. va_start(list, cmd);
  589. arg = va_arg(list, long);
  590. va_end(list);
  591. return(__syscall_fcntl(fd, cmd, arg));
  592. }
  593. weak_alias(__libc_fcntl, fcntl)
  594. #if ! defined __NR_fcntl64 && defined __UCLIBC_HAS_LFS__
  595. weak_alias(__libc_fcntl, fcntl64);
  596. #endif
  597. #endif
  598. //#define __NR_mpx 56
  599. //#define __NR_setpgid 57
  600. #ifdef L___syscall_setpgid
  601. #include <unistd.h>
  602. #define __NR___syscall_setpgid __NR_setpgid
  603. static inline
  604. _syscall2(int, __syscall_setpgid, __kernel_pid_t, pid, __kernel_pid_t, pgid);
  605. int setpgid(pid_t pid, pid_t pgid)
  606. {
  607. return(__syscall_setpgid(pid, pgid));
  608. }
  609. #endif
  610. //#define __NR_ulimit 58
  611. //See ulimit.c
  612. //#define __NR_oldolduname 59
  613. //#define __NR_umask 60
  614. #ifdef L___syscall_umask
  615. #include <sys/stat.h>
  616. #define __NR___syscall_umask __NR_umask
  617. static inline
  618. _syscall1(__kernel_mode_t, __syscall_umask, __kernel_mode_t, mode);
  619. mode_t umask(mode_t mode)
  620. {
  621. return(__syscall_umask(mode));
  622. }
  623. #endif
  624. //#define __NR_chroot 61
  625. #ifdef L___syscall_chroot
  626. #define __NR___syscall_chroot __NR_chroot
  627. #include <unistd.h>
  628. #include <string.h>
  629. #include <sys/param.h>
  630. static inline
  631. _syscall1(int, __syscall_chroot, const char *, path);
  632. weak_alias(__syscall_chroot, chroot)
  633. #endif
  634. //#define __NR_ustat 62
  635. #ifdef L___syscall_ustat
  636. #define __NR___syscall_ustat __NR_ustat
  637. #include <sys/ustat.h>
  638. static inline
  639. _syscall2(int, __syscall_ustat, unsigned short int, kdev_t, struct ustat *, ubuf);
  640. int ustat(dev_t dev, struct ustat *ubuf)
  641. {
  642. /* We must convert the dev_t value to a __kernel_dev_t */
  643. __kernel_dev_t k_dev;
  644. k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff);
  645. return __syscall_ustat(k_dev, ubuf);
  646. }
  647. #endif
  648. //#define __NR_dup2 63
  649. #ifdef L_dup2
  650. #include <unistd.h>
  651. _syscall2(int, dup2, int, oldfd, int, newfd);
  652. #endif
  653. //#define __NR_getppid 64
  654. #ifdef L_getppid
  655. # include <unistd.h>
  656. # ifdef __NR_getppid
  657. _syscall0(pid_t, getppid);
  658. # else
  659. pid_t getppid(void)
  660. {
  661. return (getpid());
  662. }
  663. # endif
  664. #endif
  665. //#define __NR_getpgrp 65
  666. #ifdef L_getpgrp
  667. #include <unistd.h>
  668. _syscall0(pid_t, getpgrp);
  669. #endif
  670. //#define __NR_setsid 66
  671. #ifdef L_setsid
  672. #include <unistd.h>
  673. _syscall0(pid_t, setsid);
  674. #endif
  675. //#define __NR_sigaction 67
  676. #ifndef __NR_rt_sigaction
  677. #ifdef L___syscall_sigaction
  678. #define __NR___syscall_sigaction __NR_sigaction
  679. #include <signal.h>
  680. #undef sigaction
  681. _syscall3(int, __syscall_sigaction, int, signum, const struct sigaction *, act,
  682. struct sigaction *, oldact);
  683. #endif
  684. #endif
  685. //#define __NR_sgetmask 68
  686. //#define __NR_ssetmask 69
  687. //#define __NR_setreuid 70
  688. #ifdef L___syscall_setreuid
  689. #include <unistd.h>
  690. #define __NR___syscall_setreuid __NR_setreuid
  691. static inline
  692. _syscall2(int, __syscall_setreuid, __kernel_uid_t, ruid, __kernel_uid_t, euid);
  693. int setreuid(uid_t ruid, uid_t euid)
  694. {
  695. if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  696. || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U)))
  697. {
  698. __set_errno(EINVAL);
  699. return -1;
  700. }
  701. return(__syscall_setreuid(ruid, euid));
  702. }
  703. #endif
  704. //#define __NR_setregid 71
  705. #ifdef L___syscall_setregid
  706. #include <unistd.h>
  707. #define __NR___syscall_setregid __NR_setregid
  708. static inline
  709. _syscall2(int, __syscall_setregid, __kernel_gid_t, rgid, __kernel_gid_t, egid);
  710. int setregid(gid_t rgid, gid_t egid)
  711. {
  712. if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  713. || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  714. {
  715. __set_errno (EINVAL);
  716. return -1;
  717. }
  718. return(__syscall_setregid(rgid, egid));
  719. }
  720. #endif
  721. //#define __NR_sigsuspend 72
  722. #ifndef __NR_rt_sigsuspend
  723. #define __NR___sigsuspend __NR_sigsuspend
  724. #ifdef L___sigsuspend
  725. #include <signal.h>
  726. #undef sigsuspend
  727. _syscall3(int, __sigsuspend, int, a, unsigned long int, b, unsigned long int, c);
  728. int sigsuspend (const sigset_t *set)
  729. {
  730. return __sigsuspend(0, 0, set->__val[0]);
  731. }
  732. #endif
  733. #endif
  734. //#define __NR_sigpending 73
  735. #ifndef __NR_rt_sigpending
  736. #ifdef L_sigpending
  737. #include <signal.h>
  738. #undef sigpending
  739. _syscall1(int, sigpending, sigset_t *, set);
  740. #endif
  741. #endif
  742. //#define __NR_sethostname 74
  743. #ifdef L_sethostname
  744. #include <unistd.h>
  745. _syscall2(int, sethostname, const char *, name, size_t, len);
  746. #endif
  747. //#define __NR_setrlimit 75
  748. #ifndef __NR_ugetrlimit
  749. /* Only wrap setrlimit if the new ugetrlimit is not present */
  750. #ifdef L___setrlimit
  751. #define __NR___setrlimit __NR_setrlimit
  752. #include <unistd.h>
  753. #include <sys/resource.h>
  754. #define RMIN(x, y) ((x) < (y) ? (x) : (y))
  755. _syscall2(int, __setrlimit, int, resource, const struct rlimit *, rlim);
  756. int setrlimit (__rlimit_resource_t resource, const struct rlimit *rlimits)
  757. {
  758. struct rlimit rlimits_small;
  759. /* We might have to correct the limits values. Since the old values
  760. * were signed the new values might be too large. */
  761. rlimits_small.rlim_cur = RMIN ((unsigned long int) rlimits->rlim_cur,
  762. RLIM_INFINITY >> 1);
  763. rlimits_small.rlim_max = RMIN ((unsigned long int) rlimits->rlim_max,
  764. RLIM_INFINITY >> 1);
  765. return(__setrlimit(resource, &rlimits_small));
  766. }
  767. #undef RMIN
  768. #endif
  769. #else /* We don't need to wrap setrlimit */
  770. #ifdef L_setrlimit
  771. #include <unistd.h>
  772. struct rlimit;
  773. _syscall2(int, setrlimit, unsigned int, resource, const struct rlimit *, rlim);
  774. #endif
  775. #endif /* __NR_setrlimit */
  776. //#define __NR_getrlimit 76
  777. #ifdef L___getrlimit
  778. /* Only include the old getrlimit if the new one (ugetrlimit) is not around */
  779. #ifndef __NR_ugetrlimit
  780. #define __NR___getrlimit __NR_getrlimit
  781. #include <unistd.h>
  782. #include <sys/resource.h>
  783. _syscall2(int, __getrlimit, int, resource, struct rlimit *, rlim);
  784. int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
  785. {
  786. int result;
  787. result = __getrlimit(resource, rlimits);
  788. if (result == -1)
  789. return result;
  790. /* We might have to correct the limits values. Since the old values
  791. * were signed the infinity value is too small. */
  792. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  793. rlimits->rlim_cur = RLIM_INFINITY;
  794. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  795. rlimits->rlim_max = RLIM_INFINITY;
  796. return result;
  797. }
  798. #endif
  799. #endif /* __NR_getrlimit */
  800. //#define __NR_getrusage 77
  801. #ifdef L_getrusage
  802. #include <unistd.h>
  803. #include <wait.h>
  804. _syscall2(int, getrusage, int, who, struct rusage *, usage);
  805. #endif
  806. //#define __NR_gettimeofday 78
  807. #ifdef L_gettimeofday
  808. #include <sys/time.h>
  809. _syscall2(int, gettimeofday, struct timeval *, tv, struct timezone *, tz);
  810. #endif
  811. //#define __NR_settimeofday 79
  812. #ifdef L_settimeofday
  813. #include <sys/time.h>
  814. _syscall2(int, settimeofday, const struct timeval *, tv,
  815. const struct timezone *, tz);
  816. #endif
  817. //#define __NR_getgroups 80
  818. #ifdef L___syscall_getgroups
  819. #include <unistd.h>
  820. #define __NR___syscall_getgroups __NR_getgroups
  821. static inline
  822. _syscall2(int, __syscall_getgroups, int, size, __kernel_gid_t *, list);
  823. #define MIN(a,b) (((a)<(b))?(a):(b))
  824. int getgroups(int n, gid_t *groups)
  825. {
  826. if (unlikely(n < 0)) {
  827. __set_errno(EINVAL);
  828. return -1;
  829. } else {
  830. int i, ngids;
  831. __kernel_gid_t kernel_groups[n = MIN(n, sysconf(_SC_NGROUPS_MAX))];
  832. ngids = __syscall_getgroups(n, kernel_groups);
  833. if (n != 0 && ngids > 0) {
  834. for (i = 0; i < ngids; i++) {
  835. groups[i] = kernel_groups[i];
  836. }
  837. }
  838. return ngids;
  839. }
  840. }
  841. #endif
  842. //#define __NR_setgroups 81
  843. #ifdef L___syscall_setgroups
  844. #include <unistd.h>
  845. #include <grp.h>
  846. #define __NR___syscall_setgroups __NR_setgroups
  847. static inline
  848. _syscall2(int, __syscall_setgroups, size_t, size, const __kernel_gid_t *, list);
  849. int setgroups (size_t n, const gid_t *groups)
  850. {
  851. if (n > (size_t)sysconf(_SC_NGROUPS_MAX)) {
  852. __set_errno (EINVAL);
  853. return -1;
  854. } else {
  855. size_t i;
  856. __kernel_gid_t kernel_groups[n];
  857. for (i = 0; i < n; i++) {
  858. kernel_groups[i] = (groups)[i];
  859. if (groups[i] != (gid_t) ((__kernel_gid_t)groups[i])) {
  860. __set_errno (EINVAL);
  861. return -1;
  862. }
  863. }
  864. return(__syscall_setgroups(n, kernel_groups));
  865. }
  866. }
  867. #endif
  868. //#define __NR_select 82
  869. #ifdef L_select
  870. //Used as a fallback if _newselect isn't available...
  871. #ifndef __NR__newselect
  872. #include <unistd.h>
  873. extern int select(int n, fd_set *readfds, fd_set *writefds,
  874. fd_set *exceptfds, struct timeval *timeout);
  875. _syscall5(int, select, int, n, fd_set *, readfds, fd_set *, writefds,
  876. fd_set *, exceptfds, struct timeval *, timeout);
  877. #endif
  878. #endif
  879. //#define __NR_symlink 83
  880. #ifdef L_symlink
  881. #include <unistd.h>
  882. _syscall2(int, symlink, const char *, oldpath, const char *, newpath);
  883. #endif
  884. //#define __NR_oldlstat 84
  885. //#define __NR_readlink 85
  886. #ifdef L_readlink
  887. #include <unistd.h>
  888. _syscall3(int, readlink, const char *, path, char *, buf, size_t, bufsiz);
  889. #endif
  890. //#define __NR_uselib 86
  891. #ifdef L_uselib
  892. #include <unistd.h>
  893. _syscall1(int, uselib, const char *, library);
  894. #endif
  895. //#define __NR_swapon 87
  896. #ifdef L_swapon
  897. #include <sys/swap.h>
  898. _syscall2(int, swapon, const char *, path, int, swapflags);
  899. #endif
  900. //#define __NR_reboot 88
  901. #ifdef L__reboot
  902. #define __NR__reboot __NR_reboot
  903. extern int _reboot(int magic, int magic2, int flag);
  904. _syscall3(int, _reboot, int, magic, int, magic2, int, flag);
  905. int reboot(int flag)
  906. {
  907. return (_reboot((int) 0xfee1dead, 672274793, flag));
  908. }
  909. #endif
  910. //#define __NR_readdir 89
  911. //#define __NR_mmap 90
  912. #ifdef L__mmap
  913. #define __NR__mmap __NR_mmap
  914. #include <unistd.h>
  915. #include <sys/mman.h>
  916. extern __ptr_t _mmap(unsigned long *buffer);
  917. _syscall1(__ptr_t, _mmap, unsigned long *, buffer);
  918. __ptr_t mmap(__ptr_t addr, size_t len, int prot,
  919. int flags, int fd, __off_t offset)
  920. {
  921. unsigned long buffer[6];
  922. buffer[0] = (unsigned long) addr;
  923. buffer[1] = (unsigned long) len;
  924. buffer[2] = (unsigned long) prot;
  925. buffer[3] = (unsigned long) flags;
  926. buffer[4] = (unsigned long) fd;
  927. buffer[5] = (unsigned long) offset;
  928. return (__ptr_t) _mmap(buffer);
  929. }
  930. #endif
  931. //#define __NR_munmap 91
  932. #ifdef L_munmap
  933. #include <unistd.h>
  934. #include <sys/mman.h>
  935. _syscall2(int, munmap, void *, start, size_t, length);
  936. #endif
  937. //#define __NR_truncate 92
  938. #ifdef L_truncate
  939. #include <unistd.h>
  940. _syscall2(int, truncate, const char *, path, __off_t, length);
  941. #endif
  942. //#define __NR_ftruncate 93
  943. #ifdef L_ftruncate
  944. #include <unistd.h>
  945. _syscall2(int, ftruncate, int, fd, __off_t, length);
  946. #endif
  947. //#define __NR_fchmod 94
  948. #ifdef L___syscall_fchmod
  949. #include <sys/stat.h>
  950. #define __NR___syscall_fchmod __NR_fchmod
  951. static inline
  952. _syscall2(int, __syscall_fchmod, int, fildes, __kernel_mode_t, mode);
  953. int fchmod(int fildes, mode_t mode)
  954. {
  955. return(__syscall_fchmod(fildes, mode));
  956. }
  957. #endif
  958. //#define __NR_fchown 95
  959. #ifdef L___syscall_fchown
  960. #include <unistd.h>
  961. #define __NR___syscall_fchown __NR_fchown
  962. static inline
  963. _syscall3(int, __syscall_fchown, int, fd, __kernel_uid_t, owner, __kernel_gid_t, group);
  964. int fchown(int fd, uid_t owner, gid_t group)
  965. {
  966. if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
  967. || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  968. {
  969. __set_errno (EINVAL);
  970. return -1;
  971. }
  972. return(__syscall_fchown(fd, owner, group));
  973. }
  974. #endif
  975. //#define __NR_getpriority 96
  976. #ifdef L___syscall_getpriority
  977. #include <sys/resource.h>
  978. #define __NR___syscall_getpriority __NR_getpriority
  979. _syscall2(int, __syscall_getpriority, __priority_which_t, which, id_t, who);
  980. /* The return value of __syscall_getpriority is biased by this value
  981. * to avoid returning negative values. */
  982. #define PZERO 20
  983. int getpriority (enum __priority_which which, id_t who)
  984. {
  985. int res;
  986. res = __syscall_getpriority(which, who);
  987. if (res >= 0)
  988. res = PZERO - res;
  989. return res;
  990. }
  991. #endif
  992. //#define __NR_setpriority 97
  993. #ifdef L_setpriority
  994. #include <sys/resource.h>
  995. _syscall3(int, setpriority, __priority_which_t, which, id_t, who, int, prio);
  996. #endif
  997. //#define __NR_profil 98
  998. //#define __NR_statfs 99
  999. #ifdef L___syscall_statfs
  1000. #define __NR___syscall_statfs __NR_statfs
  1001. #include <string.h>
  1002. #include <sys/param.h>
  1003. #include <sys/vfs.h>
  1004. static inline
  1005. _syscall2(int, __syscall_statfs, const char *, path, struct statfs *, buf);
  1006. weak_alias(__syscall_statfs, statfs)
  1007. #endif
  1008. //#define __NR_fstatfs 100
  1009. #ifdef L_fstatfs
  1010. #include <sys/vfs.h>
  1011. _syscall2(int, fstatfs, int, fd, struct statfs *, buf);
  1012. #endif
  1013. //#define __NR_ioperm 101
  1014. #ifdef L_ioperm
  1015. # if defined __ARCH_HAS_MMU__ && defined __NR_ioperm
  1016. _syscall3(int, ioperm, unsigned long, from, unsigned long, num, int, turn_on);
  1017. # else
  1018. int ioperm(unsigned long from, unsigned long num, int turn_on)
  1019. {
  1020. __set_errno(ENOSYS);
  1021. return -1;
  1022. }
  1023. # endif
  1024. #endif
  1025. //#define __NR_socketcall 102
  1026. #ifdef L___socketcall
  1027. #ifdef __NR_socketcall
  1028. #define __NR___socketcall __NR_socketcall
  1029. _syscall2(int, __socketcall, int, call, unsigned long *, args);
  1030. #endif
  1031. #endif
  1032. //#define __NR_syslog 103
  1033. #ifdef L__syslog
  1034. #include <unistd.h>
  1035. #define __NR__syslog __NR_syslog
  1036. extern int _syslog(int type, char *buf, int len);
  1037. _syscall3(int, _syslog, int, type, char *, buf, int, len);
  1038. int klogctl(int type, char *buf, int len)
  1039. {
  1040. return (_syslog(type, buf, len));
  1041. }
  1042. #endif
  1043. //#define __NR_setitimer 104
  1044. #ifdef L_setitimer
  1045. #include <sys/time.h>
  1046. _syscall3(int, setitimer, __itimer_which_t, which,
  1047. const struct itimerval *, new, struct itimerval *, old);
  1048. #endif
  1049. //#define __NR_getitimer 105
  1050. #ifdef L_getitimer
  1051. #include <sys/time.h>
  1052. _syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value);
  1053. #endif
  1054. //#define __NR_stat 106
  1055. #ifdef L___syscall_stat
  1056. #define __NR___syscall_stat __NR_stat
  1057. #include <unistd.h>
  1058. #define _SYS_STAT_H
  1059. #include <bits/stat.h>
  1060. #include "xstatconv.h"
  1061. _syscall2(int, __syscall_stat, const char *, file_name, struct kernel_stat *, buf);
  1062. int stat(const char * file_name, struct stat * buf)
  1063. {
  1064. int result;
  1065. struct kernel_stat kbuf;
  1066. result = __syscall_stat(file_name, &kbuf);
  1067. if (result == 0) {
  1068. __xstat_conv(&kbuf, buf);
  1069. }
  1070. return result;
  1071. }
  1072. #if ! defined __NR_stat64 && defined __UCLIBC_HAS_LFS__
  1073. weak_alias(stat, stat64);
  1074. #endif
  1075. #endif
  1076. //#define __NR_lstat 107
  1077. #ifdef L___syscall_lstat
  1078. #define __NR___syscall_lstat __NR_lstat
  1079. #include <unistd.h>
  1080. #define _SYS_STAT_H
  1081. #include <bits/stat.h>
  1082. #include <bits/kernel_stat.h>
  1083. #include "xstatconv.h"
  1084. _syscall2(int, __syscall_lstat, const char *, file_name, struct kernel_stat *, buf);
  1085. int lstat(const char * file_name, struct stat * buf)
  1086. {
  1087. int result;
  1088. struct kernel_stat kbuf;
  1089. result = __syscall_lstat(file_name, &kbuf);
  1090. if (result == 0) {
  1091. __xstat_conv(&kbuf, buf);
  1092. }
  1093. return result;
  1094. }
  1095. #if ! defined __NR_lstat64 && defined __UCLIBC_HAS_LFS__
  1096. weak_alias(lstat, lstat64);
  1097. #endif
  1098. #endif
  1099. //#define __NR_fstat 108
  1100. #ifdef L___syscall_fstat
  1101. #define __NR___syscall_fstat __NR_fstat
  1102. #include <unistd.h>
  1103. #define _SYS_STAT_H
  1104. #include <bits/stat.h>
  1105. #include <bits/kernel_stat.h>
  1106. #include "xstatconv.h"
  1107. _syscall2(int, __syscall_fstat, int, fd, struct kernel_stat *, buf);
  1108. int fstat(int fd, struct stat * buf)
  1109. {
  1110. int result;
  1111. struct kernel_stat kbuf;
  1112. result = __syscall_fstat(fd, &kbuf);
  1113. if (result == 0) {
  1114. __xstat_conv(&kbuf, buf);
  1115. }
  1116. return result;
  1117. }
  1118. #if ! defined __NR_fstat64 && defined __UCLIBC_HAS_LFS__
  1119. weak_alias(fstat, fstat64);
  1120. #endif
  1121. #endif
  1122. //#define __NR_olduname 109
  1123. //#define __NR_iopl 110
  1124. #ifdef L_iopl
  1125. /* For arm there is a totally different implementation */
  1126. #if !defined(__arm__)
  1127. /* Tuns out the m68k unistd.h kernel header is broken */
  1128. # if defined __ARCH_HAS_MMU__ && defined __NR_iopl && ( !defined(__mc68000__))
  1129. _syscall1(int, iopl, int, level);
  1130. # else
  1131. int iopl(int level)
  1132. {
  1133. __set_errno(ENOSYS);
  1134. return -1;
  1135. }
  1136. # endif
  1137. # endif
  1138. #endif
  1139. //#define __NR_vhangup 111
  1140. #ifdef L_vhangup
  1141. #include <unistd.h>
  1142. _syscall0(int, vhangup);
  1143. #endif
  1144. //#define __NR_idle 112
  1145. //int idle(void);
  1146. //#define __NR_vm86old 113
  1147. //#define __NR_wait4 114
  1148. #ifdef L___syscall_wait4
  1149. #define __NR___syscall_wait4 __NR_wait4
  1150. static inline
  1151. _syscall4(int, __syscall_wait4, __kernel_pid_t, pid, int *, status, int, opts, void *, rusage);
  1152. int wait4(pid_t pid, int * status, int opts, void * rusage)
  1153. {
  1154. return(__syscall_wait4(pid, status, opts, rusage));
  1155. }
  1156. #endif
  1157. //#define __NR_swapoff 115
  1158. #ifdef L_swapoff
  1159. #include <sys/swap.h>
  1160. _syscall1(int, swapoff, const char *, path);
  1161. #endif
  1162. //#define __NR_sysinfo 116
  1163. #ifdef L_sysinfo
  1164. #include <sys/sysinfo.h>
  1165. _syscall1(int, sysinfo, struct sysinfo *, info);
  1166. #endif
  1167. //#define __NR_ipc 117
  1168. #ifdef L___ipc
  1169. #ifdef __NR_ipc
  1170. #define __NR___ipc __NR_ipc
  1171. _syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, third, void *, ptr);
  1172. #endif
  1173. #endif
  1174. //#define __NR_fsync 118
  1175. #ifdef L___libc_fsync
  1176. #include <unistd.h>
  1177. #define __NR___libc_fsync __NR_fsync
  1178. _syscall1(int, __libc_fsync, int, fd);
  1179. weak_alias(__libc_fsync, fsync)
  1180. #endif
  1181. //#define __NR_sigreturn 119
  1182. //int sigreturn(unsigned long __unused);
  1183. //#define __NR_clone 120
  1184. //See architecture specific implementation...
  1185. //#define __NR_setdomainname 121
  1186. #ifdef L_setdomainname
  1187. #include <unistd.h>
  1188. _syscall2(int, setdomainname, const char *, name, size_t, len);
  1189. #endif
  1190. //#define __NR_uname 122
  1191. #ifdef L_uname
  1192. #include <sys/utsname.h>
  1193. _syscall1(int, uname, struct utsname *, buf);
  1194. #endif
  1195. //#define __NR_modify_ldt 123
  1196. #ifdef __NR_modify_ldt
  1197. #ifdef L_modify_ldt
  1198. _syscall3(int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount);
  1199. weak_alias(modify_ldt, __modify_ldt);
  1200. #endif
  1201. #endif
  1202. //#define __NR_adjtimex 124
  1203. #ifdef L_adjtimex
  1204. #include <sys/timex.h>
  1205. _syscall1(int, adjtimex, struct timex *, buf);
  1206. weak_alias(adjtimex, __adjtimex);
  1207. weak_alias(adjtimex, ntp_adjtime);
  1208. #endif
  1209. //#define __NR_mprotect 125
  1210. #ifdef L_mprotect
  1211. #include <sys/mman.h>
  1212. _syscall3(int, mprotect, void *, addr, size_t, len, int, prot);
  1213. #endif
  1214. //#define __NR_sigprocmask 126
  1215. #ifndef __NR_rt_sigprocmask
  1216. #ifdef L___syscall_sigprocmask
  1217. #include <signal.h>
  1218. #define __NR___syscall_sigprocmask __NR_sigprocmask
  1219. static inline
  1220. _syscall3(int, __syscall_sigprocmask, int, how, const sigset_t *, set,
  1221. sigset_t *, oldset);
  1222. #undef sigprocmask
  1223. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
  1224. {
  1225. if (set &&
  1226. #if (SIG_BLOCK == 0) && (SIG_UNBLOCK == 1) && (SIG_SETMASK == 2)
  1227. (((unsigned int) how) > 2)
  1228. #else
  1229. #warning "compile time assumption violated.. slow path..."
  1230. ((how != SIG_BLOCK) && (how != SIG_UNBLOCK) && (how != SIG_SETMASK))
  1231. #endif
  1232. )
  1233. {
  1234. __set_errno (EINVAL);
  1235. return -1;
  1236. }
  1237. return(__syscall_sigprocmask(how, set, oldset));
  1238. }
  1239. #endif
  1240. #endif
  1241. //#define __NR_create_module 127
  1242. //See sysdeps/linux/commom/create_module.c
  1243. //#define __NR_init_module 128
  1244. #ifdef L_init_module
  1245. /* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
  1246. * (for 2.2 and 2.4 kernels). Use the greatest common denominator,
  1247. * and let the kernel cope with whatever it gets. It's good at that. */
  1248. _syscall5(int, init_module, void *, first, void *, second, void *, third,
  1249. void *, fourth, void *, fifth);
  1250. #endif
  1251. //#define __NR_delete_module 129
  1252. #ifdef L_delete_module
  1253. # ifdef __NR_delete_module
  1254. _syscall1(int, delete_module, const char *, name);
  1255. # else
  1256. int delete_module(const char * name)
  1257. {
  1258. __set_errno(ENOSYS);
  1259. return -1;
  1260. }
  1261. # endif
  1262. #endif
  1263. //#define __NR_get_kernel_syms 130
  1264. #ifdef L_get_kernel_syms
  1265. struct kernel_sym;
  1266. _syscall1(int, get_kernel_syms, struct kernel_sym *, table);
  1267. #endif
  1268. //#define __NR_quotactl 131
  1269. #ifdef __NR_quotactl
  1270. #ifdef L_quotactl
  1271. #include <sys/quota.h>
  1272. _syscall4(int, quotactl, int, cmd, const char *, special , int, id, caddr_t, addr);
  1273. #endif
  1274. #endif
  1275. //#define __NR_getpgid 132
  1276. #ifdef L___syscall_getpgid
  1277. #define __NR___syscall_getpgid __NR_getpgid
  1278. #define __FAVOR_BSD
  1279. static inline
  1280. _syscall1(__kernel_pid_t, __syscall_getpgid, __kernel_pid_t, pid);
  1281. pid_t __getpgid(pid_t pid)
  1282. {
  1283. return(__syscall_getpgid(pid));
  1284. }
  1285. weak_alias(__getpgid, getpgid);
  1286. #endif
  1287. //#define __NR_fchdir 133
  1288. #ifdef L_fchdir
  1289. #include <unistd.h>
  1290. _syscall1(int, fchdir, int, fd);
  1291. #endif
  1292. //#define __NR_bdflush 134
  1293. #ifdef L_bdflush
  1294. #include <sys/kdaemon.h>
  1295. _syscall2(int, bdflush, int, __func, long int, __data);
  1296. #endif
  1297. //#define __NR_sysfs 135
  1298. //_syscall3(int, sysfs, int, option, unsigned int, index, char addr);
  1299. //#define __NR_personality 136
  1300. #ifdef __NR_personality
  1301. #ifdef L_personality
  1302. #include <sys/personality.h>
  1303. _syscall1(int, personality, unsigned long int, __persona);
  1304. #endif
  1305. #endif
  1306. //#define __NR_afs_syscall 137
  1307. //#define __NR_setfsuid 138
  1308. #ifdef __NR_setfsuid
  1309. #ifdef L___syscall_setfsuid
  1310. #include <sys/fsuid.h>
  1311. #define __NR___syscall_setfsuid __NR_setfsuid
  1312. static inline
  1313. _syscall1(int, __syscall_setfsuid, __kernel_uid_t, uid);
  1314. int setfsuid(uid_t uid)
  1315. {
  1316. if (uid != (uid_t) ((__kernel_uid_t) uid))
  1317. {
  1318. __set_errno (EINVAL);
  1319. return -1;
  1320. }
  1321. return(__syscall_setfsuid(uid));
  1322. }
  1323. #endif
  1324. #endif
  1325. //#define __NR_setfsgid 139
  1326. #ifdef __NR_setfsgid
  1327. #ifdef L___syscall_setfsgid
  1328. #include <sys/fsuid.h>
  1329. #define __NR___syscall_setfsgid __NR_setfsgid
  1330. static inline
  1331. _syscall1(int, __syscall_setfsgid, __kernel_gid_t, gid);
  1332. int setfsgid(gid_t gid)
  1333. {
  1334. if (gid != (gid_t) ((__kernel_gid_t) gid))
  1335. {
  1336. __set_errno (EINVAL);
  1337. return -1;
  1338. }
  1339. return(__syscall_setfsgid(gid));
  1340. }
  1341. #endif
  1342. #endif
  1343. //#define __NR__llseek 140
  1344. //See llseek.c
  1345. //#define __NR_getdents 141
  1346. // See getdents.c
  1347. //#define __NR__newselect 142
  1348. #ifdef L__newselect
  1349. //Used in preference to select when available...
  1350. #ifdef __NR__newselect
  1351. #include <unistd.h>
  1352. extern int _newselect(int n, fd_set *readfds, fd_set *writefds,
  1353. fd_set *exceptfds, struct timeval *timeout);
  1354. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  1355. fd_set *, exceptfds, struct timeval *, timeout);
  1356. weak_alias(_newselect, select);
  1357. #endif
  1358. #endif
  1359. //#define __NR_flock 143
  1360. #ifdef L___syscall_flock
  1361. #include <sys/file.h>
  1362. #define __NR___syscall_flock __NR_flock
  1363. static inline
  1364. _syscall2(int, __syscall_flock, int, fd, int, operation);
  1365. int flock(int fd, int operation)
  1366. {
  1367. return(__syscall_flock(fd, operation));
  1368. }
  1369. #endif
  1370. //#define __NR_msync 144
  1371. #ifdef L___libc_msync
  1372. #include <unistd.h>
  1373. #include <sys/mman.h>
  1374. #define __NR___libc_msync __NR_msync
  1375. _syscall3(int, __libc_msync, void *, addr, size_t, length, int, flags);
  1376. weak_alias(__libc_msync, msync);
  1377. #endif
  1378. //#define __NR_readv 145
  1379. #ifdef L_readv
  1380. #include <sys/uio.h>
  1381. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  1382. count);
  1383. #endif
  1384. //#define __NR_writev 146
  1385. #ifdef L_writev
  1386. #include <sys/uio.h>
  1387. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  1388. count);
  1389. #endif
  1390. //#define __NR_getsid 147
  1391. #ifdef L___syscall_getsid
  1392. #include <unistd.h>
  1393. #define __NR___syscall_getsid __NR_getsid
  1394. static inline
  1395. _syscall1(__kernel_pid_t, __syscall_getsid, __kernel_pid_t, pid);
  1396. pid_t getsid(pid_t pid)
  1397. {
  1398. return(__syscall_getsid(pid));
  1399. }
  1400. #endif
  1401. //#define __NR_fdatasync 148
  1402. #ifdef __NR_fdatasync
  1403. #ifdef L_fdatasync
  1404. #include <unistd.h>
  1405. _syscall1(int, fdatasync, int, fd);
  1406. #endif
  1407. #endif
  1408. //#define __NR__sysctl 149
  1409. #ifdef __NR__sysctl
  1410. #ifdef L__sysctl
  1411. struct __sysctl_args {
  1412. int *name;
  1413. int nlen;
  1414. void *oldval;
  1415. size_t *oldlenp;
  1416. void *newval;
  1417. size_t newlen;
  1418. unsigned long __unused[4];
  1419. };
  1420. _syscall1(int, _sysctl, struct __sysctl_args *, args);
  1421. int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
  1422. void *newval, size_t newlen)
  1423. {
  1424. struct __sysctl_args args =
  1425. {
  1426. name: name,
  1427. nlen: nlen,
  1428. oldval: oldval,
  1429. oldlenp: oldlenp,
  1430. newval: newval,
  1431. newlen: newlen
  1432. };
  1433. return _sysctl(&args);
  1434. }
  1435. #endif
  1436. #endif
  1437. //#define __NR_mlock 150
  1438. #ifdef L_mlock
  1439. #include <sys/mman.h>
  1440. # if defined __ARCH_HAS_MMU__ && defined __NR_mlock
  1441. _syscall2(int, mlock, const void *, addr, size_t, len);
  1442. # endif
  1443. #endif
  1444. //#define __NR_munlock 151
  1445. #ifdef L_munlock
  1446. #include <sys/mman.h>
  1447. # if defined __ARCH_HAS_MMU__ && defined __NR_munlock
  1448. _syscall2(int, munlock, const void *, addr, size_t, len);
  1449. # endif
  1450. #endif
  1451. //#define __NR_mlockall 152
  1452. #ifdef L_mlockall
  1453. #include <sys/mman.h>
  1454. # if defined __ARCH_HAS_MMU__ && defined __NR_mlockall
  1455. _syscall1(int, mlockall, int, flags);
  1456. # endif
  1457. #endif
  1458. //#define __NR_munlockall 153
  1459. #ifdef L_munlockall
  1460. #include <sys/mman.h>
  1461. # if defined __ARCH_HAS_MMU__ && defined L_munlockall
  1462. _syscall0(int, munlockall);
  1463. # endif
  1464. #endif
  1465. //#define __NR_sched_setparam 154
  1466. #ifdef __NR_sched_setparam
  1467. #ifdef L___syscall_sched_setparam
  1468. #include <sched.h>
  1469. #define __NR___syscall_sched_setparam __NR_sched_setparam
  1470. static inline
  1471. _syscall2(int, __syscall_sched_setparam, __kernel_pid_t, pid, const struct sched_param *, p);
  1472. int sched_setparam(pid_t pid, const struct sched_param * p)
  1473. {
  1474. return(__syscall_sched_setparam(pid, p));
  1475. }
  1476. #endif
  1477. #endif
  1478. //#define __NR_sched_getparam 155
  1479. #ifdef __NR_sched_getparam
  1480. #ifdef L___syscall_sched_getparam
  1481. #include <sched.h>
  1482. #define __NR___syscall_sched_getparam __NR_sched_getparam
  1483. static inline
  1484. _syscall2(int, __syscall_sched_getparam, __kernel_pid_t, pid, struct sched_param *, p);
  1485. int sched_getparam(pid_t pid, struct sched_param * p)
  1486. {
  1487. return(__syscall_sched_getparam(pid, p));
  1488. }
  1489. #endif
  1490. #endif
  1491. //#define __NR_sched_setscheduler 156
  1492. #ifdef __NR_sched_setscheduler
  1493. #ifdef L___syscall_sched_setscheduler
  1494. #include <sched.h>
  1495. #define __NR___syscall_sched_setscheduler __NR_sched_setscheduler
  1496. static inline
  1497. _syscall3(int, __syscall_sched_setscheduler, __kernel_pid_t, pid, int, policy, const struct sched_param *, p);
  1498. int sched_setscheduler(pid_t pid, int policy, const struct sched_param * p)
  1499. {
  1500. return(__syscall_sched_setscheduler(pid, policy, p));
  1501. }
  1502. #endif
  1503. #endif
  1504. //#define __NR_sched_getscheduler 157
  1505. #ifdef __NR_sched_getscheduler
  1506. #ifdef L___syscall_sched_getscheduler
  1507. #include <sched.h>
  1508. #define __NR___syscall_sched_getscheduler __NR_sched_getscheduler
  1509. static inline
  1510. _syscall1(int, __syscall_sched_getscheduler, __kernel_pid_t, pid);
  1511. int sched_getscheduler(pid_t pid)
  1512. {
  1513. return(__syscall_sched_getscheduler(pid));
  1514. }
  1515. #endif
  1516. #endif
  1517. //#define __NR_sched_yield 158
  1518. #ifdef __NR_sched_yield
  1519. #ifdef L_sched_yield
  1520. #include <sched.h>
  1521. _syscall0(int, sched_yield);
  1522. #endif
  1523. #endif
  1524. //#define __NR_sched_get_priority_max 159
  1525. #ifdef __NR_sched_get_priority_max
  1526. #ifdef L_sched_get_priority_max
  1527. #include <sched.h>
  1528. _syscall1(int, sched_get_priority_max, int, policy);
  1529. #endif
  1530. #endif
  1531. //#define __NR_sched_get_priority_min 160
  1532. #ifdef __NR_sched_get_priority_min
  1533. #ifdef L_sched_get_priority_min
  1534. #include <sched.h>
  1535. _syscall1(int, sched_get_priority_min, int, policy);
  1536. #endif
  1537. #endif
  1538. //#define __NR_sched_rr_get_interval 161
  1539. #ifdef __NR_sched_rr_get_interval
  1540. #ifdef L___syscall_sched_rr_get_interval
  1541. #include <sched.h>
  1542. #define __NR___syscall_sched_rr_get_interval __NR_sched_rr_get_interval
  1543. static inline
  1544. _syscall2(int, __syscall_sched_rr_get_interval, __kernel_pid_t, pid, struct timespec *, tp);
  1545. int sched_rr_get_interval(pid_t pid, struct timespec * tp)
  1546. {
  1547. return(__syscall_sched_rr_get_interval(pid, tp));
  1548. }
  1549. #endif
  1550. #endif
  1551. //#define __NR_nanosleep 162
  1552. #ifdef L___libc_nanosleep
  1553. #include <time.h>
  1554. #define __NR___libc_nanosleep __NR_nanosleep
  1555. _syscall2(int, __libc_nanosleep, const struct timespec *, req, struct timespec *, rem);
  1556. weak_alias(__libc_nanosleep, nanosleep)
  1557. #endif
  1558. //#define __NR_mremap 163
  1559. #ifdef L_mremap
  1560. #include <unistd.h>
  1561. #include <sys/mman.h>
  1562. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t, new_size, int, may_move);
  1563. #endif
  1564. //#define __NR_setresuid 164
  1565. #ifdef __NR_setresuid
  1566. #ifdef L___syscall_setresuid
  1567. #define __NR___syscall_setresuid __NR_setresuid
  1568. static inline
  1569. _syscall3(int, __syscall_setresuid, __kernel_uid_t, rgid, __kernel_uid_t, egid, __kernel_uid_t, sgid);
  1570. int setresuid(uid_t ruid, uid_t euid, uid_t suid)
  1571. {
  1572. if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1573. || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1574. || ((suid + 1) > (uid_t) ((__kernel_uid_t) -1U)))
  1575. {
  1576. __set_errno (EINVAL);
  1577. return -1;
  1578. }
  1579. return(__syscall_setresuid(ruid, euid, suid));
  1580. }
  1581. #endif
  1582. #endif
  1583. //#define __NR_getresuid 165
  1584. #ifdef __NR_getresuid
  1585. #ifdef L___syscall_getresuid
  1586. #define __NR___syscall_getresuid __NR_getresuid
  1587. static inline
  1588. _syscall3(int, __syscall_getresuid, __kernel_uid_t *, ruid, __kernel_uid_t *, euid, __kernel_uid_t *, suid);
  1589. int getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
  1590. {
  1591. int result;
  1592. __kernel_uid_t k_ruid, k_euid, k_suid;
  1593. result = __syscall_getresuid(&k_ruid, &k_euid, &k_suid);
  1594. if (result == 0) {
  1595. *ruid = (uid_t) k_ruid;
  1596. *euid = (uid_t) k_euid;
  1597. *suid = (uid_t) k_suid;
  1598. }
  1599. return result;
  1600. }
  1601. #endif
  1602. #endif
  1603. //#define __NR_vm86 166
  1604. //#define __NR_query_module 167
  1605. #ifdef L_query_module
  1606. # ifdef __NR_query_module
  1607. _syscall5(int, query_module, const char *, name, int, which,
  1608. void *, buf, size_t, bufsize, size_t*, ret);
  1609. # else
  1610. int query_module(const char * name, int which,
  1611. void * buf, size_t bufsize, size_t* ret)
  1612. {
  1613. __set_errno(ENOSYS);
  1614. return -1;
  1615. }
  1616. # endif
  1617. #endif
  1618. //#define __NR_poll 168
  1619. #ifdef L_poll
  1620. #ifdef __NR_poll
  1621. #include <sys/poll.h>
  1622. _syscall3(int, poll, struct pollfd *, fds, unsigned long int, nfds, int, timeout);
  1623. #else
  1624. /* uClinux 2.0 doesn't have poll, emulate it using select */
  1625. #include "poll.c"
  1626. #endif
  1627. #endif
  1628. //#define __NR_nfsservctl 169
  1629. //nfsservctl EXTRA nfsservctl i:ipp nfsservctl
  1630. //#define __NR_setresgid 170
  1631. #ifdef __NR_setresgid
  1632. #ifdef L___syscall_setresgid
  1633. #define __NR___syscall_setresgid __NR_setresgid
  1634. static inline
  1635. _syscall3(int, __syscall_setresgid, __kernel_gid_t, rgid, __kernel_gid_t, egid, __kernel_gid_t, sgid);
  1636. int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
  1637. {
  1638. if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  1639. || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  1640. || ((sgid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  1641. {
  1642. __set_errno (EINVAL);
  1643. return -1;
  1644. }
  1645. return(__syscall_setresgid(rgid, egid, sgid));
  1646. }
  1647. #endif
  1648. #endif
  1649. //#define __NR_getresgid 171
  1650. #ifdef __NR_getresgid
  1651. #ifdef L___syscall_getresgid
  1652. #define __NR___syscall_getresgid __NR_getresgid
  1653. static inline
  1654. _syscall3(int, __syscall_getresgid, __kernel_gid_t *, egid, __kernel_gid_t *, rgid, __kernel_gid_t *, sgid);
  1655. int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
  1656. {
  1657. int result;
  1658. __kernel_gid_t k_rgid, k_egid, k_sgid;
  1659. result = __syscall_getresgid(&k_rgid, &k_egid, &k_sgid);
  1660. if (result == 0) {
  1661. *rgid = (gid_t) k_rgid;
  1662. *egid = (gid_t) k_egid;
  1663. *sgid = (gid_t) k_sgid;
  1664. }
  1665. return result;
  1666. }
  1667. #endif
  1668. #endif
  1669. //#define __NR_prctl 172
  1670. #ifdef __NR_prctl
  1671. #ifdef L_prctl
  1672. #include <stdarg.h>
  1673. //#include <sys/prctl.h>
  1674. _syscall5(int, prctl, int, a, int, b, int, c, int, d, int, e);
  1675. #endif
  1676. #endif
  1677. //#define __NR_rt_sigreturn 173
  1678. //#define __NR_rt_sigaction 174
  1679. #ifdef __NR_rt_sigaction
  1680. #define __NR___syscall_rt_sigaction __NR_rt_sigaction
  1681. #ifdef L___syscall_rt_sigaction
  1682. #include <signal.h>
  1683. #undef sigaction
  1684. _syscall4(int, __syscall_rt_sigaction, int, signum, const struct sigaction *, act,
  1685. struct sigaction *, oldact, size_t, size);
  1686. #endif
  1687. #endif
  1688. //#define __NR_rt_sigprocmask 175
  1689. #ifdef __NR_rt_sigprocmask
  1690. #define __NR___rt_sigprocmask __NR_rt_sigprocmask
  1691. #ifdef L___rt_sigprocmask
  1692. #include <signal.h>
  1693. #undef sigprocmask
  1694. _syscall4(int, __rt_sigprocmask, int, how, const sigset_t *, set,
  1695. sigset_t *, oldset, size_t, size);
  1696. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
  1697. {
  1698. if (set &&
  1699. #if (SIG_BLOCK == 0) && (SIG_UNBLOCK == 1) && (SIG_SETMASK == 2)
  1700. (((unsigned int) how) > 2)
  1701. #else
  1702. #warning "compile time assumption violated.. slow path..."
  1703. ((how != SIG_BLOCK) && (how != SIG_UNBLOCK) && (how != SIG_SETMASK))
  1704. #endif
  1705. )
  1706. {
  1707. __set_errno (EINVAL);
  1708. return -1;
  1709. }
  1710. return __rt_sigprocmask(how, set, oldset, _NSIG/8);
  1711. }
  1712. #endif
  1713. #endif
  1714. //#define __NR_rt_sigpending 176
  1715. #ifdef __NR_rt_sigpending
  1716. #define __NR___rt_sigpending __NR_rt_sigpending
  1717. #ifdef L___rt_sigpending
  1718. #include <signal.h>
  1719. #undef sigpending
  1720. _syscall2(int, __rt_sigpending, sigset_t *, set, size_t, size);
  1721. int sigpending(sigset_t *set)
  1722. {
  1723. return __rt_sigpending(set, _NSIG/8);
  1724. }
  1725. #endif
  1726. #endif
  1727. //#define __NR_rt_sigtimedwait 177
  1728. #ifdef L___rt_sigtimedwait
  1729. #include <signal.h>
  1730. #define __need_NULL
  1731. #include <stddef.h>
  1732. #ifdef __NR_rt_sigtimedwait
  1733. #define __NR___rt_sigtimedwait __NR_rt_sigtimedwait
  1734. _syscall4(int, __rt_sigtimedwait, const sigset_t *, set, siginfo_t *, info,
  1735. const struct timespec *, timeout, size_t, setsize);
  1736. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1737. {
  1738. return __rt_sigtimedwait (set, info, NULL, _NSIG/8);
  1739. }
  1740. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1741. {
  1742. return __rt_sigtimedwait (set, info, timeout, _NSIG/8);
  1743. }
  1744. #else
  1745. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1746. {
  1747. if (set==NULL)
  1748. __set_errno (EINVAL);
  1749. else
  1750. __set_errno (ENOSYS);
  1751. return -1;
  1752. }
  1753. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1754. {
  1755. if (set==NULL)
  1756. __set_errno (EINVAL);
  1757. else
  1758. __set_errno (ENOSYS);
  1759. return -1;
  1760. }
  1761. #endif
  1762. #endif
  1763. //#define __NR_rt_sigqueueinfo 178
  1764. //#define __NR_rt_sigsuspend 179
  1765. #ifdef __NR_rt_sigsuspend
  1766. #define __NR___rt_sigsuspend __NR_rt_sigsuspend
  1767. #ifdef L___rt_sigsuspend
  1768. #include <signal.h>
  1769. #undef _sigsuspend
  1770. _syscall2(int, __rt_sigsuspend, const sigset_t *, mask, size_t, size);
  1771. int sigsuspend (const sigset_t *mask)
  1772. {
  1773. return __rt_sigsuspend(mask, _NSIG/8);
  1774. }
  1775. #endif
  1776. #endif
  1777. //#define __NR_pread 180
  1778. // See pread_write.c
  1779. //#define __NR_pwrite 181
  1780. // See pread_write.c
  1781. //#define __NR_chown 182
  1782. #ifdef L___syscall_chown
  1783. #include <unistd.h>
  1784. #define __NR___syscall_chown __NR_chown
  1785. static inline
  1786. _syscall3(int, __syscall_chown, const char *, path, __kernel_uid_t, owner, __kernel_gid_t, group);
  1787. int chown(const char * path, uid_t owner, gid_t group)
  1788. {
  1789. if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1790. || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  1791. {
  1792. __set_errno (EINVAL);
  1793. return -1;
  1794. }
  1795. return(__syscall_chown(path, owner, group));
  1796. }
  1797. #endif
  1798. //#define __NR_getcwd 183
  1799. // See getcwd.c in this directory
  1800. //#define __NR_capget 184
  1801. #ifdef L_capget
  1802. # ifdef __NR_capget
  1803. _syscall2(int, capget, void*, header, void*, data);
  1804. # else
  1805. int capget(void* header, void* data)
  1806. {
  1807. __set_errno(ENOSYS);
  1808. return -1;
  1809. }
  1810. # endif
  1811. #endif
  1812. //#define __NR_capset 185
  1813. #ifdef L_capset
  1814. # ifdef __NR_capset
  1815. _syscall2(int, capset, void*, header, const void*, data);
  1816. # else
  1817. int capset(void* header, const void* data)
  1818. {
  1819. __set_errno(ENOSYS);
  1820. return -1;
  1821. }
  1822. # endif
  1823. #endif
  1824. //#define __NR_sigaltstack 186
  1825. #ifdef __NR_sigaltstack
  1826. #ifdef L_sigaltstack
  1827. #include <signal.h>
  1828. _syscall2(int, sigaltstack, const struct sigaltstack *, ss, struct sigaltstack *, oss);
  1829. #endif
  1830. #endif
  1831. //#define __NR_sendfile 187
  1832. #ifdef __NR_sendfile
  1833. #ifdef L_sendfile
  1834. #include <unistd.h>
  1835. #include <sys/sendfile.h>
  1836. _syscall4(ssize_t,sendfile, int, out_fd, int, in_fd, __off_t *, offset, size_t, count);
  1837. #endif
  1838. #endif
  1839. //#define __NR_getpmsg 188
  1840. //#define __NR_putpmsg 189
  1841. //#define __NR_vfork 190
  1842. //See sysdeps/linux/<arch>vfork.[cS] for architecture specific implementation...
  1843. //#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
  1844. #ifdef L___ugetrlimit
  1845. #ifdef __NR_ugetrlimit
  1846. #define __NR___ugetrlimit __NR_ugetrlimit
  1847. #include <unistd.h>
  1848. #include <sys/resource.h>
  1849. _syscall2(int, __ugetrlimit, enum __rlimit_resource, resource, struct rlimit *, rlim);
  1850. int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
  1851. {
  1852. return(__ugetrlimit(resource, rlimits));
  1853. }
  1854. #endif /* __NR_ugetrlimit */
  1855. #endif
  1856. //#define __NR_mmap2 192
  1857. //#define __NR_truncate64 193
  1858. //See libc/sysdeps/linux/common/truncate64.c
  1859. //#define __NR_ftruncate64 194
  1860. //See libc/sysdeps/linux/common/ftruncate64.c
  1861. //#define __NR_stat64 195
  1862. #ifdef L___syscall_stat64
  1863. #if defined __UCLIBC_HAS_LFS__ && defined __NR_stat64
  1864. #define __NR___syscall_stat64 __NR_stat64
  1865. #include <unistd.h>
  1866. #include <sys/stat.h>
  1867. #include <bits/kernel_stat.h>
  1868. #include "xstatconv.h"
  1869. _syscall2(int, __syscall_stat64, const char *, file_name, struct kernel_stat64 *, buf);
  1870. int stat64(const char * file_name, struct stat64 * buf)
  1871. {
  1872. int result;
  1873. struct kernel_stat64 kbuf;
  1874. result = __syscall_stat64(file_name, &kbuf);
  1875. if (result == 0) {
  1876. __xstat64_conv(&kbuf, buf);
  1877. }
  1878. return result;
  1879. }
  1880. #endif /* __UCLIBC_HAS_LFS__ */
  1881. #endif
  1882. //#define __NR_lstat64 196
  1883. #ifdef L___syscall_lstat64
  1884. #if defined __UCLIBC_HAS_LFS__ && defined __NR_lstat64
  1885. #define __NR___syscall_lstat64 __NR_lstat64
  1886. #include <unistd.h>
  1887. #include <sys/stat.h>
  1888. #include <bits/kernel_stat.h>
  1889. #include "xstatconv.h"
  1890. _syscall2(int, __syscall_lstat64, const char *, file_name, struct kernel_stat64 *, buf);
  1891. int lstat64(const char * file_name, struct stat64 * buf)
  1892. {
  1893. int result;
  1894. struct kernel_stat64 kbuf;
  1895. result = __syscall_lstat64(file_name, &kbuf);
  1896. if (result == 0) {
  1897. __xstat64_conv(&kbuf, buf);
  1898. }
  1899. return result;
  1900. }
  1901. #endif /* __UCLIBC_HAS_LFS__ */
  1902. #endif
  1903. //#define __NR_fstat64 197
  1904. #ifdef L___syscall_fstat64
  1905. #if defined __UCLIBC_HAS_LFS__ && defined __NR_fstat64
  1906. #define __NR___syscall_fstat64 __NR_fstat64
  1907. #include <unistd.h>
  1908. #include <sys/stat.h>
  1909. #include <bits/kernel_stat.h>
  1910. #include "xstatconv.h"
  1911. _syscall2(int, __syscall_fstat64, int, filedes, struct kernel_stat64 *, buf);
  1912. int fstat64(int fd, struct stat64 * buf)
  1913. {
  1914. int result;
  1915. struct kernel_stat64 kbuf;
  1916. result = __syscall_fstat64(fd, &kbuf);
  1917. if (result == 0) {
  1918. __xstat64_conv(&kbuf, buf);
  1919. }
  1920. return result;
  1921. }
  1922. #endif /* __UCLIBC_HAS_LFS__ */
  1923. #endif
  1924. //#define __NR_lchown32 198
  1925. //#define __NR_getuid32 199
  1926. //#define __NR_getgid32 200
  1927. //#define __NR_geteuid32 201
  1928. //#define __NR_getegid32 202
  1929. //#define __NR_setreuid32 203
  1930. //#define __NR_setregid32 204
  1931. //#define __NR_getgroups32 205
  1932. //#define __NR_setgroups32 206
  1933. //#define __NR_fchown32 207
  1934. //#define __NR_setresuid32 208
  1935. //#define __NR_getresuid32 209
  1936. //#define __NR_setresgid32 210
  1937. //#define __NR_getresgid32 211
  1938. //#define __NR_chown32 212
  1939. //#define __NR_setuid32 213
  1940. //#define __NR_setgid32 214
  1941. //#define __NR_setfsuid32 215
  1942. //#define __NR_setfsgid32 216
  1943. //#define __NR_pivot_root 217
  1944. #ifdef __NR_pivot_root
  1945. #ifdef L_pivot_root
  1946. _syscall2(int, pivot_root, const char *, new_root, const char *, put_old);
  1947. #endif
  1948. #endif
  1949. //#define __NR_mincore 218
  1950. //#define __NR_madvise 219
  1951. #ifdef __NR_madvise
  1952. #ifdef L_madvise
  1953. _syscall3(int, madvise, void*, __addr, size_t, __len, int, __advice);
  1954. #endif
  1955. #endif
  1956. //#define __NR_madvise1 219 /* delete when C lib stub is removed */
  1957. //#define __NR_getdents64 220
  1958. // See getdents64.c
  1959. //#define __NR_fcntl64 221
  1960. #ifdef L___syscall_fcntl64
  1961. #include <stdarg.h>
  1962. #include <fcntl.h>
  1963. #if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  1964. #define __NR___syscall_fcntl64 __NR_fcntl64
  1965. static inline
  1966. _syscall3(int, __syscall_fcntl64, int, fd, int, cmd, long, arg);
  1967. int __libc_fcntl64(int fd, int cmd, ...)
  1968. {
  1969. long arg;
  1970. va_list list;
  1971. va_start(list, cmd);
  1972. arg = va_arg(list, long);
  1973. va_end(list);
  1974. return(__syscall_fcntl64(fd, cmd, arg));
  1975. }
  1976. weak_alias(__libc_fcntl64, fcntl64)
  1977. #endif
  1978. #endif
  1979. //#define __NR_security 223 /* syscall for security modules */
  1980. //#define __NR_gettid 224
  1981. //#define __NR_readahead 225