syscalls.c 42 KB

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