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. #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(EINVAL);
  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(EINVAL);
  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_sigprocmask
  1284. #include <signal.h>
  1285. #undef sigprocmask
  1286. _syscall3(int, sigprocmask, int, how, const sigset_t *, set,
  1287. sigset_t *, oldset);
  1288. #endif
  1289. #endif
  1290. //#define __NR_create_module 127
  1291. //See sysdeps/linux/commom/create_module.c
  1292. //#define __NR_init_module 128
  1293. #ifdef L_init_module
  1294. /* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
  1295. * (for 2.2 and 2.4 kernels). Use the greatest common denominator,
  1296. * and let the kernel cope with whatever it gets. It's good at that. */
  1297. _syscall5(int, init_module, void *, first, void *, second, void *, third,
  1298. void *, fourth, void *, fifth);
  1299. #endif
  1300. //#define __NR_delete_module 129
  1301. #ifdef L_delete_module
  1302. # ifdef __NR_delete_module
  1303. _syscall1(int, delete_module, const char *, name);
  1304. # else
  1305. int delete_module(const char * name)
  1306. {
  1307. __set_errno(ENOSYS);
  1308. return -1;
  1309. }
  1310. # endif
  1311. #endif
  1312. //#define __NR_get_kernel_syms 130
  1313. #ifdef L_get_kernel_syms
  1314. struct kernel_sym;
  1315. _syscall1(int, get_kernel_syms, struct kernel_sym *, table);
  1316. #endif
  1317. //#define __NR_quotactl 131
  1318. #ifdef __NR_quotactl
  1319. #ifdef L_quotactl
  1320. #include <sys/quota.h>
  1321. _syscall4(int, quotactl, int, cmd, const char *, special , int, id, caddr_t, addr);
  1322. #endif
  1323. #endif
  1324. //#define __NR_getpgid 132
  1325. #ifdef L___syscall_getpgid
  1326. #define __NR___syscall_getpgid __NR_getpgid
  1327. static inline
  1328. _syscall1(__kernel_pid_t, __syscall_getpgid, __kernel_pid_t, pid);
  1329. pid_t getpgid(pid_t pid)
  1330. {
  1331. return(__syscall_getpgid(pid));
  1332. }
  1333. #endif
  1334. //#define __NR_fchdir 133
  1335. #ifdef L_fchdir
  1336. #include <unistd.h>
  1337. _syscall1(int, fchdir, int, fd);
  1338. #endif
  1339. //#define __NR_bdflush 134
  1340. #ifdef L_bdflush
  1341. #include <sys/kdaemon.h>
  1342. _syscall2(int, bdflush, int, __func, long int, __data);
  1343. #endif
  1344. //#define __NR_sysfs 135
  1345. //_syscall3(int, sysfs, int, option, unsigned int, index, char addr);
  1346. //#define __NR_personality 136
  1347. #ifdef __NR_personality
  1348. #ifdef L_personality
  1349. #include <sys/personality.h>
  1350. _syscall1(int, personality, unsigned long int, __persona);
  1351. #endif
  1352. #endif
  1353. //#define __NR_afs_syscall 137
  1354. //#define __NR_setfsuid 138
  1355. #ifdef __NR_setfsuid
  1356. #ifdef L___syscall_setfsuid
  1357. #include <sys/fsuid.h>
  1358. #define __NR___syscall_setfsuid __NR_setfsuid
  1359. static inline
  1360. _syscall1(int, __syscall_setfsuid, __kernel_uid_t, uid);
  1361. int setfsuid(uid_t uid)
  1362. {
  1363. if (uid != (uid_t) ((__kernel_uid_t) uid))
  1364. {
  1365. __set_errno (EINVAL);
  1366. return -1;
  1367. }
  1368. return(__syscall_setfsuid(uid));
  1369. }
  1370. #endif
  1371. #endif
  1372. //#define __NR_setfsgid 139
  1373. #ifdef __NR_setfsgid
  1374. #ifdef L___syscall_setfsgid
  1375. #include <sys/fsuid.h>
  1376. #define __NR___syscall_setfsgid __NR_setfsgid
  1377. static inline
  1378. _syscall1(int, __syscall_setfsgid, __kernel_gid_t, gid);
  1379. int setfsgid(gid_t gid)
  1380. {
  1381. if (gid != (gid_t) ((__kernel_gid_t) gid))
  1382. {
  1383. __set_errno (EINVAL);
  1384. return -1;
  1385. }
  1386. return(__syscall_setfsgid(gid));
  1387. }
  1388. #endif
  1389. #endif
  1390. //#define __NR__llseek 140
  1391. //See llseek.c
  1392. //#define __NR_getdents 141
  1393. // See getdents.c
  1394. //#define __NR__newselect 142
  1395. #ifdef L__newselect
  1396. //Used in preference to select when available...
  1397. #ifdef __NR__newselect
  1398. #include <unistd.h>
  1399. extern int _newselect(int n, fd_set *readfds, fd_set *writefds,
  1400. fd_set *exceptfds, struct timeval *timeout);
  1401. _syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *, writefds,
  1402. fd_set *, exceptfds, struct timeval *, timeout);
  1403. weak_alias(_newselect, select);
  1404. #endif
  1405. #endif
  1406. //#define __NR_flock 143
  1407. #ifdef L___syscall_flock
  1408. #include <sys/file.h>
  1409. #define __NR___syscall_flock __NR_flock
  1410. static inline
  1411. _syscall2(int, __syscall_flock, int, fd, int, operation);
  1412. int flock(int fd, int operation)
  1413. {
  1414. return(__syscall_flock(fd, operation));
  1415. }
  1416. #endif
  1417. //#define __NR_msync 144
  1418. #ifdef L___libc_msync
  1419. #include <unistd.h>
  1420. #include <sys/mman.h>
  1421. #define __NR___libc_msync __NR_msync
  1422. _syscall3(int, __libc_msync, void *, addr, size_t, length, int, flags);
  1423. weak_alias(__libc_msync, msync);
  1424. #endif
  1425. //#define __NR_readv 145
  1426. #ifdef L_readv
  1427. #include <sys/uio.h>
  1428. _syscall3(ssize_t, readv, int, filedes, const struct iovec *, vector, int,
  1429. count);
  1430. #endif
  1431. //#define __NR_writev 146
  1432. #ifdef L_writev
  1433. #include <sys/uio.h>
  1434. _syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector, int,
  1435. count);
  1436. #endif
  1437. //#define __NR_getsid 147
  1438. #ifdef L___syscall_getsid
  1439. #include <unistd.h>
  1440. #define __NR___syscall_getsid __NR_getsid
  1441. static inline
  1442. _syscall1(__kernel_pid_t, __syscall_getsid, __kernel_pid_t, pid);
  1443. pid_t getsid(pid_t pid)
  1444. {
  1445. return(__syscall_getsid(pid));
  1446. }
  1447. #endif
  1448. //#define __NR_fdatasync 148
  1449. #ifdef __NR_fdatasync
  1450. #ifdef L_fdatasync
  1451. #include <unistd.h>
  1452. _syscall1(int, fdatasync, int, fd);
  1453. #endif
  1454. #endif
  1455. //#define __NR__sysctl 149
  1456. #ifdef __NR__sysctl
  1457. #ifdef L__sysctl
  1458. struct __sysctl_args {
  1459. int *name;
  1460. int nlen;
  1461. void *oldval;
  1462. size_t *oldlenp;
  1463. void *newval;
  1464. size_t newlen;
  1465. unsigned long __unused[4];
  1466. };
  1467. _syscall1(int, _sysctl, struct __sysctl_args *, args);
  1468. int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
  1469. void *newval, size_t newlen)
  1470. {
  1471. struct __sysctl_args args =
  1472. {
  1473. name: name,
  1474. nlen: nlen,
  1475. oldval: oldval,
  1476. oldlenp: oldlenp,
  1477. newval: newval,
  1478. newlen: newlen
  1479. };
  1480. return _sysctl(&args);
  1481. }
  1482. #endif
  1483. #endif
  1484. //#define __NR_mlock 150
  1485. #ifdef L_mlock
  1486. #include <sys/mman.h>
  1487. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlock
  1488. _syscall2(int, mlock, const void *, addr, size_t, len);
  1489. # endif
  1490. #endif
  1491. //#define __NR_munlock 151
  1492. #ifdef L_munlock
  1493. #include <sys/mman.h>
  1494. # if defined __UCLIBC_HAS_MMU__ && defined __NR_munlock
  1495. _syscall2(int, munlock, const void *, addr, size_t, len);
  1496. # endif
  1497. #endif
  1498. //#define __NR_mlockall 152
  1499. #ifdef L_mlockall
  1500. #include <sys/mman.h>
  1501. # if defined __UCLIBC_HAS_MMU__ && defined __NR_mlockall
  1502. _syscall1(int, mlockall, int, flags);
  1503. # endif
  1504. #endif
  1505. //#define __NR_munlockall 153
  1506. #ifdef L_munlockall
  1507. #include <sys/mman.h>
  1508. # if defined __UCLIBC_HAS_MMU__ && defined L_munlockall
  1509. _syscall0(int, munlockall);
  1510. # endif
  1511. #endif
  1512. //#define __NR_sched_setparam 154
  1513. #ifdef __NR_sched_setparam
  1514. #ifdef L___syscall_sched_setparam
  1515. #include <sched.h>
  1516. #define __NR___syscall_sched_setparam __NR_sched_setparam
  1517. static inline
  1518. _syscall2(int, __syscall_sched_setparam, __kernel_pid_t, pid, const struct sched_param *, p);
  1519. int sched_setparam(pid_t pid, const struct sched_param * p)
  1520. {
  1521. return(__syscall_sched_setparam(pid, p));
  1522. }
  1523. #endif
  1524. #endif
  1525. //#define __NR_sched_getparam 155
  1526. #ifdef __NR_sched_getparam
  1527. #ifdef L___syscall_sched_getparam
  1528. #include <sched.h>
  1529. #define __NR___syscall_sched_getparam __NR_sched_getparam
  1530. static inline
  1531. _syscall2(int, __syscall_sched_getparam, __kernel_pid_t, pid, struct sched_param *, p);
  1532. int sched_getparam(pid_t pid, struct sched_param * p)
  1533. {
  1534. return(__syscall_sched_getparam(pid, p));
  1535. }
  1536. #endif
  1537. #endif
  1538. //#define __NR_sched_setscheduler 156
  1539. #ifdef __NR_sched_setscheduler
  1540. #ifdef L___syscall_sched_setscheduler
  1541. #include <sched.h>
  1542. #define __NR___syscall_sched_setscheduler __NR_sched_setscheduler
  1543. static inline
  1544. _syscall3(int, __syscall_sched_setscheduler, __kernel_pid_t, pid, int, policy, const struct sched_param *, p);
  1545. int sched_setscheduler(pid_t pid, int policy, const struct sched_param * p)
  1546. {
  1547. return(__syscall_sched_setscheduler(pid, policy, p));
  1548. }
  1549. #endif
  1550. #endif
  1551. //#define __NR_sched_getscheduler 157
  1552. #ifdef __NR_sched_getscheduler
  1553. #ifdef L___syscall_sched_getscheduler
  1554. #include <sched.h>
  1555. #define __NR___syscall_sched_getscheduler __NR_sched_getscheduler
  1556. static inline
  1557. _syscall1(int, __syscall_sched_getscheduler, __kernel_pid_t, pid);
  1558. int sched_getscheduler(pid_t pid)
  1559. {
  1560. return(__syscall_sched_getscheduler(pid));
  1561. }
  1562. #endif
  1563. #endif
  1564. //#define __NR_sched_yield 158
  1565. #ifdef __NR_sched_yield
  1566. #ifdef L_sched_yield
  1567. #include <sched.h>
  1568. _syscall0(int, sched_yield);
  1569. #endif
  1570. #endif
  1571. //#define __NR_sched_get_priority_max 159
  1572. #ifdef __NR_sched_get_priority_max
  1573. #ifdef L_sched_get_priority_max
  1574. #include <sched.h>
  1575. _syscall1(int, sched_get_priority_max, int, policy);
  1576. #endif
  1577. #endif
  1578. //#define __NR_sched_get_priority_min 160
  1579. #ifdef __NR_sched_get_priority_min
  1580. #ifdef L_sched_get_priority_min
  1581. #include <sched.h>
  1582. _syscall1(int, sched_get_priority_min, int, policy);
  1583. #endif
  1584. #endif
  1585. //#define __NR_sched_rr_get_interval 161
  1586. #ifdef __NR_sched_rr_get_interval
  1587. #ifdef L___syscall_sched_rr_get_interval
  1588. #include <sched.h>
  1589. #define __NR___syscall_sched_rr_get_interval __NR_sched_rr_get_interval
  1590. static inline
  1591. _syscall2(int, __syscall_sched_rr_get_interval, __kernel_pid_t, pid, struct timespec *, tp);
  1592. int sched_rr_get_interval(pid_t pid, struct timespec * tp)
  1593. {
  1594. return(__syscall_sched_rr_get_interval(pid, tp));
  1595. }
  1596. #endif
  1597. #endif
  1598. //#define __NR_nanosleep 162
  1599. #ifdef L___libc_nanosleep
  1600. #include <time.h>
  1601. #define __NR___libc_nanosleep __NR_nanosleep
  1602. _syscall2(int, __libc_nanosleep, const struct timespec *, req, struct timespec *, rem);
  1603. weak_alias(__libc_nanosleep, nanosleep)
  1604. #endif
  1605. //#define __NR_mremap 163
  1606. #ifdef L_mremap
  1607. #include <unistd.h>
  1608. #include <sys/mman.h>
  1609. _syscall4(__ptr_t, mremap, __ptr_t, old_address, size_t, old_size, size_t, new_size, int, may_move);
  1610. #endif
  1611. //#define __NR_setresuid 164
  1612. #ifdef __NR_setresuid
  1613. #ifdef L___syscall_setresuid
  1614. #define __NR___syscall_setresuid __NR_setresuid
  1615. static inline
  1616. _syscall3(int, __syscall_setresuid, __kernel_uid_t, rgid, __kernel_uid_t, egid, __kernel_uid_t, sgid);
  1617. int setresuid(uid_t ruid, uid_t euid, uid_t suid)
  1618. {
  1619. if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1620. || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1621. || ((suid + 1) > (uid_t) ((__kernel_uid_t) -1U)))
  1622. {
  1623. __set_errno (EINVAL);
  1624. return -1;
  1625. }
  1626. return(__syscall_setresuid(ruid, euid, suid));
  1627. }
  1628. #endif
  1629. #endif
  1630. //#define __NR_getresuid 165
  1631. #ifdef __NR_getresuid
  1632. #ifdef L___syscall_getresuid
  1633. #define __NR___syscall_getresuid __NR_getresuid
  1634. static inline
  1635. _syscall3(int, __syscall_getresuid, __kernel_uid_t *, ruid, __kernel_uid_t *, euid, __kernel_uid_t *, suid);
  1636. int getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
  1637. {
  1638. int result;
  1639. __kernel_uid_t k_ruid, k_euid, k_suid;
  1640. result = __syscall_getresuid(&k_ruid, &k_euid, &k_suid);
  1641. if (result == 0) {
  1642. *ruid = (uid_t) k_ruid;
  1643. *euid = (uid_t) k_euid;
  1644. *suid = (uid_t) k_suid;
  1645. }
  1646. return result;
  1647. }
  1648. #endif
  1649. #endif
  1650. //#define __NR_vm86 166
  1651. //#define __NR_query_module 167
  1652. #ifdef L_query_module
  1653. # ifdef __NR_query_module
  1654. _syscall5(int, query_module, const char *, name, int, which,
  1655. void *, buf, size_t, bufsize, size_t*, ret);
  1656. # else
  1657. int query_module(const char * name, int which,
  1658. void * buf, size_t bufsize, size_t* ret)
  1659. {
  1660. __set_errno(ENOSYS);
  1661. return -1;
  1662. }
  1663. # endif
  1664. #endif
  1665. //#define __NR_poll 168
  1666. #ifdef L_poll
  1667. #ifdef __NR_poll
  1668. #include <sys/poll.h>
  1669. _syscall3(int, poll, struct pollfd *, fds, unsigned long int, nfds, int, timeout);
  1670. #else
  1671. /* uClinux 2.0 doesn't have poll, emulate it using select */
  1672. #include "poll.c"
  1673. #endif
  1674. #endif
  1675. //#define __NR_nfsservctl 169
  1676. //nfsservctl EXTRA nfsservctl i:ipp nfsservctl
  1677. //#define __NR_setresgid 170
  1678. #ifdef __NR_setresgid
  1679. #ifdef L___syscall_setresgid
  1680. #define __NR___syscall_setresgid __NR_setresgid
  1681. static inline
  1682. _syscall3(int, __syscall_setresgid, __kernel_gid_t, rgid, __kernel_gid_t, egid, __kernel_gid_t, sgid);
  1683. int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
  1684. {
  1685. if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  1686. || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U))
  1687. || ((sgid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  1688. {
  1689. __set_errno (EINVAL);
  1690. return -1;
  1691. }
  1692. return(__syscall_setresgid(rgid, egid, sgid));
  1693. }
  1694. #endif
  1695. #endif
  1696. //#define __NR_getresgid 171
  1697. #ifdef __NR_getresgid
  1698. #ifdef L___syscall_getresgid
  1699. #define __NR___syscall_getresgid __NR_getresgid
  1700. static inline
  1701. _syscall3(int, __syscall_getresgid, __kernel_gid_t *, egid, __kernel_gid_t *, rgid, __kernel_gid_t *, sgid);
  1702. int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
  1703. {
  1704. int result;
  1705. __kernel_gid_t k_rgid, k_egid, k_sgid;
  1706. result = __syscall_getresgid(&k_rgid, &k_egid, &k_sgid);
  1707. if (result == 0) {
  1708. *rgid = (gid_t) k_rgid;
  1709. *egid = (gid_t) k_egid;
  1710. *sgid = (gid_t) k_sgid;
  1711. }
  1712. return result;
  1713. }
  1714. #endif
  1715. #endif
  1716. //#define __NR_prctl 172
  1717. #ifdef __NR_prctl
  1718. #ifdef L_prctl
  1719. #include <stdarg.h>
  1720. //#include <sys/prctl.h>
  1721. _syscall5(int, prctl, int, a, int, b, int, c, int, d, int, e);
  1722. #endif
  1723. #endif
  1724. //#define __NR_rt_sigreturn 173
  1725. //#define __NR_rt_sigaction 174
  1726. #ifdef __NR_rt_sigaction
  1727. #define __NR___syscall_rt_sigaction __NR_rt_sigaction
  1728. #ifdef L___syscall_rt_sigaction
  1729. #include <signal.h>
  1730. #undef sigaction
  1731. _syscall4(int, __syscall_rt_sigaction, int, signum, const struct sigaction *, act,
  1732. struct sigaction *, oldact, size_t, size);
  1733. #endif
  1734. #endif
  1735. //#define __NR_rt_sigprocmask 175
  1736. #ifdef __NR_rt_sigprocmask
  1737. #define __NR___rt_sigprocmask __NR_rt_sigprocmask
  1738. #ifdef L___rt_sigprocmask
  1739. #include <signal.h>
  1740. #undef sigprocmask
  1741. _syscall4(int, __rt_sigprocmask, int, how, const sigset_t *, set,
  1742. sigset_t *, oldset, size_t, size);
  1743. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
  1744. {
  1745. return __rt_sigprocmask(how, set, oldset, _NSIG/8);
  1746. }
  1747. #endif
  1748. #endif
  1749. //#define __NR_rt_sigpending 176
  1750. #ifdef __NR_rt_sigpending
  1751. #define __NR___rt_sigpending __NR_rt_sigpending
  1752. #ifdef L___rt_sigpending
  1753. #include <signal.h>
  1754. #undef sigpending
  1755. _syscall2(int, __rt_sigpending, sigset_t *, set, size_t, size);
  1756. int sigpending(sigset_t *set)
  1757. {
  1758. return __rt_sigpending(set, _NSIG/8);
  1759. }
  1760. #endif
  1761. #endif
  1762. //#define __NR_rt_sigtimedwait 177
  1763. #ifdef L___rt_sigtimedwait
  1764. #include <signal.h>
  1765. #define __need_NULL
  1766. #include <stddef.h>
  1767. #ifdef __NR_rt_sigtimedwait
  1768. #define __NR___rt_sigtimedwait __NR_rt_sigtimedwait
  1769. _syscall4(int, __rt_sigtimedwait, const sigset_t *, set, siginfo_t *, info,
  1770. const struct timespec *, timeout, size_t, setsize);
  1771. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1772. {
  1773. return __rt_sigtimedwait (set, info, NULL, _NSIG/8);
  1774. }
  1775. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1776. {
  1777. return __rt_sigtimedwait (set, info, timeout, _NSIG/8);
  1778. }
  1779. #else
  1780. int sigwaitinfo(const sigset_t *set, siginfo_t *info)
  1781. {
  1782. if (set==NULL)
  1783. __set_errno (EINVAL);
  1784. else
  1785. __set_errno (ENOSYS);
  1786. return -1;
  1787. }
  1788. int sigtimedwait (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  1789. {
  1790. if (set==NULL)
  1791. __set_errno (EINVAL);
  1792. else
  1793. __set_errno (ENOSYS);
  1794. return -1;
  1795. }
  1796. #endif
  1797. #endif
  1798. //#define __NR_rt_sigqueueinfo 178
  1799. //#define __NR_rt_sigsuspend 179
  1800. #ifdef __NR_rt_sigsuspend
  1801. #define __NR___rt_sigsuspend __NR_rt_sigsuspend
  1802. #ifdef L___rt_sigsuspend
  1803. #include <signal.h>
  1804. #undef _sigsuspend
  1805. _syscall2(int, __rt_sigsuspend, const sigset_t *, mask, size_t, size);
  1806. int sigsuspend (const sigset_t *mask)
  1807. {
  1808. return __rt_sigsuspend(mask, _NSIG/8);
  1809. }
  1810. #endif
  1811. #endif
  1812. //#define __NR_pread 180
  1813. // See pread_write.c
  1814. //#define __NR_pwrite 181
  1815. // See pread_write.c
  1816. //#define __NR_chown 182
  1817. #ifdef L___syscall_chown
  1818. #include <unistd.h>
  1819. #define __NR___syscall_chown __NR_chown
  1820. static inline
  1821. _syscall3(int, __syscall_chown, const char *, path, __kernel_uid_t, owner, __kernel_gid_t, group);
  1822. int chown(const char * path, uid_t owner, gid_t group)
  1823. {
  1824. if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
  1825. || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
  1826. {
  1827. __set_errno (EINVAL);
  1828. return -1;
  1829. }
  1830. return(__syscall_chown(path, owner, group));
  1831. }
  1832. #endif
  1833. //#define __NR_getcwd 183
  1834. // See getcwd.c in this directory
  1835. //#define __NR_capget 184
  1836. #ifdef L_capget
  1837. # ifdef __NR_capget
  1838. _syscall2(int, capget, void*, header, void*, data);
  1839. # else
  1840. int capget(void* header, void* data)
  1841. {
  1842. __set_errno(ENOSYS);
  1843. return -1;
  1844. }
  1845. # endif
  1846. #endif
  1847. //#define __NR_capset 185
  1848. #ifdef L_capset
  1849. # ifdef __NR_capset
  1850. _syscall2(int, capset, void*, header, const void*, data);
  1851. # else
  1852. int capset(void* header, const void* data)
  1853. {
  1854. __set_errno(ENOSYS);
  1855. return -1;
  1856. }
  1857. # endif
  1858. #endif
  1859. //#define __NR_sigaltstack 186
  1860. #ifdef __NR_sigaltstack
  1861. #ifdef L_sigaltstack
  1862. #include <signal.h>
  1863. _syscall2(int, sigaltstack, const struct sigaltstack *, ss, struct sigaltstack *, oss);
  1864. #endif
  1865. #endif
  1866. //#define __NR_sendfile 187
  1867. #ifdef __NR_sendfile
  1868. #ifdef L_sendfile
  1869. #include <unistd.h>
  1870. #include <sys/sendfile.h>
  1871. _syscall4(ssize_t,sendfile, int, out_fd, int, in_fd, __off_t *, offset, size_t, count);
  1872. #endif
  1873. #endif
  1874. //#define __NR_getpmsg 188
  1875. //#define __NR_putpmsg 189
  1876. //#define __NR_vfork 190
  1877. //See sysdeps/linux/<arch>vfork.[cS] for architecture specific implementation...
  1878. //#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
  1879. #ifdef L___ugetrlimit
  1880. #ifdef __NR_ugetrlimit
  1881. #define __NR___ugetrlimit __NR_ugetrlimit
  1882. #include <unistd.h>
  1883. #include <sys/resource.h>
  1884. _syscall2(int, __ugetrlimit, enum __rlimit_resource, resource, struct rlimit *, rlim);
  1885. int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
  1886. {
  1887. return(__ugetrlimit(resource, rlimits));
  1888. }
  1889. #endif /* __NR_ugetrlimit */
  1890. #endif
  1891. //#define __NR_mmap2 192
  1892. //#define __NR_truncate64 193
  1893. //See libc/sysdeps/linux/common/truncate64.c
  1894. //#define __NR_ftruncate64 194
  1895. //See libc/sysdeps/linux/common/ftruncate64.c
  1896. //#define __NR_stat64 195
  1897. #ifdef L___syscall_stat64
  1898. #if defined __UCLIBC_HAS_LFS__ && defined __NR_stat64
  1899. #define __NR___syscall_stat64 __NR_stat64
  1900. #include <unistd.h>
  1901. #include <sys/stat.h>
  1902. #include <bits/kernel_stat.h>
  1903. #include "xstatconv.h"
  1904. _syscall2(int, __syscall_stat64, const char *, file_name, struct kernel_stat64 *, buf);
  1905. int stat64(const char * file_name, struct stat64 * buf)
  1906. {
  1907. int result;
  1908. struct kernel_stat64 kbuf;
  1909. result = __syscall_stat64(file_name, &kbuf);
  1910. if (result == 0) {
  1911. __xstat64_conv(&kbuf, buf);
  1912. }
  1913. return result;
  1914. }
  1915. #endif /* __UCLIBC_HAS_LFS__ */
  1916. #endif
  1917. //#define __NR_lstat64 196
  1918. #ifdef L___syscall_lstat64
  1919. #if defined __UCLIBC_HAS_LFS__ && defined __NR_lstat64
  1920. #define __NR___syscall_lstat64 __NR_lstat64
  1921. #include <unistd.h>
  1922. #include <sys/stat.h>
  1923. #include <bits/kernel_stat.h>
  1924. #include "xstatconv.h"
  1925. _syscall2(int, __syscall_lstat64, const char *, file_name, struct kernel_stat64 *, buf);
  1926. int lstat64(const char * file_name, struct stat64 * buf)
  1927. {
  1928. int result;
  1929. struct kernel_stat64 kbuf;
  1930. result = __syscall_lstat64(file_name, &kbuf);
  1931. if (result == 0) {
  1932. __xstat64_conv(&kbuf, buf);
  1933. }
  1934. return result;
  1935. }
  1936. #endif /* __UCLIBC_HAS_LFS__ */
  1937. #endif
  1938. //#define __NR_fstat64 197
  1939. #ifdef L___syscall_fstat64
  1940. #if defined __UCLIBC_HAS_LFS__ && defined __NR_fstat64
  1941. #define __NR___syscall_fstat64 __NR_fstat64
  1942. #include <unistd.h>
  1943. #include <sys/stat.h>
  1944. #include <bits/kernel_stat.h>
  1945. #include "xstatconv.h"
  1946. _syscall2(int, __syscall_fstat64, int, filedes, struct kernel_stat64 *, buf);
  1947. int fstat64(int fd, struct stat64 * buf)
  1948. {
  1949. int result;
  1950. struct kernel_stat64 kbuf;
  1951. result = __syscall_fstat64(fd, &kbuf);
  1952. if (result == 0) {
  1953. __xstat64_conv(&kbuf, buf);
  1954. }
  1955. return result;
  1956. }
  1957. #endif /* __UCLIBC_HAS_LFS__ */
  1958. #endif
  1959. //#define __NR_lchown32 198
  1960. //#define __NR_getuid32 199
  1961. //#define __NR_getgid32 200
  1962. //#define __NR_geteuid32 201
  1963. //#define __NR_getegid32 202
  1964. //#define __NR_setreuid32 203
  1965. //#define __NR_setregid32 204
  1966. //#define __NR_getgroups32 205
  1967. //#define __NR_setgroups32 206
  1968. //#define __NR_fchown32 207
  1969. //#define __NR_setresuid32 208
  1970. //#define __NR_getresuid32 209
  1971. //#define __NR_setresgid32 210
  1972. //#define __NR_getresgid32 211
  1973. //#define __NR_chown32 212
  1974. //#define __NR_setuid32 213
  1975. //#define __NR_setgid32 214
  1976. //#define __NR_setfsuid32 215
  1977. //#define __NR_setfsgid32 216
  1978. //#define __NR_pivot_root 217
  1979. #ifdef __NR_pivot_root
  1980. #ifdef L_pivot_root
  1981. _syscall2(int, pivot_root, const char *, new_root, const char *, put_old);
  1982. #endif
  1983. #endif
  1984. //#define __NR_mincore 218
  1985. //#define __NR_madvise 219
  1986. #ifdef __NR_madvise
  1987. #ifdef L_madvise
  1988. _syscall3(int, madvise, void*, __addr, size_t, __len, int, __advice);
  1989. #endif
  1990. #endif
  1991. //#define __NR_madvise1 219 /* delete when C lib stub is removed */
  1992. //#define __NR_getdents64 220
  1993. // See getdents64.c
  1994. //#define __NR_fcntl64 221
  1995. #ifdef L___syscall_fcntl64
  1996. #include <stdarg.h>
  1997. #include <fcntl.h>
  1998. #if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  1999. #define __NR___syscall_fcntl64 __NR_fcntl64
  2000. static inline
  2001. _syscall3(int, __syscall_fcntl64, int, fd, int, cmd, long, arg);
  2002. int __libc_fcntl64(int fd, int cmd, ...)
  2003. {
  2004. long arg;
  2005. va_list list;
  2006. va_start(list, cmd);
  2007. arg = va_arg(list, long);
  2008. va_end(list);
  2009. return(__syscall_fcntl64(fd, cmd, arg));
  2010. }
  2011. weak_alias(__libc_fcntl64, fcntl64)
  2012. #endif
  2013. #endif
  2014. //#define __NR_security 223 /* syscall for security modules */
  2015. //#define __NR_gettid 224
  2016. //#define __NR_readahead 225