syscalls.c 44 KB

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