sys.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2. /*
  3. * Syscall definitions for NOLIBC (those in man(2))
  4. * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
  5. */
  6. /* make sure to include all global symbols */
  7. #include "nolibc.h"
  8. #ifndef _NOLIBC_SYS_H
  9. #define _NOLIBC_SYS_H
  10. #include "std.h"
  11. /* system includes */
  12. #include <linux/unistd.h>
  13. #include <linux/signal.h> /* for SIGCHLD */
  14. #include <linux/termios.h>
  15. #include <linux/mman.h>
  16. #include <linux/fs.h>
  17. #include <linux/loop.h>
  18. #include <linux/time.h>
  19. #include <linux/auxvec.h>
  20. #include <linux/fcntl.h> /* for O_* and AT_* */
  21. #include <linux/sched.h> /* for CLONE_* */
  22. #include <linux/stat.h> /* for statx() */
  23. #include "errno.h"
  24. #include "stdarg.h"
  25. #include "types.h"
  26. /* Syscall return helper: takes the syscall value in argument and checks for an
  27. * error in it. This may only be used with signed returns (int or long), but
  28. * not with pointers. An error is any value < 0. When an error is encountered,
  29. * -ret is set into errno and -1 is returned. Otherwise the returned value is
  30. * passed as-is with its type preserved.
  31. */
  32. #define __sysret(arg) \
  33. ({ \
  34. __typeof__(arg) __sysret_arg = (arg); \
  35. (__sysret_arg < 0) /* error ? */ \
  36. ? (({ SET_ERRNO(-__sysret_arg); }), -1) /* ret -1 with errno = -arg */ \
  37. : __sysret_arg; /* return original value */ \
  38. })
  39. /* Syscall ENOSYS helper: Avoids unused-parameter warnings and provides a
  40. * debugging hook.
  41. */
  42. static __inline__ int __nolibc_enosys(const char *syscall, ...)
  43. {
  44. (void)syscall;
  45. return -ENOSYS;
  46. }
  47. /* Functions in this file only describe syscalls. They're declared static so
  48. * that the compiler usually decides to inline them while still being allowed
  49. * to pass a pointer to one of their instances. Each syscall exists in two
  50. * versions:
  51. * - the "internal" ones, which matches the raw syscall interface at the
  52. * kernel level, which may sometimes slightly differ from the documented
  53. * libc-level ones. For example most of them return either a valid value
  54. * or -errno. All of these are prefixed with "sys_". They may be called
  55. * by non-portable applications if desired.
  56. *
  57. * - the "exported" ones, whose interface must closely match the one
  58. * documented in man(2), that applications are supposed to expect. These
  59. * ones rely on the internal ones, and set errno.
  60. *
  61. * Each syscall will be defined with the two functions, sorted in alphabetical
  62. * order applied to the exported names.
  63. *
  64. * In case of doubt about the relevance of a function here, only those which
  65. * set errno should be defined here. Wrappers like those appearing in man(3)
  66. * should not be placed here.
  67. */
  68. /*
  69. * int brk(void *addr);
  70. * void *sbrk(intptr_t inc)
  71. */
  72. static __attribute__((unused))
  73. void *sys_brk(void *addr)
  74. {
  75. return (void *)my_syscall1(__NR_brk, addr);
  76. }
  77. static __attribute__((unused))
  78. int brk(void *addr)
  79. {
  80. void *ret = sys_brk(addr);
  81. if (!ret) {
  82. SET_ERRNO(ENOMEM);
  83. return -1;
  84. }
  85. return 0;
  86. }
  87. static __attribute__((unused))
  88. void *sbrk(intptr_t inc)
  89. {
  90. /* first call to find current end */
  91. void *ret = sys_brk(NULL);
  92. if (ret && sys_brk(ret + inc) == ret + inc)
  93. return ret + inc;
  94. SET_ERRNO(ENOMEM);
  95. return (void *)-1;
  96. }
  97. /*
  98. * int chdir(const char *path);
  99. * int fchdir(int fildes);
  100. */
  101. static __attribute__((unused))
  102. int sys_chdir(const char *path)
  103. {
  104. return my_syscall1(__NR_chdir, path);
  105. }
  106. static __attribute__((unused))
  107. int chdir(const char *path)
  108. {
  109. return __sysret(sys_chdir(path));
  110. }
  111. static __attribute__((unused))
  112. int sys_fchdir(int fildes)
  113. {
  114. return my_syscall1(__NR_fchdir, fildes);
  115. }
  116. static __attribute__((unused))
  117. int fchdir(int fildes)
  118. {
  119. return __sysret(sys_fchdir(fildes));
  120. }
  121. /*
  122. * int chmod(const char *path, mode_t mode);
  123. */
  124. static __attribute__((unused))
  125. int sys_chmod(const char *path, mode_t mode)
  126. {
  127. #if defined(__NR_fchmodat)
  128. return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0);
  129. #else
  130. return my_syscall2(__NR_chmod, path, mode);
  131. #endif
  132. }
  133. static __attribute__((unused))
  134. int chmod(const char *path, mode_t mode)
  135. {
  136. return __sysret(sys_chmod(path, mode));
  137. }
  138. /*
  139. * int chown(const char *path, uid_t owner, gid_t group);
  140. */
  141. static __attribute__((unused))
  142. int sys_chown(const char *path, uid_t owner, gid_t group)
  143. {
  144. #if defined(__NR_fchownat)
  145. return my_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0);
  146. #else
  147. return my_syscall3(__NR_chown, path, owner, group);
  148. #endif
  149. }
  150. static __attribute__((unused))
  151. int chown(const char *path, uid_t owner, gid_t group)
  152. {
  153. return __sysret(sys_chown(path, owner, group));
  154. }
  155. /*
  156. * int chroot(const char *path);
  157. */
  158. static __attribute__((unused))
  159. int sys_chroot(const char *path)
  160. {
  161. return my_syscall1(__NR_chroot, path);
  162. }
  163. static __attribute__((unused))
  164. int chroot(const char *path)
  165. {
  166. return __sysret(sys_chroot(path));
  167. }
  168. /*
  169. * int close(int fd);
  170. */
  171. static __attribute__((unused))
  172. int sys_close(int fd)
  173. {
  174. return my_syscall1(__NR_close, fd);
  175. }
  176. static __attribute__((unused))
  177. int close(int fd)
  178. {
  179. return __sysret(sys_close(fd));
  180. }
  181. /*
  182. * int dup(int fd);
  183. */
  184. static __attribute__((unused))
  185. int sys_dup(int fd)
  186. {
  187. return my_syscall1(__NR_dup, fd);
  188. }
  189. static __attribute__((unused))
  190. int dup(int fd)
  191. {
  192. return __sysret(sys_dup(fd));
  193. }
  194. /*
  195. * int dup2(int old, int new);
  196. */
  197. static __attribute__((unused))
  198. int sys_dup2(int old, int new)
  199. {
  200. #if defined(__NR_dup3)
  201. int ret, nr_fcntl;
  202. #ifdef __NR_fcntl64
  203. nr_fcntl = __NR_fcntl64;
  204. #else
  205. nr_fcntl = __NR_fcntl;
  206. #endif
  207. if (old == new) {
  208. ret = my_syscall2(nr_fcntl, old, F_GETFD);
  209. return ret < 0 ? ret : old;
  210. }
  211. return my_syscall3(__NR_dup3, old, new, 0);
  212. #else
  213. return my_syscall2(__NR_dup2, old, new);
  214. #endif
  215. }
  216. static __attribute__((unused))
  217. int dup2(int old, int new)
  218. {
  219. return __sysret(sys_dup2(old, new));
  220. }
  221. /*
  222. * int dup3(int old, int new, int flags);
  223. */
  224. #if defined(__NR_dup3)
  225. static __attribute__((unused))
  226. int sys_dup3(int old, int new, int flags)
  227. {
  228. return my_syscall3(__NR_dup3, old, new, flags);
  229. }
  230. static __attribute__((unused))
  231. int dup3(int old, int new, int flags)
  232. {
  233. return __sysret(sys_dup3(old, new, flags));
  234. }
  235. #endif
  236. /*
  237. * int execve(const char *filename, char *const argv[], char *const envp[]);
  238. */
  239. static __attribute__((unused))
  240. int sys_execve(const char *filename, char *const argv[], char *const envp[])
  241. {
  242. return my_syscall3(__NR_execve, filename, argv, envp);
  243. }
  244. static __attribute__((unused))
  245. int execve(const char *filename, char *const argv[], char *const envp[])
  246. {
  247. return __sysret(sys_execve(filename, argv, envp));
  248. }
  249. /*
  250. * void exit(int status);
  251. */
  252. static __attribute__((noreturn,unused))
  253. void sys_exit(int status)
  254. {
  255. my_syscall1(__NR_exit, status & 255);
  256. while(1); /* shut the "noreturn" warnings. */
  257. }
  258. static __attribute__((noreturn,unused))
  259. void _exit(int status)
  260. {
  261. sys_exit(status);
  262. }
  263. static __attribute__((noreturn,unused))
  264. void exit(int status)
  265. {
  266. _exit(status);
  267. }
  268. /*
  269. * pid_t fork(void);
  270. */
  271. #ifndef sys_fork
  272. static __attribute__((unused))
  273. pid_t sys_fork(void)
  274. {
  275. #if defined(__NR_clone)
  276. /* note: some archs only have clone() and not fork(). Different archs
  277. * have a different API, but most archs have the flags on first arg and
  278. * will not use the rest with no other flag.
  279. */
  280. return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0);
  281. #else
  282. return my_syscall0(__NR_fork);
  283. #endif
  284. }
  285. #endif
  286. static __attribute__((unused))
  287. pid_t fork(void)
  288. {
  289. return __sysret(sys_fork());
  290. }
  291. #ifndef sys_vfork
  292. static __attribute__((unused))
  293. pid_t sys_vfork(void)
  294. {
  295. #if defined(__NR_clone)
  296. /* See the note in sys_fork(). */
  297. return my_syscall5(__NR_clone, CLONE_VM | CLONE_VFORK | SIGCHLD, 0, 0, 0, 0);
  298. #elif defined(__NR_vfork)
  299. return my_syscall0(__NR_vfork);
  300. #endif
  301. }
  302. #endif
  303. static __attribute__((unused))
  304. pid_t vfork(void)
  305. {
  306. return __sysret(sys_vfork());
  307. }
  308. /*
  309. * int fsync(int fd);
  310. */
  311. static __attribute__((unused))
  312. int sys_fsync(int fd)
  313. {
  314. return my_syscall1(__NR_fsync, fd);
  315. }
  316. static __attribute__((unused))
  317. int fsync(int fd)
  318. {
  319. return __sysret(sys_fsync(fd));
  320. }
  321. /*
  322. * int getdents64(int fd, struct linux_dirent64 *dirp, int count);
  323. */
  324. static __attribute__((unused))
  325. int sys_getdents64(int fd, struct linux_dirent64 *dirp, int count)
  326. {
  327. return my_syscall3(__NR_getdents64, fd, dirp, count);
  328. }
  329. static __attribute__((unused))
  330. int getdents64(int fd, struct linux_dirent64 *dirp, int count)
  331. {
  332. return __sysret(sys_getdents64(fd, dirp, count));
  333. }
  334. /*
  335. * uid_t geteuid(void);
  336. */
  337. static __attribute__((unused))
  338. uid_t sys_geteuid(void)
  339. {
  340. #if defined(__NR_geteuid32)
  341. return my_syscall0(__NR_geteuid32);
  342. #else
  343. return my_syscall0(__NR_geteuid);
  344. #endif
  345. }
  346. static __attribute__((unused))
  347. uid_t geteuid(void)
  348. {
  349. return sys_geteuid();
  350. }
  351. /*
  352. * pid_t getpgid(pid_t pid);
  353. */
  354. static __attribute__((unused))
  355. pid_t sys_getpgid(pid_t pid)
  356. {
  357. return my_syscall1(__NR_getpgid, pid);
  358. }
  359. static __attribute__((unused))
  360. pid_t getpgid(pid_t pid)
  361. {
  362. return __sysret(sys_getpgid(pid));
  363. }
  364. /*
  365. * pid_t getpgrp(void);
  366. */
  367. static __attribute__((unused))
  368. pid_t sys_getpgrp(void)
  369. {
  370. return sys_getpgid(0);
  371. }
  372. static __attribute__((unused))
  373. pid_t getpgrp(void)
  374. {
  375. return sys_getpgrp();
  376. }
  377. /*
  378. * pid_t getpid(void);
  379. */
  380. static __attribute__((unused))
  381. pid_t sys_getpid(void)
  382. {
  383. return my_syscall0(__NR_getpid);
  384. }
  385. static __attribute__((unused))
  386. pid_t getpid(void)
  387. {
  388. return sys_getpid();
  389. }
  390. /*
  391. * pid_t getppid(void);
  392. */
  393. static __attribute__((unused))
  394. pid_t sys_getppid(void)
  395. {
  396. return my_syscall0(__NR_getppid);
  397. }
  398. static __attribute__((unused))
  399. pid_t getppid(void)
  400. {
  401. return sys_getppid();
  402. }
  403. /*
  404. * pid_t gettid(void);
  405. */
  406. static __attribute__((unused))
  407. pid_t sys_gettid(void)
  408. {
  409. return my_syscall0(__NR_gettid);
  410. }
  411. static __attribute__((unused))
  412. pid_t gettid(void)
  413. {
  414. return sys_gettid();
  415. }
  416. #ifndef NOLIBC_NO_RUNTIME
  417. static unsigned long getauxval(unsigned long key);
  418. /*
  419. * int getpagesize(void);
  420. */
  421. static __attribute__((unused))
  422. int getpagesize(void)
  423. {
  424. return __sysret((int)getauxval(AT_PAGESZ) ?: -ENOENT);
  425. }
  426. #endif /* NOLIBC_NO_RUNTIME */
  427. /*
  428. * uid_t getuid(void);
  429. */
  430. static __attribute__((unused))
  431. uid_t sys_getuid(void)
  432. {
  433. #if defined(__NR_getuid32)
  434. return my_syscall0(__NR_getuid32);
  435. #else
  436. return my_syscall0(__NR_getuid);
  437. #endif
  438. }
  439. static __attribute__((unused))
  440. uid_t getuid(void)
  441. {
  442. return sys_getuid();
  443. }
  444. /*
  445. * int kill(pid_t pid, int signal);
  446. */
  447. static __attribute__((unused))
  448. int sys_kill(pid_t pid, int signal)
  449. {
  450. return my_syscall2(__NR_kill, pid, signal);
  451. }
  452. static __attribute__((unused))
  453. int kill(pid_t pid, int signal)
  454. {
  455. return __sysret(sys_kill(pid, signal));
  456. }
  457. /*
  458. * int link(const char *old, const char *new);
  459. */
  460. static __attribute__((unused))
  461. int sys_link(const char *old, const char *new)
  462. {
  463. #if defined(__NR_linkat)
  464. return my_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0);
  465. #else
  466. return my_syscall2(__NR_link, old, new);
  467. #endif
  468. }
  469. static __attribute__((unused))
  470. int link(const char *old, const char *new)
  471. {
  472. return __sysret(sys_link(old, new));
  473. }
  474. /*
  475. * off_t lseek(int fd, off_t offset, int whence);
  476. */
  477. static __attribute__((unused))
  478. off_t sys_lseek(int fd, off_t offset, int whence)
  479. {
  480. #if defined(__NR_llseek)
  481. __kernel_loff_t loff = 0;
  482. off_t result;
  483. int ret;
  484. ret = my_syscall5(__NR_llseek, fd, offset >> 32, (uint32_t)offset, &loff, whence);
  485. if (ret < 0)
  486. result = ret;
  487. else
  488. result = loff;
  489. return result;
  490. #else
  491. return my_syscall3(__NR_lseek, fd, offset, whence);
  492. #endif
  493. }
  494. static __attribute__((unused))
  495. off_t lseek(int fd, off_t offset, int whence)
  496. {
  497. return __sysret(sys_lseek(fd, offset, whence));
  498. }
  499. /*
  500. * int mkdir(const char *path, mode_t mode);
  501. */
  502. static __attribute__((unused))
  503. int sys_mkdir(const char *path, mode_t mode)
  504. {
  505. #if defined(__NR_mkdirat)
  506. return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode);
  507. #else
  508. return my_syscall2(__NR_mkdir, path, mode);
  509. #endif
  510. }
  511. static __attribute__((unused))
  512. int mkdir(const char *path, mode_t mode)
  513. {
  514. return __sysret(sys_mkdir(path, mode));
  515. }
  516. /*
  517. * int rmdir(const char *path);
  518. */
  519. static __attribute__((unused))
  520. int sys_rmdir(const char *path)
  521. {
  522. #if defined(__NR_rmdir)
  523. return my_syscall1(__NR_rmdir, path);
  524. #else
  525. return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
  526. #endif
  527. }
  528. static __attribute__((unused))
  529. int rmdir(const char *path)
  530. {
  531. return __sysret(sys_rmdir(path));
  532. }
  533. /*
  534. * int mknod(const char *path, mode_t mode, dev_t dev);
  535. */
  536. static __attribute__((unused))
  537. long sys_mknod(const char *path, mode_t mode, dev_t dev)
  538. {
  539. #if defined(__NR_mknodat)
  540. return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev);
  541. #else
  542. return my_syscall3(__NR_mknod, path, mode, dev);
  543. #endif
  544. }
  545. static __attribute__((unused))
  546. int mknod(const char *path, mode_t mode, dev_t dev)
  547. {
  548. return __sysret(sys_mknod(path, mode, dev));
  549. }
  550. /*
  551. * int pipe2(int pipefd[2], int flags);
  552. * int pipe(int pipefd[2]);
  553. */
  554. static __attribute__((unused))
  555. int sys_pipe2(int pipefd[2], int flags)
  556. {
  557. return my_syscall2(__NR_pipe2, pipefd, flags);
  558. }
  559. static __attribute__((unused))
  560. int pipe2(int pipefd[2], int flags)
  561. {
  562. return __sysret(sys_pipe2(pipefd, flags));
  563. }
  564. static __attribute__((unused))
  565. int pipe(int pipefd[2])
  566. {
  567. return pipe2(pipefd, 0);
  568. }
  569. /*
  570. * int pivot_root(const char *new, const char *old);
  571. */
  572. static __attribute__((unused))
  573. int sys_pivot_root(const char *new, const char *old)
  574. {
  575. return my_syscall2(__NR_pivot_root, new, old);
  576. }
  577. static __attribute__((unused))
  578. int pivot_root(const char *new, const char *old)
  579. {
  580. return __sysret(sys_pivot_root(new, old));
  581. }
  582. /*
  583. * ssize_t read(int fd, void *buf, size_t count);
  584. */
  585. static __attribute__((unused))
  586. ssize_t sys_read(int fd, void *buf, size_t count)
  587. {
  588. return my_syscall3(__NR_read, fd, buf, count);
  589. }
  590. static __attribute__((unused))
  591. ssize_t read(int fd, void *buf, size_t count)
  592. {
  593. return __sysret(sys_read(fd, buf, count));
  594. }
  595. /*
  596. * int sched_yield(void);
  597. */
  598. static __attribute__((unused))
  599. int sys_sched_yield(void)
  600. {
  601. return my_syscall0(__NR_sched_yield);
  602. }
  603. static __attribute__((unused))
  604. int sched_yield(void)
  605. {
  606. return __sysret(sys_sched_yield());
  607. }
  608. /*
  609. * int setpgid(pid_t pid, pid_t pgid);
  610. */
  611. static __attribute__((unused))
  612. int sys_setpgid(pid_t pid, pid_t pgid)
  613. {
  614. return my_syscall2(__NR_setpgid, pid, pgid);
  615. }
  616. static __attribute__((unused))
  617. int setpgid(pid_t pid, pid_t pgid)
  618. {
  619. return __sysret(sys_setpgid(pid, pgid));
  620. }
  621. /*
  622. * pid_t setpgrp(void)
  623. */
  624. static __attribute__((unused))
  625. pid_t setpgrp(void)
  626. {
  627. return setpgid(0, 0);
  628. }
  629. /*
  630. * pid_t setsid(void);
  631. */
  632. static __attribute__((unused))
  633. pid_t sys_setsid(void)
  634. {
  635. return my_syscall0(__NR_setsid);
  636. }
  637. static __attribute__((unused))
  638. pid_t setsid(void)
  639. {
  640. return __sysret(sys_setsid());
  641. }
  642. /*
  643. * int symlink(const char *old, const char *new);
  644. */
  645. static __attribute__((unused))
  646. int sys_symlink(const char *old, const char *new)
  647. {
  648. #if defined(__NR_symlinkat)
  649. return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new);
  650. #else
  651. return my_syscall2(__NR_symlink, old, new);
  652. #endif
  653. }
  654. static __attribute__((unused))
  655. int symlink(const char *old, const char *new)
  656. {
  657. return __sysret(sys_symlink(old, new));
  658. }
  659. /*
  660. * mode_t umask(mode_t mode);
  661. */
  662. static __attribute__((unused))
  663. mode_t sys_umask(mode_t mode)
  664. {
  665. return my_syscall1(__NR_umask, mode);
  666. }
  667. static __attribute__((unused))
  668. mode_t umask(mode_t mode)
  669. {
  670. return sys_umask(mode);
  671. }
  672. /*
  673. * int umount2(const char *path, int flags);
  674. */
  675. static __attribute__((unused))
  676. int sys_umount2(const char *path, int flags)
  677. {
  678. return my_syscall2(__NR_umount2, path, flags);
  679. }
  680. static __attribute__((unused))
  681. int umount2(const char *path, int flags)
  682. {
  683. return __sysret(sys_umount2(path, flags));
  684. }
  685. /*
  686. * int unlink(const char *path);
  687. */
  688. static __attribute__((unused))
  689. int sys_unlink(const char *path)
  690. {
  691. #if defined(__NR_unlinkat)
  692. return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0);
  693. #else
  694. return my_syscall1(__NR_unlink, path);
  695. #endif
  696. }
  697. static __attribute__((unused))
  698. int unlink(const char *path)
  699. {
  700. return __sysret(sys_unlink(path));
  701. }
  702. /*
  703. * ssize_t write(int fd, const void *buf, size_t count);
  704. */
  705. static __attribute__((unused))
  706. ssize_t sys_write(int fd, const void *buf, size_t count)
  707. {
  708. return my_syscall3(__NR_write, fd, buf, count);
  709. }
  710. static __attribute__((unused))
  711. ssize_t write(int fd, const void *buf, size_t count)
  712. {
  713. return __sysret(sys_write(fd, buf, count));
  714. }
  715. /*
  716. * int memfd_create(const char *name, unsigned int flags);
  717. */
  718. static __attribute__((unused))
  719. int sys_memfd_create(const char *name, unsigned int flags)
  720. {
  721. return my_syscall2(__NR_memfd_create, name, flags);
  722. }
  723. static __attribute__((unused))
  724. int memfd_create(const char *name, unsigned int flags)
  725. {
  726. return __sysret(sys_memfd_create(name, flags));
  727. }
  728. #endif /* _NOLIBC_SYS_H */