unistd.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/ScopedValueRollback.h>
  27. #include <AK/String.h>
  28. #include <AK/Vector.h>
  29. #include <Kernel/Syscall.h>
  30. #include <alloca.h>
  31. #include <assert.h>
  32. #include <errno.h>
  33. #include <fcntl.h>
  34. #include <grp.h>
  35. #include <pwd.h>
  36. #include <stdarg.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <sys/ioctl.h>
  41. #include <sys/mman.h>
  42. #include <sys/types.h>
  43. #include <termios.h>
  44. #include <unistd.h>
  45. extern "C" {
  46. static __thread int s_cached_tid = 0;
  47. int chown(const char* pathname, uid_t uid, gid_t gid)
  48. {
  49. if (!pathname) {
  50. errno = EFAULT;
  51. return -1;
  52. }
  53. Syscall::SC_chown_params params { { pathname, strlen(pathname) }, uid, gid };
  54. int rc = syscall(SC_chown, &params);
  55. __RETURN_WITH_ERRNO(rc, rc, -1);
  56. }
  57. int fchown(int fd, uid_t uid, gid_t gid)
  58. {
  59. int rc = syscall(SC_fchown, fd, uid, gid);
  60. __RETURN_WITH_ERRNO(rc, rc, -1);
  61. }
  62. pid_t fork()
  63. {
  64. int rc = syscall(SC_fork);
  65. if (rc == 0)
  66. s_cached_tid = 0;
  67. __RETURN_WITH_ERRNO(rc, rc, -1);
  68. }
  69. int execv(const char* path, char* const argv[])
  70. {
  71. return execve(path, argv, environ);
  72. }
  73. int execve(const char* filename, char* const argv[], char* const envp[])
  74. {
  75. size_t arg_count = 0;
  76. for (size_t i = 0; argv[i]; ++i)
  77. ++arg_count;
  78. size_t env_count = 0;
  79. for (size_t i = 0; envp[i]; ++i)
  80. ++env_count;
  81. auto copy_strings = [&](auto& vec, size_t count, auto& output) {
  82. output.length = count;
  83. for (size_t i = 0; vec[i]; ++i) {
  84. output.strings[i].characters = vec[i];
  85. output.strings[i].length = strlen(vec[i]);
  86. }
  87. };
  88. Syscall::SC_execve_params params;
  89. params.arguments.strings = (Syscall::StringArgument*)alloca(arg_count * sizeof(Syscall::StringArgument));
  90. params.environment.strings = (Syscall::StringArgument*)alloca(env_count * sizeof(Syscall::StringArgument));
  91. params.path = { filename, strlen(filename) };
  92. copy_strings(argv, arg_count, params.arguments);
  93. copy_strings(envp, env_count, params.environment);
  94. int rc = syscall(SC_execve, &params);
  95. __RETURN_WITH_ERRNO(rc, rc, -1);
  96. }
  97. int execvpe(const char* filename, char* const argv[], char* const envp[])
  98. {
  99. if (strchr(filename, '/'))
  100. return execve(filename, argv, envp);
  101. ScopedValueRollback errno_rollback(errno);
  102. String path = getenv("PATH");
  103. if (path.is_empty())
  104. path = "/bin:/usr/bin";
  105. auto parts = path.split(':');
  106. for (auto& part : parts) {
  107. auto candidate = String::format("%s/%s", part.characters(), filename);
  108. int rc = execve(candidate.characters(), argv, envp);
  109. if (rc < 0 && errno != ENOENT) {
  110. errno_rollback.set_override_rollback_value(errno);
  111. dbg() << "execvpe() failed on attempt (" << candidate << ") with " << strerror(errno);
  112. return rc;
  113. }
  114. }
  115. errno_rollback.set_override_rollback_value(ENOENT);
  116. dbg() << "execvpe() leaving :(";
  117. return -1;
  118. }
  119. int execvp(const char* filename, char* const argv[])
  120. {
  121. int rc = execvpe(filename, argv, environ);
  122. int saved_errno = errno;
  123. dbg() << "execvp() about to return " << rc << " with errno=" << saved_errno;
  124. errno = saved_errno;
  125. return rc;
  126. }
  127. int execl(const char* filename, const char* arg0, ...)
  128. {
  129. Vector<const char*, 16> args;
  130. args.append(arg0);
  131. va_list ap;
  132. va_start(ap, arg0);
  133. for (;;) {
  134. const char* arg = va_arg(ap, const char*);
  135. if (!arg)
  136. break;
  137. args.append(arg);
  138. }
  139. va_end(ap);
  140. args.append(nullptr);
  141. return execve(filename, const_cast<char* const*>(args.data()), environ);
  142. }
  143. int execlp(const char* filename, const char* arg0, ...)
  144. {
  145. Vector<const char*, 16> args;
  146. args.append(arg0);
  147. va_list ap;
  148. va_start(ap, arg0);
  149. for (;;) {
  150. const char* arg = va_arg(ap, const char*);
  151. if (!arg)
  152. break;
  153. args.append(arg);
  154. }
  155. va_end(ap);
  156. args.append(nullptr);
  157. return execvpe(filename, const_cast<char* const*>(args.data()), environ);
  158. }
  159. uid_t geteuid()
  160. {
  161. return syscall(SC_geteuid);
  162. }
  163. gid_t getegid()
  164. {
  165. return syscall(SC_getegid);
  166. }
  167. uid_t getuid()
  168. {
  169. return syscall(SC_getuid);
  170. }
  171. gid_t getgid()
  172. {
  173. return syscall(SC_getgid);
  174. }
  175. pid_t getpid()
  176. {
  177. return syscall(SC_getpid);
  178. }
  179. pid_t getppid()
  180. {
  181. return syscall(SC_getppid);
  182. }
  183. int getresuid(uid_t* ruid, uid_t* euid, uid_t* suid)
  184. {
  185. return syscall(SC_getresuid, ruid, euid, suid);
  186. }
  187. int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
  188. {
  189. return syscall(SC_getresgid, rgid, egid, sgid);
  190. }
  191. pid_t getsid(pid_t pid)
  192. {
  193. int rc = syscall(SC_getsid, pid);
  194. __RETURN_WITH_ERRNO(rc, rc, -1);
  195. }
  196. pid_t setsid()
  197. {
  198. int rc = syscall(SC_setsid);
  199. __RETURN_WITH_ERRNO(rc, rc, -1);
  200. }
  201. pid_t tcgetpgrp(int fd)
  202. {
  203. return ioctl(fd, TIOCGPGRP);
  204. }
  205. int tcsetpgrp(int fd, pid_t pgid)
  206. {
  207. return ioctl(fd, TIOCSPGRP, pgid);
  208. }
  209. int setpgid(pid_t pid, pid_t pgid)
  210. {
  211. int rc = syscall(SC_setpgid, pid, pgid);
  212. __RETURN_WITH_ERRNO(rc, rc, -1);
  213. }
  214. pid_t getpgid(pid_t pid)
  215. {
  216. int rc = syscall(SC_getpgid, pid);
  217. __RETURN_WITH_ERRNO(rc, rc, -1);
  218. }
  219. pid_t getpgrp()
  220. {
  221. int rc = syscall(SC_getpgrp);
  222. __RETURN_WITH_ERRNO(rc, rc, -1);
  223. }
  224. ssize_t read(int fd, void* buf, size_t count)
  225. {
  226. int rc = syscall(SC_read, fd, buf, count);
  227. __RETURN_WITH_ERRNO(rc, rc, -1);
  228. }
  229. ssize_t write(int fd, const void* buf, size_t count)
  230. {
  231. int rc = syscall(SC_write, fd, buf, count);
  232. __RETURN_WITH_ERRNO(rc, rc, -1);
  233. }
  234. int ttyname_r(int fd, char* buffer, size_t size)
  235. {
  236. int rc = syscall(SC_ttyname_r, fd, buffer, size);
  237. __RETURN_WITH_ERRNO(rc, rc, -1);
  238. }
  239. static char ttyname_buf[32];
  240. char* ttyname(int fd)
  241. {
  242. if (ttyname_r(fd, ttyname_buf, sizeof(ttyname_buf)) < 0)
  243. return nullptr;
  244. return ttyname_buf;
  245. }
  246. int close(int fd)
  247. {
  248. int rc = syscall(SC_close, fd);
  249. __RETURN_WITH_ERRNO(rc, rc, -1);
  250. }
  251. static int do_stat(const char* path, struct stat* statbuf, bool follow_symlinks)
  252. {
  253. if (!path) {
  254. errno = EFAULT;
  255. return -1;
  256. }
  257. Syscall::SC_stat_params params { { path, strlen(path) }, statbuf, follow_symlinks };
  258. int rc = syscall(SC_stat, &params);
  259. __RETURN_WITH_ERRNO(rc, rc, -1);
  260. }
  261. int lstat(const char* path, struct stat* statbuf)
  262. {
  263. return do_stat(path, statbuf, false);
  264. }
  265. int stat(const char* path, struct stat* statbuf)
  266. {
  267. return do_stat(path, statbuf, true);
  268. }
  269. int fstat(int fd, struct stat* statbuf)
  270. {
  271. int rc = syscall(SC_fstat, fd, statbuf);
  272. __RETURN_WITH_ERRNO(rc, rc, -1);
  273. }
  274. int chdir(const char* path)
  275. {
  276. if (!path) {
  277. errno = EFAULT;
  278. return -1;
  279. }
  280. int rc = syscall(SC_chdir, path, strlen(path));
  281. __RETURN_WITH_ERRNO(rc, rc, -1);
  282. }
  283. int fchdir(int fd)
  284. {
  285. int rc = syscall(SC_fchdir, fd);
  286. __RETURN_WITH_ERRNO(rc, rc, -1);
  287. }
  288. char* getcwd(char* buffer, size_t size)
  289. {
  290. if (!buffer) {
  291. size = size ? size : PATH_MAX;
  292. buffer = (char*)malloc(size);
  293. }
  294. int rc = syscall(SC_getcwd, buffer, size);
  295. __RETURN_WITH_ERRNO(rc, buffer, nullptr);
  296. }
  297. char* getwd(char* buf)
  298. {
  299. auto* p = getcwd(buf, PATH_MAX);
  300. return p;
  301. }
  302. int sleep(unsigned seconds)
  303. {
  304. return syscall(SC_sleep, seconds);
  305. }
  306. int usleep(useconds_t usec)
  307. {
  308. return syscall(SC_usleep, usec);
  309. }
  310. int gethostname(char* buffer, size_t size)
  311. {
  312. int rc = syscall(SC_gethostname, buffer, size);
  313. __RETURN_WITH_ERRNO(rc, rc, -1);
  314. }
  315. int sethostname(const char* hostname, ssize_t size)
  316. {
  317. int rc = syscall(SC_sethostname, hostname, size);
  318. __RETURN_WITH_ERRNO(rc, rc, -1);
  319. }
  320. ssize_t readlink(const char* path, char* buffer, size_t size)
  321. {
  322. Syscall::SC_readlink_params params { { path, strlen(path) }, { buffer, size } };
  323. int rc = syscall(SC_readlink, &params);
  324. // Return the number of bytes placed in the buffer, not the full path size.
  325. __RETURN_WITH_ERRNO(rc, min((size_t)rc, size), -1);
  326. }
  327. off_t lseek(int fd, off_t offset, int whence)
  328. {
  329. int rc = syscall(SC_lseek, fd, offset, whence);
  330. __RETURN_WITH_ERRNO(rc, rc, -1);
  331. }
  332. int link(const char* old_path, const char* new_path)
  333. {
  334. if (!old_path || !new_path) {
  335. errno = EFAULT;
  336. return -1;
  337. }
  338. Syscall::SC_link_params params { { old_path, strlen(old_path) }, { new_path, strlen(new_path) } };
  339. int rc = syscall(SC_link, &params);
  340. __RETURN_WITH_ERRNO(rc, rc, -1);
  341. }
  342. int unlink(const char* pathname)
  343. {
  344. int rc = syscall(SC_unlink, pathname, strlen(pathname));
  345. __RETURN_WITH_ERRNO(rc, rc, -1);
  346. }
  347. int symlink(const char* target, const char* linkpath)
  348. {
  349. if (!target || !linkpath) {
  350. errno = EFAULT;
  351. return -1;
  352. }
  353. Syscall::SC_symlink_params params { { target, strlen(target) }, { linkpath, strlen(linkpath) } };
  354. int rc = syscall(SC_symlink, &params);
  355. __RETURN_WITH_ERRNO(rc, rc, -1);
  356. }
  357. int rmdir(const char* pathname)
  358. {
  359. if (!pathname) {
  360. errno = EFAULT;
  361. return -1;
  362. }
  363. int rc = syscall(SC_rmdir, pathname, strlen(pathname));
  364. __RETURN_WITH_ERRNO(rc, rc, -1);
  365. }
  366. int isatty(int fd)
  367. {
  368. return fcntl(fd, F_ISTTY);
  369. }
  370. int dup(int old_fd)
  371. {
  372. int rc = syscall(SC_dup, old_fd);
  373. __RETURN_WITH_ERRNO(rc, rc, -1);
  374. }
  375. int dup2(int old_fd, int new_fd)
  376. {
  377. int rc = syscall(SC_dup2, old_fd, new_fd);
  378. __RETURN_WITH_ERRNO(rc, rc, -1);
  379. }
  380. int setgroups(size_t size, const gid_t* list)
  381. {
  382. int rc = syscall(SC_setgroups, size, list);
  383. __RETURN_WITH_ERRNO(rc, rc, -1);
  384. }
  385. int getgroups(int size, gid_t list[])
  386. {
  387. int rc = syscall(SC_getgroups, size, list);
  388. __RETURN_WITH_ERRNO(rc, rc, -1);
  389. }
  390. int pipe(int pipefd[2])
  391. {
  392. return pipe2(pipefd, 0);
  393. }
  394. int pipe2(int pipefd[2], int flags)
  395. {
  396. int rc = syscall(SC_pipe, pipefd, flags);
  397. __RETURN_WITH_ERRNO(rc, rc, -1);
  398. }
  399. unsigned int alarm(unsigned int seconds)
  400. {
  401. return syscall(SC_alarm, seconds);
  402. }
  403. int seteuid(uid_t euid)
  404. {
  405. int rc = syscall(SC_seteuid, euid);
  406. __RETURN_WITH_ERRNO(rc, rc, -1);
  407. }
  408. int setegid(gid_t egid)
  409. {
  410. int rc = syscall(SC_setegid, egid);
  411. __RETURN_WITH_ERRNO(rc, rc, -1);
  412. }
  413. int setuid(uid_t uid)
  414. {
  415. int rc = syscall(SC_setuid, uid);
  416. __RETURN_WITH_ERRNO(rc, rc, -1);
  417. }
  418. int setgid(gid_t gid)
  419. {
  420. int rc = syscall(SC_setgid, gid);
  421. __RETURN_WITH_ERRNO(rc, rc, -1);
  422. }
  423. int setresuid(uid_t ruid, uid_t euid, uid_t suid)
  424. {
  425. int rc = syscall(SC_setresuid, ruid, euid, suid);
  426. __RETURN_WITH_ERRNO(rc, rc, -1);
  427. }
  428. int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
  429. {
  430. int rc = syscall(SC_setresgid, rgid, egid, sgid);
  431. __RETURN_WITH_ERRNO(rc, rc, -1);
  432. }
  433. int access(const char* pathname, int mode)
  434. {
  435. if (!pathname) {
  436. errno = EFAULT;
  437. return -1;
  438. }
  439. int rc = syscall(SC_access, pathname, strlen(pathname), mode);
  440. __RETURN_WITH_ERRNO(rc, rc, -1);
  441. }
  442. int mknod(const char* pathname, mode_t mode, dev_t dev)
  443. {
  444. if (!pathname) {
  445. errno = EFAULT;
  446. return -1;
  447. }
  448. Syscall::SC_mknod_params params { { pathname, strlen(pathname) }, mode, dev };
  449. int rc = syscall(SC_mknod, &params);
  450. __RETURN_WITH_ERRNO(rc, rc, -1);
  451. }
  452. long fpathconf(int fd, int name)
  453. {
  454. (void)fd;
  455. (void)name;
  456. switch (name) {
  457. case _PC_PATH_MAX:
  458. return PATH_MAX;
  459. case _PC_VDISABLE:
  460. return _POSIX_VDISABLE;
  461. }
  462. ASSERT_NOT_REACHED();
  463. }
  464. long pathconf(const char* path, int name)
  465. {
  466. (void)path;
  467. switch (name) {
  468. case _PC_PATH_MAX:
  469. return PATH_MAX;
  470. case _PC_PIPE_BUF:
  471. return PIPE_BUF;
  472. }
  473. ASSERT_NOT_REACHED();
  474. }
  475. void _exit(int status)
  476. {
  477. syscall(SC_exit, status);
  478. ASSERT_NOT_REACHED();
  479. }
  480. void sync()
  481. {
  482. syscall(SC_sync);
  483. }
  484. int set_process_icon(int icon_id)
  485. {
  486. int rc = syscall(SC_set_process_icon, icon_id);
  487. __RETURN_WITH_ERRNO(rc, rc, -1);
  488. }
  489. char* getlogin()
  490. {
  491. static char __getlogin_buffer[256];
  492. if (auto* passwd = getpwuid(getuid())) {
  493. strncpy(__getlogin_buffer, passwd->pw_name, sizeof(__getlogin_buffer) - 1);
  494. endpwent();
  495. return __getlogin_buffer;
  496. }
  497. endpwent();
  498. return nullptr;
  499. }
  500. int ftruncate(int fd, off_t length)
  501. {
  502. int rc = syscall(SC_ftruncate, fd, length);
  503. __RETURN_WITH_ERRNO(rc, rc, -1);
  504. }
  505. int truncate(const char* path, off_t length)
  506. {
  507. int fd = open(path, O_RDWR | O_CREAT, 0666);
  508. if (fd < 0)
  509. return fd;
  510. int rc = ftruncate(fd, length);
  511. int saved_errno = errno;
  512. if (int close_rc = close(fd); close_rc < 0)
  513. return close_rc;
  514. errno = saved_errno;
  515. return rc;
  516. }
  517. int gettid()
  518. {
  519. if (!s_cached_tid)
  520. s_cached_tid = syscall(SC_gettid);
  521. return s_cached_tid;
  522. }
  523. int donate(int tid)
  524. {
  525. int rc = syscall(SC_donate, tid);
  526. __RETURN_WITH_ERRNO(rc, rc, -1);
  527. }
  528. void sysbeep()
  529. {
  530. syscall(SC_beep);
  531. }
  532. int fsync(int fd)
  533. {
  534. UNUSED_PARAM(fd);
  535. dbgprintf("FIXME: Implement fsync()\n");
  536. return 0;
  537. }
  538. int halt()
  539. {
  540. int rc = syscall(SC_halt);
  541. __RETURN_WITH_ERRNO(rc, rc, -1);
  542. }
  543. int reboot()
  544. {
  545. int rc = syscall(SC_reboot);
  546. __RETURN_WITH_ERRNO(rc, rc, -1);
  547. }
  548. int mount(int source_fd, const char* target, const char* fs_type, int flags)
  549. {
  550. if (!target || !fs_type) {
  551. errno = EFAULT;
  552. return -1;
  553. }
  554. Syscall::SC_mount_params params {
  555. source_fd,
  556. { target, strlen(target) },
  557. { fs_type, strlen(fs_type) },
  558. flags
  559. };
  560. int rc = syscall(SC_mount, &params);
  561. __RETURN_WITH_ERRNO(rc, rc, -1);
  562. }
  563. int umount(const char* mountpoint)
  564. {
  565. int rc = syscall(SC_umount, mountpoint, strlen(mountpoint));
  566. __RETURN_WITH_ERRNO(rc, rc, -1);
  567. }
  568. void dump_backtrace()
  569. {
  570. syscall(SC_dump_backtrace);
  571. }
  572. int get_process_name(char* buffer, int buffer_size)
  573. {
  574. int rc = syscall(SC_get_process_name, buffer, buffer_size);
  575. __RETURN_WITH_ERRNO(rc, rc, -1);
  576. }
  577. int chroot(const char* path)
  578. {
  579. return chroot_with_mount_flags(path, -1);
  580. }
  581. int chroot_with_mount_flags(const char* path, int mount_flags)
  582. {
  583. if (!path) {
  584. errno = EFAULT;
  585. return -1;
  586. }
  587. int rc = syscall(SC_chroot, path, strlen(path), mount_flags);
  588. __RETURN_WITH_ERRNO(rc, rc, -1);
  589. }
  590. int pledge(const char* promises, const char* execpromises)
  591. {
  592. Syscall::SC_pledge_params params {
  593. { promises, promises ? strlen(promises) : 0 },
  594. { execpromises, execpromises ? strlen(execpromises) : 0 }
  595. };
  596. int rc = syscall(SC_pledge, &params);
  597. __RETURN_WITH_ERRNO(rc, rc, -1);
  598. }
  599. int unveil(const char* path, const char* permissions)
  600. {
  601. Syscall::SC_unveil_params params {
  602. { path, path ? strlen(path) : 0 },
  603. { permissions, permissions ? strlen(permissions) : 0 }
  604. };
  605. int rc = syscall(SC_unveil, &params);
  606. __RETURN_WITH_ERRNO(rc, rc, -1);
  607. }
  608. ssize_t pread(int fd, void* buf, size_t count, off_t offset)
  609. {
  610. // FIXME: This is not thread safe and should be implemented in the kernel instead.
  611. off_t old_offset = lseek(fd, 0, SEEK_CUR);
  612. lseek(fd, offset, SEEK_SET);
  613. ssize_t nread = read(fd, buf, count);
  614. lseek(fd, old_offset, SEEK_SET);
  615. return nread;
  616. }
  617. char* getpass(const char* prompt)
  618. {
  619. dbg() << "FIXME: getpass(\"" << prompt << "\")";
  620. ASSERT_NOT_REACHED();
  621. }
  622. }