syscalls.c 55 KB

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