syscalls.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252
  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(EINVAL);
  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(EINVAL);
  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(EINVAL);
  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(EINVAL);
  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. #endif
  640. //#define __NR_mpx 56
  641. //#define __NR_setpgid 57
  642. #ifdef L___syscall_setpgid
  643. #include <unistd.h>
  644. #define __NR___syscall_setpgid __NR_setpgid
  645. static inline
  646. _syscall2(int, __syscall_setpgid, __kernel_pid_t, pid, __kernel_pid_t, pgid);
  647. int setpgid(pid_t pid, pid_t pgid)
  648. {
  649. return(__syscall_setpgid(pid, pgid));
  650. }
  651. #endif
  652. //#define __NR_ulimit 58
  653. //See ulimit.c
  654. //#define __NR_oldolduname 59
  655. //#define __NR_umask 60
  656. #ifdef L___syscall_umask
  657. #include <sys/stat.h>
  658. #define __NR___syscall_umask __NR_umask
  659. static inline
  660. _syscall1(__kernel_mode_t, __syscall_umask, __kernel_mode_t, mode);
  661. mode_t umask(mode_t mode)
  662. {
  663. return(__syscall_umask(mode));
  664. }
  665. #endif
  666. //#define __NR_chroot 61
  667. #ifdef L___syscall_chroot
  668. #define __NR___syscall_chroot __NR_chroot
  669. #include <unistd.h>
  670. #include <string.h>
  671. #include <sys/param.h>
  672. static inline
  673. _syscall1(int, __syscall_chroot, const char *, path);
  674. int chroot(const char *path)
  675. {
  676. if (unlikely(path==NULL || *path=='\0')) {
  677. __set_errno(EINVAL);
  678. return -1;
  679. }
  680. if (unlikely(((strlen(path)+1) > NAME_MAX))) {
  681. __set_errno(ENAMETOOLONG);
  682. return -1;
  683. }
  684. return __syscall_chroot(path);
  685. }
  686. #endif
  687. //#define __NR_ustat 62
  688. #ifdef L___syscall_ustat
  689. #define __NR___syscall_ustat __NR_ustat
  690. #include <sys/ustat.h>
  691. static inline
  692. _syscall2(int, __syscall_ustat, unsigned short int, kdev_t, struct ustat *, ubuf);
  693. int ustat(dev_t dev, struct ustat *ubuf)
  694. {
  695. /* We must convert the dev_t value to a __kernel_dev_t */
  696. __kernel_dev_t k_dev;
  697. k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff);
  698. return __syscall_ustat(k_dev, ubuf);
  699. }
  700. #endif
  701. //#define __NR_dup2 63
  702. #ifdef L_dup2
  703. #include <unistd.h>
  704. _syscall2(int, dup2, int, oldfd, int, newfd);
  705. #endif
  706. //#define __NR_getppid 64
  707. #ifdef L_getppid
  708. # include <unistd.h>
  709. # ifdef __NR_getppid
  710. _syscall0(pid_t, getppid);
  711. # else
  712. pid_t getppid(void)
  713. {
  714. return (getpid());
  715. }
  716. # endif
  717. #endif
  718. //#define __NR_getpgrp 65
  719. #ifdef L_getpgrp
  720. #include <unistd.h>
  721. _syscall0(pid_t, getpgrp);
  722. #endif
  723. //#define __NR_setsid 66
  724. #ifdef L_setsid
  725. #include <unistd.h>
  726. _syscall0(pid_t, setsid);
  727. #endif
  728. //#define __NR_sigaction 67
  729. #ifndef __NR_rt_sigaction
  730. #ifdef L___syscall_sigaction
  731. #define __NR___syscall_sigaction __NR_sigaction
  732. #include <signal.h>
  733. #undef sigaction
  734. _syscall3(int, __syscall_sigaction, int, signum, const struct sigaction *, act,
  735. struct sigaction *, oldact);
  736. #endif
  737. #endif
  738. //#define __NR_sgetmask 68
  739. //#define __NR_ssetmask 69
  740. //#define __NR_setreuid 70
  741. #ifdef L___syscall_setreuid
  742. #include <unistd.h>
  743. #define __NR___syscall_setreuid __NR_setreuid
  744. static inline
  745. _syscall2(int, __syscall_setreuid, __kernel_uid_t, ruid, __kernel_uid_t, euid);
  746. int setreuid(uid_t ruid, uid_t euid)
  747. {
  748. if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  749. || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U)))
  750. {
  751. __set_errno(EINVAL);
  752. return -1;
  753. }
  754. return(__syscall_setreuid(ruid, euid));
  755. }
  756. #endif
  757. //#define __NR_setregid 71
  758. #ifdef L___syscall_setregid
  759. #include <unistd.h>
  760. #define __NR___syscall_setregid __NR_setregid
  761. static inline
  762. _syscall2(int, __syscall_setregid, __kernel_gid_t, rgid, __kernel_gid_t, egid);
  763. int setregid(gid_t rgid, gid_t egid)
  764. {
  765. if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  766. || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  767. {
  768. __set_errno (EINVAL);
  769. return -1;
  770. }
  771. return(__syscall_setregid(rgid, egid));
  772. }
  773. #endif
  774. //#define __NR_sigsuspend 72
  775. #ifndef __NR_rt_sigsuspend
  776. #define __NR___sigsuspend __NR_sigsuspend
  777. #ifdef L___sigsuspend
  778. #include <signal.h>
  779. #undef sigsuspend
  780. _syscall3(int, __sigsuspend, int, a, unsigned long int, b, unsigned long int, c);
  781. int sigsuspend (const sigset_t *set)
  782. {
  783. return __sigsuspend(0, 0, set->__val[0]);
  784. }
  785. #endif
  786. #endif
  787. //#define __NR_sigpending 73
  788. #ifndef __NR_rt_sigpending
  789. #ifdef L_sigpending
  790. #include <signal.h>
  791. #undef sigpending
  792. _syscall1(int, sigpending, sigset_t *, set);
  793. #endif
  794. #endif
  795. //#define __NR_sethostname 74
  796. #ifdef L_sethostname
  797. #include <unistd.h>
  798. _syscall2(int, sethostname, const char *, name, size_t, len);
  799. #endif
  800. //#define __NR_setrlimit 75
  801. #ifndef __NR_ugetrlimit
  802. /* Only wrap setrlimit if the new ugetrlimit is not present */
  803. #ifdef L___setrlimit
  804. #define __NR___setrlimit __NR_setrlimit
  805. #include <unistd.h>
  806. #include <sys/resource.h>
  807. #define RMIN(x, y) ((x) < (y) ? (x) : (y))
  808. _syscall2(int, __setrlimit, int, resource, const struct rlimit *, rlim);
  809. int setrlimit (__rlimit_resource_t resource, const struct rlimit *rlimits)
  810. {
  811. struct rlimit rlimits_small;
  812. /* We might have to correct the limits values. Since the old values
  813. * were signed the new values might be too large. */
  814. rlimits_small.rlim_cur = RMIN ((unsigned long int) rlimits->rlim_cur,
  815. RLIM_INFINITY >> 1);
  816. rlimits_small.rlim_max = RMIN ((unsigned long int) rlimits->rlim_max,
  817. RLIM_INFINITY >> 1);
  818. return(__setrlimit(resource, &rlimits_small));
  819. }
  820. #undef RMIN
  821. #endif
  822. #else /* We don't need to wrap setrlimit */
  823. #ifdef L_setrlimit
  824. #include <unistd.h>
  825. struct rlimit;
  826. _syscall2(int, setrlimit, unsigned int, resource, const struct rlimit *, rlim);
  827. #endif
  828. #endif /* __NR_setrlimit */
  829. //#define __NR_getrlimit 76
  830. #ifdef L___getrlimit
  831. /* Only include the old getrlimit if the new one (ugetrlimit) is not around */
  832. #ifndef __NR_ugetrlimit
  833. #define __NR___getrlimit __NR_getrlimit
  834. #include <unistd.h>
  835. #include <sys/resource.h>
  836. _syscall2(int, __getrlimit, int, resource, struct rlimit *, rlim);
  837. int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
  838. {
  839. int result;
  840. result = __getrlimit(resource, rlimits);
  841. if (result == -1)
  842. return result;
  843. /* We might have to correct the limits values. Since the old values
  844. * were signed the infinity value is too small. */
  845. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  846. rlimits->rlim_cur = RLIM_INFINITY;
  847. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  848. rlimits->rlim_max = RLIM_INFINITY;
  849. return result;
  850. }
  851. #endif
  852. #endif /* __NR_getrlimit */
  853. //#define __NR_getrusage 77
  854. #ifdef L_getrusage
  855. #include <unistd.h>
  856. #include <wait.h>
  857. _syscall2(int, getrusage, int, who, struct rusage *, usage);
  858. #endif
  859. //#define __NR_gettimeofday 78
  860. #ifdef L_gettimeofday
  861. #include <sys/time.h>
  862. _syscall2(int, gettimeofday, struct timeval *, tv, struct timezone *, tz);
  863. #endif
  864. //#define __NR_settimeofday 79
  865. #ifdef L_settimeofday
  866. #include <sys/time.h>
  867. _syscall2(int, settimeofday, const struct timeval *, tv,
  868. const struct timezone *, tz);
  869. #endif
  870. //#define __NR_getgroups 80
  871. #ifdef L___syscall_getgroups
  872. #include <unistd.h>
  873. #define __NR___syscall_getgroups __NR_getgroups
  874. static inline
  875. _syscall2(int, __syscall_getgroups, int, size, __kernel_gid_t *, list);
  876. #define MIN(a,b) (((a)<(b))?(a):(b))
  877. int getgroups(int n, gid_t *groups)
  878. {
  879. if (unlikely(n < 0)) {
  880. __set_errno(EINVAL);
  881. return -1;
  882. } else {
  883. int i, ngids;
  884. __kernel_gid_t kernel_groups[n = MIN(n, sysconf(_SC_NGROUPS_MAX))];
  885. ngids = __syscall_getgroups(n, kernel_groups);
  886. if (n != 0 && ngids > 0) {
  887. for (i = 0; i < ngids; i++) {
  888. groups[i] = kernel_groups[i];
  889. }
  890. }
  891. return ngids;
  892. }
  893. }
  894. #endif
  895. //#define __NR_setgroups 81
  896. #ifdef L___syscall_setgroups
  897. #include <unistd.h>
  898. #include <grp.h>
  899. #define __NR___syscall_setgroups __NR_setgroups
  900. static inline
  901. _syscall2(int, __syscall_setgroups, size_t, size, const __kernel_gid_t *, list);
  902. int setgroups (size_t n, const gid_t *groups)
  903. {
  904. if (n > (size_t)sysconf(_SC_NGROUPS_MAX)) {
  905. __set_errno (EINVAL);
  906. return -1;
  907. } else {
  908. size_t i;
  909. __kernel_gid_t kernel_groups[n];
  910. for (i = 0; i < n; i++) {
  911. kernel_groups[i] = (groups)[i];
  912. if (groups[i] != (gid_t) ((__kernel_gid_t)groups[i])) {
  913. __set_errno (EINVAL);
  914. return -1;
  915. }
  916. }
  917. return(__syscall_setgroups(n, kernel_groups));
  918. }
  919. }
  920. #endif
  921. //#define __NR_select 82
  922. #ifdef L_select
  923. //Used as a fallback if _newselect isn't available...
  924. #ifndef __NR__newselect
  925. #include <unistd.h>
  926. extern int select(int n, fd_set *readfds, fd_set *writefds,
  927. fd_set *exceptfds, struct timeval *timeout);
  928. _syscall5(int, select, int, n, fd_set *, readfds, fd_set *, writefds,
  929. fd_set *, exceptfds, struct timeval *, timeout);
  930. #endif
  931. #endif
  932. //#define __NR_symlink 83
  933. #ifdef L_symlink
  934. #include <unistd.h>
  935. _syscall2(int, symlink, const char *, oldpath, const char *, newpath);
  936. #endif
  937. //#define __NR_oldlstat 84
  938. //#define __NR_readlink 85
  939. #ifdef L_readlink
  940. #include <unistd.h>
  941. _syscall3(int, readlink, const char *, path, char *, buf, size_t, bufsiz);
  942. #endif
  943. //#define __NR_uselib 86
  944. #ifdef L_uselib
  945. #include <unistd.h>
  946. _syscall1(int, uselib, const char *, library);
  947. #endif
  948. //#define __NR_swapon 87
  949. #ifdef L_swapon
  950. #include <sys/swap.h>
  951. _syscall2(int, swapon, const char *, path, int, swapflags);
  952. #endif
  953. //#define __NR_reboot 88
  954. #ifdef L__reboot
  955. #define __NR__reboot __NR_reboot
  956. extern int _reboot(int magic, int magic2, int flag);
  957. _syscall3(int, _reboot, int, magic, int, magic2, int, flag);
  958. int reboot(int flag)
  959. {
  960. return (_reboot((int) 0xfee1dead, 672274793, flag));
  961. }
  962. #endif
  963. //#define __NR_readdir 89
  964. //#define __NR_mmap 90
  965. #ifdef L__mmap
  966. #define __NR__mmap __NR_mmap
  967. #include <unistd.h>
  968. #include <sys/mman.h>
  969. extern __ptr_t _mmap(unsigned long *buffer);
  970. _syscall1(__ptr_t, _mmap, unsigned long *, buffer);
  971. __ptr_t mmap(__ptr_t addr, size_t len, int prot,
  972. int flags, int fd, __off_t offset)
  973. {
  974. unsigned long buffer[6];
  975. buffer[0] = (unsigned long) addr;
  976. buffer[1] = (unsigned long) len;
  977. buffer[2] = (unsigned long) prot;
  978. buffer[3] = (unsigned long) flags;
  979. buffer[4] = (unsigned long) fd;
  980. buffer[5] = (unsigned long) offset;
  981. return (__ptr_t) _mmap(buffer);
  982. }
  983. #endif
  984. //#define __NR_munmap 91
  985. #ifdef L_munmap
  986. #include <unistd.h>
  987. #include <sys/mman.h>
  988. _syscall2(int, munmap, void *, start, size_t, length);
  989. #endif
  990. //#define __NR_truncate 92
  991. #ifdef L_truncate
  992. #include <unistd.h>
  993. _syscall2(int, truncate, const char *, path, __off_t, length);
  994. #endif
  995. //#define __NR_ftruncate 93
  996. #ifdef L_ftruncate
  997. #include <unistd.h>
  998. _syscall2(int, ftruncate, int, fd, __off_t, length);
  999. #endif
  1000. //#define __NR_fchmod 94
  1001. #ifdef L___syscall_fchmod
  1002. #include <sys/stat.h>
  1003. #define __NR___syscall_fchmod __NR_fchmod
  1004. static inline
  1005. _syscall2(int, __syscall_fchmod, int, fildes, __kernel_mode_t, mode);
  1006. int fchmod(int fildes, mode_t mode)
  1007. {
  1008. return(__syscall_fchmod(fildes, mode));
  1009. }
  1010. #endif
  1011. //#define __NR_fchown 95
  1012. #ifdef L___syscall_fchown
  1013. #include <unistd.h>
  1014. #define __NR___syscall_fchown __NR_fchown
  1015. static inline
  1016. _syscall3(int, __syscall_fchown, int, fd, __kernel_uid_t, owner, __kernel_gid_t, group);
  1017. int fchown(int fd, uid_t owner, gid_t group)
  1018. {
  1019. if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1020. || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  1021. {
  1022. __set_errno (EINVAL);
  1023. return -1;
  1024. }
  1025. return(__syscall_fchown(fd, owner, group));
  1026. }
  1027. #endif
  1028. //#define __NR_getpriority 96
  1029. #ifdef L___syscall_getpriority
  1030. #include <sys/resource.h>
  1031. #define __NR___syscall_getpriority __NR_getpriority
  1032. _syscall2(int, __syscall_getpriority, __priority_which_t, which, id_t, who);
  1033. /* The return value of __syscall_getpriority is biased by this value
  1034. * to avoid returning negative values. */
  1035. #define PZERO 20
  1036. int getpriority (enum __priority_which which, id_t who)
  1037. {
  1038. int res;
  1039. res = __syscall_getpriority(which, who);
  1040. if (res >= 0)
  1041. res = PZERO - res;
  1042. return res;
  1043. }
  1044. #endif
  1045. //#define __NR_setpriority 97
  1046. #ifdef L_setpriority
  1047. #include <sys/resource.h>
  1048. _syscall3(int, setpriority, __priority_which_t, which, id_t, who, int, prio);
  1049. #endif
  1050. //#define __NR_profil 98
  1051. //#define __NR_statfs 99
  1052. #ifdef L___syscall_statfs
  1053. #define __NR___syscall_statfs __NR_statfs
  1054. #include <string.h>
  1055. #include <sys/param.h>
  1056. #include <sys/vfs.h>
  1057. static inline
  1058. _syscall2(int, __syscall_statfs, const char *, path, struct statfs *, buf);
  1059. int statfs(const char *path, struct statfs *buf)
  1060. {
  1061. if (unlikely(path==NULL || *path=='\0')) {
  1062. __set_errno(EINVAL);
  1063. return -1;
  1064. }
  1065. if (unlikely(((strlen(path)+1) > NAME_MAX))) {
  1066. __set_errno(ENAMETOOLONG);
  1067. return -1;
  1068. }
  1069. return __syscall_statfs(path, buf);
  1070. }
  1071. #endif
  1072. //#define __NR_fstatfs 100
  1073. #ifdef L_fstatfs
  1074. #include <sys/vfs.h>
  1075. _syscall2(int, fstatfs, int, fd, struct statfs *, buf);
  1076. #endif
  1077. //#define __NR_ioperm 101
  1078. #ifdef L_ioperm
  1079. # if defined __UCLIBC_HAS_MMU__ && defined __NR_ioperm
  1080. _syscall3(int, ioperm, unsigned long, from, unsigned long, num, int, turn_on);
  1081. # else
  1082. int ioperm(unsigned long from, unsigned long num, int turn_on)
  1083. {
  1084. __set_errno(ENOSYS);
  1085. return -1;
  1086. }
  1087. # endif
  1088. #endif
  1089. //#define __NR_socketcall 102
  1090. #ifdef L___socketcall
  1091. #ifdef __NR_socketcall
  1092. #define __NR___socketcall __NR_socketcall
  1093. _syscall2(int, __socketcall, int, call, unsigned long *, args);
  1094. #endif
  1095. #endif
  1096. //#define __NR_syslog 103
  1097. #ifdef L__syslog
  1098. #include <unistd.h>
  1099. #define __NR__syslog __NR_syslog
  1100. extern int _syslog(int type, char *buf, int len);
  1101. _syscall3(int, _syslog, int, type, char *, buf, int, len);
  1102. int klogctl(int type, char *buf, int len)
  1103. {
  1104. return (_syslog(type, buf, len));
  1105. }
  1106. #endif
  1107. //#define __NR_setitimer 104
  1108. #ifdef L_setitimer
  1109. #include <sys/time.h>
  1110. _syscall3(int, setitimer, __itimer_which_t, which,
  1111. const struct itimerval *, new, struct itimerval *, old);
  1112. #endif
  1113. //#define __NR_getitimer 105
  1114. #ifdef L_getitimer
  1115. #include <sys/time.h>
  1116. _syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value);
  1117. #endif
  1118. //#define __NR_stat 106
  1119. #ifdef L___syscall_stat
  1120. #define __NR___syscall_stat __NR_stat
  1121. #include <unistd.h>
  1122. #define _SYS_STAT_H
  1123. #include <bits/stat.h>
  1124. #include "xstatconv.h"
  1125. _syscall2(int, __syscall_stat, const char *, file_name, struct kernel_stat *, buf);
  1126. int stat(const char * file_name, struct stat * buf)
  1127. {
  1128. int result;
  1129. struct kernel_stat kbuf;
  1130. result = __syscall_stat(file_name, &kbuf);
  1131. if (result == 0) {
  1132. __xstat_conv(&kbuf, buf);
  1133. }
  1134. return result;
  1135. }
  1136. #if ! defined __NR_stat64 && defined __UCLIBC_HAS_LFS__
  1137. weak_alias(stat, stat64);
  1138. #endif
  1139. #endif
  1140. //#define __NR_lstat 107
  1141. #ifdef L___syscall_lstat
  1142. #define __NR___syscall_lstat __NR_lstat
  1143. #include <unistd.h>
  1144. #define _SYS_STAT_H
  1145. #include <bits/stat.h>
  1146. #include <bits/kernel_stat.h>
  1147. #include "xstatconv.h"
  1148. _syscall2(int, __syscall_lstat, const char *, file_name, struct kernel_stat *, buf);
  1149. int lstat(const char * file_name, struct stat * buf)
  1150. {
  1151. int result;
  1152. struct kernel_stat kbuf;
  1153. result = __syscall_lstat(file_name, &kbuf);
  1154. if (result == 0) {
  1155. __xstat_conv(&kbuf, buf);
  1156. }
  1157. return result;
  1158. }
  1159. #if ! defined __NR_lstat64 && defined __UCLIBC_HAS_LFS__
  1160. weak_alias(lstat, lstat64);
  1161. #endif
  1162. #endif
  1163. //#define __NR_fstat 108
  1164. #ifdef L___syscall_fstat
  1165. #define __NR___syscall_fstat __NR_fstat
  1166. #include <unistd.h>
  1167. #define _SYS_STAT_H
  1168. #include <bits/stat.h>
  1169. #include <bits/kernel_stat.h>
  1170. #include "xstatconv.h"
  1171. _syscall2(int, __syscall_fstat, int, fd, struct kernel_stat *, buf);
  1172. int fstat(int fd, struct stat * buf)
  1173. {
  1174. int result;
  1175. struct kernel_stat kbuf;
  1176. result = __syscall_fstat(fd, &kbuf);
  1177. if (result == 0) {
  1178. __xstat_conv(&kbuf, buf);
  1179. }
  1180. return result;
  1181. }
  1182. #if ! defined __NR_fstat64 && defined __UCLIBC_HAS_LFS__
  1183. weak_alias(fstat, fstat64);
  1184. #endif
  1185. #endif
  1186. //#define __NR_olduname 109
  1187. //#define __NR_iopl 110
  1188. #ifdef L_iopl
  1189. /* For arm there is a totally different implementation */
  1190. #if !defined(__arm__)
  1191. /* Tuns out the m68k unistd.h kernel header is broken */
  1192. # if defined __UCLIBC_HAS_MMU__ && defined __NR_iopl && ( !defined(__mc68000__))
  1193. _syscall1(int, iopl, int, level);
  1194. # else
  1195. int iopl(int level)
  1196. {
  1197. __set_errno(ENOSYS);
  1198. return -1;
  1199. }
  1200. # endif
  1201. # endif
  1202. #endif
  1203. //#define __NR_vhangup 111
  1204. #ifdef L_vhangup
  1205. #include <unistd.h>
  1206. _syscall0(int, vhangup);
  1207. #endif
  1208. //#define __NR_idle 112
  1209. //int idle(void);
  1210. //#define __NR_vm86old 113
  1211. //#define __NR_wait4 114
  1212. #ifdef L___syscall_wait4
  1213. #define __NR___syscall_wait4 __NR_wait4
  1214. static inline
  1215. _syscall4(int, __syscall_wait4, __kernel_pid_t, pid, int *, status, int, opts, void *, rusage);
  1216. int wait4(pid_t pid, int * status, int opts, void * rusage)
  1217. {
  1218. return(__syscall_wait4(pid, status, opts, rusage));
  1219. }
  1220. #endif
  1221. //#define __NR_swapoff 115
  1222. #ifdef L_swapoff
  1223. #include <sys/swap.h>
  1224. _syscall1(int, swapoff, const char *, path);
  1225. #endif
  1226. //#define __NR_sysinfo 116
  1227. #ifdef L_sysinfo
  1228. #include <sys/sysinfo.h>
  1229. _syscall1(int, sysinfo, struct sysinfo *, info);
  1230. #endif
  1231. //#define __NR_ipc 117
  1232. #ifdef L___ipc
  1233. #ifdef __NR_ipc
  1234. #define __NR___ipc __NR_ipc
  1235. _syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, third, void *, ptr);
  1236. #endif
  1237. #endif
  1238. //#define __NR_fsync 118
  1239. #ifdef L___libc_fsync
  1240. #include <unistd.h>
  1241. #define __NR___libc_fsync __NR_fsync
  1242. _syscall1(int, __libc_fsync, int, fd);
  1243. weak_alias(__libc_fsync, fsync)
  1244. #endif
  1245. //#define __NR_sigreturn 119
  1246. //int sigreturn(unsigned long __unused);
  1247. //#define __NR_clone 120
  1248. //See architecture specific implementation...
  1249. //#define __NR_setdomainname 121
  1250. #ifdef L_setdomainname
  1251. #include <unistd.h>
  1252. _syscall2(int, setdomainname, const char *, name, size_t, len);
  1253. #endif
  1254. //#define __NR_uname 122
  1255. #ifdef L_uname
  1256. #include <sys/utsname.h>
  1257. _syscall1(int, uname, struct utsname *, buf);
  1258. #endif
  1259. //#define __NR_modify_ldt 123
  1260. #ifdef __NR_modify_ldt
  1261. #ifdef L_modify_ldt
  1262. _syscall3(int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount);
  1263. weak_alias(modify_ldt, __modify_ldt);
  1264. #endif
  1265. #endif
  1266. //#define __NR_adjtimex 124
  1267. #ifdef L_adjtimex
  1268. #include <sys/timex.h>
  1269. _syscall1(int, adjtimex, struct timex *, buf);
  1270. weak_alias(adjtimex, __adjtimex);
  1271. weak_alias(adjtimex, ntp_adjtime);
  1272. #endif
  1273. //#define __NR_mprotect 125
  1274. #ifdef L_mprotect
  1275. #include <sys/mman.h>
  1276. _syscall3(int, mprotect, void *, addr, size_t, len, int, prot);
  1277. #endif
  1278. //#define __NR_sigprocmask 126
  1279. #ifndef __NR_rt_sigprocmask
  1280. #ifdef L_sigprocmask
  1281. #include <signal.h>
  1282. #undef sigprocmask
  1283. _syscall3(int, sigprocmask, int, how, const sigset_t *, set,
  1284. sigset_t *, oldset);
  1285. #endif
  1286. #endif
  1287. //#define __NR_create_module 127
  1288. //See sysdeps/linux/commom/create_module.c
  1289. //#define __NR_init_module 128
  1290. #ifdef L_init_module
  1291. /* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
  1292. * (for 2.2 and 2.4 kernels). Use the greatest common denominator,
  1293. * and let the kernel cope with whatever it gets. It's good at that. */
  1294. _syscall5(int, init_module, void *, first, void *, second, void *, third,
  1295. void *, fourth, void *, fifth);
  1296. #endif
  1297. //#define __NR_delete_module 129
  1298. #ifdef L_delete_module
  1299. # ifdef __NR_delete_module
  1300. _syscall1(int, delete_module, const char *, name);
  1301. # else
  1302. int delete_module(const char * name)
  1303. {
  1304. __set_errno(ENOSYS);
  1305. return -1;
  1306. }
  1307. # endif
  1308. #endif
  1309. //#define __NR_get_kernel_syms 130
  1310. #ifdef L_get_kernel_syms
  1311. struct kernel_sym;
  1312. _syscall1(int, get_kernel_syms, struct kernel_sym *, table);
  1313. #endif
  1314. //#define __NR_quotactl 131
  1315. #ifdef __NR_quotactl
  1316. #ifdef L_quotactl
  1317. #include <sys/quota.h>
  1318. _syscall4(int, quotactl, int, cmd, const char *, special , int, id, caddr_t, addr);
  1319. #endif
  1320. #endif
  1321. //#define __NR_getpgid 132
  1322. #ifdef L___syscall_getpgid
  1323. #define __NR___syscall_getpgid __NR_getpgid
  1324. static inline
  1325. _syscall1(__kernel_pid_t, __syscall_getpgid, __kernel_pid_t, pid);
  1326. pid_t getpgid(pid_t pid)
  1327. {
  1328. return(__syscall_getpgid(pid));
  1329. }
  1330. #endif
  1331. //#define __NR_fchdir 133
  1332. #ifdef L_fchdir
  1333. #include <unistd.h>
  1334. _syscall1(int, fchdir, int, fd);
  1335. #endif
  1336. //#define __NR_bdflush 134
  1337. #ifdef L_bdflush
  1338. #include <sys/kdaemon.h>
  1339. _syscall2(int, bdflush, int, __func, long int, __data);
  1340. #endif
  1341. //#define __NR_sysfs 135
  1342. //_syscall3(int, sysfs, int, option, unsigned int, index, char addr);
  1343. //#define __NR_personality 136
  1344. #ifdef __NR_personality
  1345. #ifdef L_personality
  1346. #include <sys/personality.h>
  1347. _syscall1(int, personality, unsigned long int, __persona);
  1348. #endif
  1349. #endif
  1350. //#define __NR_afs_syscall 137
  1351. //#define __NR_setfsuid 138
  1352. #ifdef __NR_setfsuid
  1353. #ifdef L___syscall_setfsuid
  1354. #include <sys/fsuid.h>
  1355. #define __NR___syscall_setfsuid __NR_setfsuid
  1356. static inline
  1357. _syscall1(int, __syscall_setfsuid, __kernel_uid_t, uid);
  1358. int setfsuid(uid_t uid)
  1359. {
  1360. if (uid != (uid_t) ((__kernel_uid_t) uid))
  1361. {
  1362. __set_errno (EINVAL);
  1363. return -1;
  1364. }
  1365. return(__syscall_setfsuid(uid));
  1366. }
  1367. #endif
  1368. #endif
  1369. //#define __NR_setfsgid 139
  1370. #ifdef __NR_setfsgid
  1371. #ifdef L___syscall_setfsgid
  1372. #include <sys/fsuid.h>
  1373. #define __NR___syscall_setfsgid __NR_setfsgid
  1374. static inline
  1375. _syscall1(int, __syscall_setfsgid, __kernel_gid_t, gid);
  1376. int setfsgid(gid_t gid)
  1377. {
  1378. if (gid != (gid_t) ((__kernel_gid_t) gid))
  1379. {
  1380. __set_errno (EINVAL);
  1381. return -1;
  1382. }
  1383. return(__syscall_setfsgid(gid));
  1384. }
  1385. #endif
  1386. #endif
  1387. //#define __NR__llseek 140
  1388. //See llseek.c
  1389. //#define __NR_getdents 141
  1390. // See getdents.c
  1391. //#define __NR__newselect 142
  1392. #ifdef L__newselect
  1393. //Used in preference to select when available...
  1394. #ifdef __NR__newselect
  1395. #include <unistd.h>
  1396. extern int _newselect(int n, fd_set *readfds, fd_set *writefds,
  1397. fd_set *exceptfds, struct timeval *timeout);
  1398. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  1399. fd_set *, exceptfds, struct timeval *, timeout);
  1400. weak_alias(_newselect, select);
  1401. #endif
  1402. #endif
  1403. //#define __NR_flock 143
  1404. #ifdef L___syscall_flock
  1405. #include <sys/file.h>
  1406. #define __NR___syscall_flock __NR_flock
  1407. static inline
  1408. _syscall2(int, __syscall_flock, int, fd, int, operation);
  1409. int flock(int fd, int operation)
  1410. {
  1411. return(__syscall_flock(fd, operation));
  1412. }
  1413. #endif
  1414. //#define __NR_msync 144
  1415. #ifdef L___libc_msync
  1416. #include <unistd.h>
  1417. #include <sys/mman.h>
  1418. #define __NR___libc_msync __NR_msync
  1419. _syscall3(int, __libc_msync, void *, addr, size_t, length, int, flags);
  1420. weak_alias(__libc_msync, msync);
  1421. #endif
  1422. //#define __NR_readv 145
  1423. #ifdef L_readv
  1424. #include <sys/uio.h>
  1425. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  1426. count);
  1427. #endif
  1428. //#define __NR_writev 146
  1429. #ifdef L_writev
  1430. #include <sys/uio.h>
  1431. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  1432. count);
  1433. #endif
  1434. //#define __NR_getsid 147
  1435. #ifdef L___syscall_getsid
  1436. #include <unistd.h>
  1437. #define __NR___syscall_getsid __NR_getsid
  1438. static inline
  1439. _syscall1(__kernel_pid_t, __syscall_getsid, __kernel_pid_t, pid);
  1440. pid_t getsid(pid_t pid)
  1441. {
  1442. return(__syscall_getsid(pid));
  1443. }
  1444. #endif
  1445. //#define __NR_fdatasync 148
  1446. #ifdef __NR_fdatasync
  1447. #ifdef L_fdatasync
  1448. #include <unistd.h>
  1449. _syscall1(int, fdatasync, int, fd);
  1450. #endif
  1451. #endif
  1452. //#define __NR__sysctl 149
  1453. #ifdef __NR__sysctl
  1454. #ifdef L__sysctl
  1455. struct __sysctl_args {
  1456. int *name;
  1457. int nlen;
  1458. void *oldval;
  1459. size_t *oldlenp;
  1460. void *newval;
  1461. size_t newlen;
  1462. unsigned long __unused[4];
  1463. };
  1464. _syscall1(int, _sysctl, struct __sysctl_args *, args);
  1465. int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
  1466. void *newval, size_t newlen)
  1467. {
  1468. struct __sysctl_args args =
  1469. {
  1470. name: name,
  1471. nlen: nlen,
  1472. oldval: oldval,
  1473. oldlenp: oldlenp,
  1474. newval: newval,
  1475. newlen: newlen
  1476. };
  1477. return _sysctl(&args);
  1478. }
  1479. #endif
  1480. #endif
  1481. //#define __NR_mlock 150
  1482. #ifdef L_mlock
  1483. #include <sys/mman.h>
  1484. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlock
  1485. _syscall2(int, mlock, const void *, addr, size_t, len);
  1486. # endif
  1487. #endif
  1488. //#define __NR_munlock 151
  1489. #ifdef L_munlock
  1490. #include <sys/mman.h>
  1491. # if defined __UCLIBC_HAS_MMU__ && defined __NR_munlock
  1492. _syscall2(int, munlock, const void *, addr, size_t, len);
  1493. # endif
  1494. #endif
  1495. //#define __NR_mlockall 152
  1496. #ifdef L_mlockall
  1497. #include <sys/mman.h>
  1498. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlockall
  1499. _syscall1(int, mlockall, int, flags);
  1500. # endif
  1501. #endif
  1502. //#define __NR_munlockall 153
  1503. #ifdef L_munlockall
  1504. #include <sys/mman.h>
  1505. # if defined __UCLIBC_HAS_MMU__ && defined L_munlockall
  1506. _syscall0(int, munlockall);
  1507. # endif
  1508. #endif
  1509. //#define __NR_sched_setparam 154
  1510. #ifdef __NR_sched_setparam
  1511. #ifdef L___syscall_sched_setparam
  1512. #include <sched.h>
  1513. #define __NR___syscall_sched_setparam __NR_sched_setparam
  1514. static inline
  1515. _syscall2(int, __syscall_sched_setparam, __kernel_pid_t, pid, const struct sched_param *, p);
  1516. int sched_setparam(pid_t pid, const struct sched_param * p)
  1517. {
  1518. return(__syscall_sched_setparam(pid, p));
  1519. }
  1520. #endif
  1521. #endif
  1522. //#define __NR_sched_getparam 155
  1523. #ifdef __NR_sched_getparam
  1524. #ifdef L___syscall_sched_getparam
  1525. #include <sched.h>
  1526. #define __NR___syscall_sched_getparam __NR_sched_getparam
  1527. static inline
  1528. _syscall2(int, __syscall_sched_getparam, __kernel_pid_t, pid, struct sched_param *, p);
  1529. int sched_getparam(pid_t pid, struct sched_param * p)
  1530. {
  1531. return(__syscall_sched_getparam(pid, p));
  1532. }
  1533. #endif
  1534. #endif
  1535. //#define __NR_sched_setscheduler 156
  1536. #ifdef __NR_sched_setscheduler
  1537. #ifdef L___syscall_sched_setscheduler
  1538. #include <sched.h>
  1539. #define __NR___syscall_sched_setscheduler __NR_sched_setscheduler
  1540. static inline
  1541. _syscall3(int, __syscall_sched_setscheduler, __kernel_pid_t, pid, int, policy, const struct sched_param *, p);
  1542. int sched_setscheduler(pid_t pid, int policy, const struct sched_param * p)
  1543. {
  1544. return(__syscall_sched_setscheduler(pid, policy, p));
  1545. }
  1546. #endif
  1547. #endif
  1548. //#define __NR_sched_getscheduler 157
  1549. #ifdef __NR_sched_getscheduler
  1550. #ifdef L___syscall_sched_getscheduler
  1551. #include <sched.h>
  1552. #define __NR___syscall_sched_getscheduler __NR_sched_getscheduler
  1553. static inline
  1554. _syscall1(int, __syscall_sched_getscheduler, __kernel_pid_t, pid);
  1555. int sched_getscheduler(pid_t pid)
  1556. {
  1557. return(__syscall_sched_getscheduler(pid));
  1558. }
  1559. #endif
  1560. #endif
  1561. //#define __NR_sched_yield 158
  1562. #ifdef __NR_sched_yield
  1563. #ifdef L_sched_yield
  1564. #include <sched.h>
  1565. _syscall0(int, sched_yield);
  1566. #endif
  1567. #endif
  1568. //#define __NR_sched_get_priority_max 159
  1569. #ifdef __NR_sched_get_priority_max
  1570. #ifdef L_sched_get_priority_max
  1571. #include <sched.h>
  1572. _syscall1(int, sched_get_priority_max, int, policy);
  1573. #endif
  1574. #endif
  1575. //#define __NR_sched_get_priority_min 160
  1576. #ifdef __NR_sched_get_priority_min
  1577. #ifdef L_sched_get_priority_min
  1578. #include <sched.h>
  1579. _syscall1(int, sched_get_priority_min, int, policy);
  1580. #endif
  1581. #endif
  1582. //#define __NR_sched_rr_get_interval 161
  1583. #ifdef __NR_sched_rr_get_interval
  1584. #ifdef L___syscall_sched_rr_get_interval
  1585. #include <sched.h>
  1586. #define __NR___syscall_sched_rr_get_interval __NR_sched_rr_get_interval
  1587. static inline
  1588. _syscall2(int, __syscall_sched_rr_get_interval, __kernel_pid_t, pid, struct timespec *, tp);
  1589. int sched_rr_get_interval(pid_t pid, struct timespec * tp)
  1590. {
  1591. return(__syscall_sched_rr_get_interval(pid, tp));
  1592. }
  1593. #endif
  1594. #endif
  1595. //#define __NR_nanosleep 162
  1596. #ifdef L___libc_nanosleep
  1597. #include <time.h>
  1598. #define __NR___libc_nanosleep __NR_nanosleep
  1599. _syscall2(int, __libc_nanosleep, const struct timespec *, req, struct timespec *, rem);
  1600. weak_alias(__libc_nanosleep, nanosleep)
  1601. #endif
  1602. //#define __NR_mremap 163
  1603. #ifdef L_mremap
  1604. #include <unistd.h>
  1605. #include <sys/mman.h>
  1606. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t, new_size, int, may_move);
  1607. #endif
  1608. //#define __NR_setresuid 164
  1609. #ifdef __NR_setresuid
  1610. #ifdef L___syscall_setresuid
  1611. #define __NR___syscall_setresuid __NR_setresuid
  1612. static inline
  1613. _syscall3(int, __syscall_setresuid, __kernel_uid_t, rgid, __kernel_uid_t, egid, __kernel_uid_t, sgid);
  1614. int setresuid(uid_t ruid, uid_t euid, uid_t suid)
  1615. {
  1616. if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1617. || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1618. || ((suid + 1) > (uid_t) ((__kernel_uid_t) -1U)))
  1619. {
  1620. __set_errno (EINVAL);
  1621. return -1;
  1622. }
  1623. return(__syscall_setresuid(ruid, euid, suid));
  1624. }
  1625. #endif
  1626. #endif
  1627. //#define __NR_getresuid 165
  1628. #ifdef __NR_getresuid
  1629. #ifdef L___syscall_getresuid
  1630. #define __NR___syscall_getresuid __NR_getresuid
  1631. static inline
  1632. _syscall3(int, __syscall_getresuid, __kernel_uid_t *, ruid, __kernel_uid_t *, euid, __kernel_uid_t *, suid);
  1633. int getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
  1634. {
  1635. int result;
  1636. __kernel_uid_t k_ruid, k_euid, k_suid;
  1637. result = __syscall_getresuid(&k_ruid, &k_euid, &k_suid);
  1638. if (result == 0) {
  1639. *ruid = (uid_t) k_ruid;
  1640. *euid = (uid_t) k_euid;
  1641. *suid = (uid_t) k_suid;
  1642. }
  1643. return result;
  1644. }
  1645. #endif
  1646. #endif
  1647. //#define __NR_vm86 166
  1648. //#define __NR_query_module 167
  1649. #ifdef L_query_module
  1650. # ifdef __NR_query_module
  1651. _syscall5(int, query_module, const char *, name, int, which,
  1652. void *, buf, size_t, bufsize, size_t*, ret);
  1653. # else
  1654. int query_module(const char * name, int which,
  1655. void * buf, size_t bufsize, size_t* ret)
  1656. {
  1657. __set_errno(ENOSYS);
  1658. return -1;
  1659. }
  1660. # endif
  1661. #endif
  1662. //#define __NR_poll 168
  1663. #ifdef L_poll
  1664. #ifdef __NR_poll
  1665. #include <sys/poll.h>
  1666. _syscall3(int, poll, struct pollfd *, fds, unsigned long int, nfds, int, timeout);
  1667. #else
  1668. /* uClinux 2.0 doesn't have poll, emulate it using select */
  1669. #include "poll.c"
  1670. #endif
  1671. #endif
  1672. //#define __NR_nfsservctl 169
  1673. //nfsservctl EXTRA nfsservctl i:ipp nfsservctl
  1674. //#define __NR_setresgid 170
  1675. #ifdef __NR_setresgid
  1676. #ifdef L___syscall_setresgid
  1677. #define __NR___syscall_setresgid __NR_setresgid
  1678. static inline
  1679. _syscall3(int, __syscall_setresgid, __kernel_gid_t, rgid, __kernel_gid_t, egid, __kernel_gid_t, sgid);
  1680. int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
  1681. {
  1682. if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  1683. || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  1684. || ((sgid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  1685. {
  1686. __set_errno (EINVAL);
  1687. return -1;
  1688. }
  1689. return(__syscall_setresgid(rgid, egid, sgid));
  1690. }
  1691. #endif
  1692. #endif
  1693. //#define __NR_getresgid 171
  1694. #ifdef __NR_getresgid
  1695. #ifdef L___syscall_getresgid
  1696. #define __NR___syscall_getresgid __NR_getresgid
  1697. static inline
  1698. _syscall3(int, __syscall_getresgid, __kernel_gid_t *, egid, __kernel_gid_t *, rgid, __kernel_gid_t *, sgid);
  1699. int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
  1700. {
  1701. int result;
  1702. __kernel_gid_t k_rgid, k_egid, k_sgid;
  1703. result = __syscall_getresgid(&k_rgid, &k_egid, &k_sgid);
  1704. if (result == 0) {
  1705. *rgid = (gid_t) k_rgid;
  1706. *egid = (gid_t) k_egid;
  1707. *sgid = (gid_t) k_sgid;
  1708. }
  1709. return result;
  1710. }
  1711. #endif
  1712. #endif
  1713. //#define __NR_prctl 172
  1714. #ifdef __NR_prctl
  1715. #ifdef L_prctl
  1716. #include <stdarg.h>
  1717. //#include <sys/prctl.h>
  1718. _syscall5(int, prctl, int, a, int, b, int, c, int, d, int, e);
  1719. #endif
  1720. #endif
  1721. //#define __NR_rt_sigreturn 173
  1722. //#define __NR_rt_sigaction 174
  1723. #ifdef __NR_rt_sigaction
  1724. #define __NR___syscall_rt_sigaction __NR_rt_sigaction
  1725. #ifdef L___syscall_rt_sigaction
  1726. #include <signal.h>
  1727. #undef sigaction
  1728. _syscall4(int, __syscall_rt_sigaction, int, signum, const struct sigaction *, act,
  1729. struct sigaction *, oldact, size_t, size);
  1730. #endif
  1731. #endif
  1732. //#define __NR_rt_sigprocmask 175
  1733. #ifdef __NR_rt_sigprocmask
  1734. #define __NR___rt_sigprocmask __NR_rt_sigprocmask
  1735. #ifdef L___rt_sigprocmask
  1736. #include <signal.h>
  1737. #undef sigprocmask
  1738. _syscall4(int, __rt_sigprocmask, int, how, const sigset_t *, set,
  1739. sigset_t *, oldset, size_t, size);
  1740. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
  1741. {
  1742. return __rt_sigprocmask(how, set, oldset, _NSIG/8);
  1743. }
  1744. #endif
  1745. #endif
  1746. //#define __NR_rt_sigpending 176
  1747. #ifdef __NR_rt_sigpending
  1748. #define __NR___rt_sigpending __NR_rt_sigpending
  1749. #ifdef L___rt_sigpending
  1750. #include <signal.h>
  1751. #undef sigpending
  1752. _syscall2(int, __rt_sigpending, sigset_t *, set, size_t, size);
  1753. int sigpending(sigset_t *set)
  1754. {
  1755. return __rt_sigpending(set, _NSIG/8);
  1756. }
  1757. #endif
  1758. #endif
  1759. //#define __NR_rt_sigtimedwait 177
  1760. #ifdef L___rt_sigtimedwait
  1761. #include <signal.h>
  1762. #define __need_NULL
  1763. #include <stddef.h>
  1764. #ifdef __NR_rt_sigtimedwait
  1765. #define __NR___rt_sigtimedwait __NR_rt_sigtimedwait
  1766. _syscall4(int, __rt_sigtimedwait, const sigset_t *, set, siginfo_t *, info,
  1767. const struct timespec *, timeout, size_t, setsize);
  1768. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1769. {
  1770. return __rt_sigtimedwait (set, info, NULL, _NSIG/8);
  1771. }
  1772. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1773. {
  1774. return __rt_sigtimedwait (set, info, timeout, _NSIG/8);
  1775. }
  1776. #else
  1777. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1778. {
  1779. if (set==NULL)
  1780. __set_errno (EINVAL);
  1781. else
  1782. __set_errno (ENOSYS);
  1783. return -1;
  1784. }
  1785. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1786. {
  1787. if (set==NULL)
  1788. __set_errno (EINVAL);
  1789. else
  1790. __set_errno (ENOSYS);
  1791. return -1;
  1792. }
  1793. #endif
  1794. #endif
  1795. //#define __NR_rt_sigqueueinfo 178
  1796. //#define __NR_rt_sigsuspend 179
  1797. #ifdef __NR_rt_sigsuspend
  1798. #define __NR___rt_sigsuspend __NR_rt_sigsuspend
  1799. #ifdef L___rt_sigsuspend
  1800. #include <signal.h>
  1801. #undef _sigsuspend
  1802. _syscall2(int, __rt_sigsuspend, const sigset_t *, mask, size_t, size);
  1803. int sigsuspend (const sigset_t *mask)
  1804. {
  1805. return __rt_sigsuspend(mask, _NSIG/8);
  1806. }
  1807. #endif
  1808. #endif
  1809. //#define __NR_pread 180
  1810. // See pread_write.c
  1811. //#define __NR_pwrite 181
  1812. // See pread_write.c
  1813. //#define __NR_chown 182
  1814. #ifdef L___syscall_chown
  1815. #include <unistd.h>
  1816. #define __NR___syscall_chown __NR_chown
  1817. static inline
  1818. _syscall3(int, __syscall_chown, const char *, path, __kernel_uid_t, owner, __kernel_gid_t, group);
  1819. int chown(const char * path, uid_t owner, gid_t group)
  1820. {
  1821. if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1822. || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  1823. {
  1824. __set_errno (EINVAL);
  1825. return -1;
  1826. }
  1827. return(__syscall_chown(path, owner, group));
  1828. }
  1829. #endif
  1830. //#define __NR_getcwd 183
  1831. // See getcwd.c in this directory
  1832. //#define __NR_capget 184
  1833. #ifdef L_capget
  1834. # ifdef __NR_capget
  1835. _syscall2(int, capget, void*, header, void*, data);
  1836. # else
  1837. int capget(void* header, void* data)
  1838. {
  1839. __set_errno(ENOSYS);
  1840. return -1;
  1841. }
  1842. # endif
  1843. #endif
  1844. //#define __NR_capset 185
  1845. #ifdef L_capset
  1846. # ifdef __NR_capset
  1847. _syscall2(int, capset, void*, header, const void*, data);
  1848. # else
  1849. int capset(void* header, const void* data)
  1850. {
  1851. __set_errno(ENOSYS);
  1852. return -1;
  1853. }
  1854. # endif
  1855. #endif
  1856. //#define __NR_sigaltstack 186
  1857. #ifdef __NR_sigaltstack
  1858. #ifdef L_sigaltstack
  1859. #include <signal.h>
  1860. _syscall2(int, sigaltstack, const struct sigaltstack *, ss, struct sigaltstack *, oss);
  1861. #endif
  1862. #endif
  1863. //#define __NR_sendfile 187
  1864. #ifdef __NR_sendfile
  1865. #ifdef L_sendfile
  1866. #include <unistd.h>
  1867. #include <sys/sendfile.h>
  1868. _syscall4(ssize_t,sendfile, int, out_fd, int, in_fd, __off_t *, offset, size_t, count);
  1869. #endif
  1870. #endif
  1871. //#define __NR_getpmsg 188
  1872. //#define __NR_putpmsg 189
  1873. //#define __NR_vfork 190
  1874. //See sysdeps/linux/<arch>vfork.[cS] for architecture specific implementation...
  1875. //#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
  1876. #ifdef L___ugetrlimit
  1877. #ifdef __NR_ugetrlimit
  1878. #define __NR___ugetrlimit __NR_ugetrlimit
  1879. #include <unistd.h>
  1880. #include <sys/resource.h>
  1881. _syscall2(int, __ugetrlimit, enum __rlimit_resource, resource, struct rlimit *, rlim);
  1882. int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
  1883. {
  1884. return(__ugetrlimit(resource, rlimits));
  1885. }
  1886. #endif /* __NR_ugetrlimit */
  1887. #endif
  1888. //#define __NR_mmap2 192
  1889. //#define __NR_truncate64 193
  1890. //See libc/sysdeps/linux/common/truncate64.c
  1891. //#define __NR_ftruncate64 194
  1892. //See libc/sysdeps/linux/common/ftruncate64.c
  1893. //#define __NR_stat64 195
  1894. #ifdef L___syscall_stat64
  1895. #if defined __UCLIBC_HAS_LFS__ && defined __NR_stat64
  1896. #define __NR___syscall_stat64 __NR_stat64
  1897. #include <unistd.h>
  1898. #include <sys/stat.h>
  1899. #include <bits/kernel_stat.h>
  1900. #include "xstatconv.h"
  1901. _syscall2(int, __syscall_stat64, const char *, file_name, struct kernel_stat64 *, buf);
  1902. int stat64(const char * file_name, struct stat64 * buf)
  1903. {
  1904. int result;
  1905. struct kernel_stat64 kbuf;
  1906. result = __syscall_stat64(file_name, &kbuf);
  1907. if (result == 0) {
  1908. __xstat64_conv(&kbuf, buf);
  1909. }
  1910. return result;
  1911. }
  1912. #endif /* __UCLIBC_HAS_LFS__ */
  1913. #endif
  1914. //#define __NR_lstat64 196
  1915. #ifdef L___syscall_lstat64
  1916. #if defined __UCLIBC_HAS_LFS__ && defined __NR_lstat64
  1917. #define __NR___syscall_lstat64 __NR_lstat64
  1918. #include <unistd.h>
  1919. #include <sys/stat.h>
  1920. #include <bits/kernel_stat.h>
  1921. #include "xstatconv.h"
  1922. _syscall2(int, __syscall_lstat64, const char *, file_name, struct kernel_stat64 *, buf);
  1923. int lstat64(const char * file_name, struct stat64 * buf)
  1924. {
  1925. int result;
  1926. struct kernel_stat64 kbuf;
  1927. result = __syscall_lstat64(file_name, &kbuf);
  1928. if (result == 0) {
  1929. __xstat64_conv(&kbuf, buf);
  1930. }
  1931. return result;
  1932. }
  1933. #endif /* __UCLIBC_HAS_LFS__ */
  1934. #endif
  1935. //#define __NR_fstat64 197
  1936. #ifdef L___syscall_fstat64
  1937. #if defined __UCLIBC_HAS_LFS__ && defined __NR_fstat64
  1938. #define __NR___syscall_fstat64 __NR_fstat64
  1939. #include <unistd.h>
  1940. #include <sys/stat.h>
  1941. #include <bits/kernel_stat.h>
  1942. #include "xstatconv.h"
  1943. _syscall2(int, __syscall_fstat64, int, filedes, struct kernel_stat64 *, buf);
  1944. int fstat64(int fd, struct stat64 * buf)
  1945. {
  1946. int result;
  1947. struct kernel_stat64 kbuf;
  1948. result = __syscall_fstat64(fd, &kbuf);
  1949. if (result == 0) {
  1950. __xstat64_conv(&kbuf, buf);
  1951. }
  1952. return result;
  1953. }
  1954. #endif /* __UCLIBC_HAS_LFS__ */
  1955. #endif
  1956. //#define __NR_lchown32 198
  1957. //#define __NR_getuid32 199
  1958. //#define __NR_getgid32 200
  1959. //#define __NR_geteuid32 201
  1960. //#define __NR_getegid32 202
  1961. //#define __NR_setreuid32 203
  1962. //#define __NR_setregid32 204
  1963. //#define __NR_getgroups32 205
  1964. //#define __NR_setgroups32 206
  1965. //#define __NR_fchown32 207
  1966. //#define __NR_setresuid32 208
  1967. //#define __NR_getresuid32 209
  1968. //#define __NR_setresgid32 210
  1969. //#define __NR_getresgid32 211
  1970. //#define __NR_chown32 212
  1971. //#define __NR_setuid32 213
  1972. //#define __NR_setgid32 214
  1973. //#define __NR_setfsuid32 215
  1974. //#define __NR_setfsgid32 216
  1975. //#define __NR_pivot_root 217
  1976. #ifdef __NR_pivot_root
  1977. #ifdef L_pivot_root
  1978. _syscall2(int, pivot_root, const char *, new_root, const char *, put_old);
  1979. #endif
  1980. #endif
  1981. //#define __NR_mincore 218
  1982. //#define __NR_madvise 219
  1983. #ifdef __NR_madvise
  1984. #ifdef L_madvise
  1985. _syscall3(int, madvise, void*, __addr, size_t, __len, int, __advice);
  1986. #endif
  1987. #endif
  1988. //#define __NR_madvise1 219 /* delete when C lib stub is removed */
  1989. //#define __NR_getdents64 220
  1990. // See getdents64.c
  1991. //#define __NR_fcntl64 221
  1992. #ifdef L___syscall_fcntl64
  1993. #include <stdarg.h>
  1994. #include <fcntl.h>
  1995. #if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  1996. #define __NR___syscall_fcntl64 __NR_fcntl64
  1997. static inline
  1998. _syscall3(int, __syscall_fcntl64, int, fd, int, cmd, long, arg);
  1999. #else
  2000. #define __syscall_fcntl64 __syscall_fcntl
  2001. extern int __syscall_fcntl(int fd, int cmd, ...);
  2002. #endif
  2003. int __libc_fcntl64(int fd, int cmd, ...)
  2004. {
  2005. long arg;
  2006. va_list list;
  2007. va_start(list, cmd);
  2008. arg = va_arg(list, long);
  2009. va_end(list);
  2010. return(__syscall_fcntl64(fd, cmd, arg));
  2011. }
  2012. weak_alias(__libc_fcntl64, fcntl64)
  2013. #endif
  2014. //#define __NR_security 223 /* syscall for security modules */
  2015. //#define __NR_gettid 224
  2016. //#define __NR_readahead 225