System.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Kenneth Myhra <kennethmyhra@gmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Error.h>
  9. #include <grp.h>
  10. #include <pwd.h>
  11. #include <signal.h>
  12. #include <spawn.h>
  13. #include <sys/stat.h>
  14. #include <sys/wait.h>
  15. #include <termios.h>
  16. #include <time.h>
  17. namespace Core::System {
  18. #ifdef __serenity__
  19. ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
  20. ErrorOr<void> unveil(StringView path, StringView permissions);
  21. ErrorOr<Array<int, 2>> pipe2(int flags);
  22. ErrorOr<void> sendfd(int sockfd, int fd);
  23. ErrorOr<int> recvfd(int sockfd, int options);
  24. ErrorOr<void> ptrace_peekbuf(pid_t tid, void const* tracee_addr, Bytes destination_buf);
  25. ErrorOr<void> setgroups(Span<gid_t const>);
  26. ErrorOr<void> mount(int source_fd, StringView target, StringView fs_type, int flags);
  27. #endif
  28. ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
  29. ErrorOr<struct stat> fstat(int fd);
  30. ErrorOr<int> fcntl(int fd, int command, ...);
  31. ErrorOr<void*> mmap(void* address, size_t, int protection, int flags, int fd, off_t, size_t alignment = 0, StringView name = {});
  32. ErrorOr<void> munmap(void* address, size_t);
  33. ErrorOr<int> open(StringView path, int options, ...);
  34. ErrorOr<void> close(int fd);
  35. ErrorOr<void> ftruncate(int fd, off_t length);
  36. ErrorOr<struct stat> stat(StringView path);
  37. ErrorOr<struct stat> lstat(StringView path);
  38. ErrorOr<ssize_t> read(int fd, Bytes buffer);
  39. ErrorOr<ssize_t> write(int fd, ReadonlyBytes buffer);
  40. ErrorOr<void> kill(pid_t, int signal);
  41. ErrorOr<int> dup(int source_fd);
  42. ErrorOr<int> dup2(int source_fd, int destination_fd);
  43. ErrorOr<String> ptsname(int fd);
  44. ErrorOr<String> gethostname();
  45. ErrorOr<void> ioctl(int fd, unsigned request, ...);
  46. ErrorOr<struct termios> tcgetattr(int fd);
  47. ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const&);
  48. ErrorOr<void> chmod(StringView pathname, mode_t mode);
  49. ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid);
  50. ErrorOr<struct passwd> getpwnam(StringView name);
  51. ErrorOr<struct group> getgrnam(StringView name);
  52. ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts);
  53. ErrorOr<pid_t> posix_spawnp(StringView const path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]);
  54. ErrorOr<pid_t> waitpid(pid_t waitee, int* wstatus, int options);
  55. ErrorOr<void> setuid(uid_t);
  56. ErrorOr<void> seteuid(uid_t);
  57. ErrorOr<void> setgid(gid_t);
  58. ErrorOr<void> setegid(gid_t);
  59. ErrorOr<bool> isatty(int fd);
  60. ErrorOr<void> symlink(StringView target, StringView link_path);
  61. ErrorOr<void> mkdir(StringView path, mode_t);
  62. ErrorOr<pid_t> fork();
  63. ErrorOr<int> mkstemp(Span<char> pattern);
  64. ErrorOr<void> fchmod(int fd, mode_t mode);
  65. ErrorOr<void> rename(StringView old_path, StringView new_path);
  66. }