Wrappers.cpp 975 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibSystem/Wrappers.h>
  7. #include <LibSystem/syscall.h>
  8. namespace System {
  9. ErrorOr<void> pledge(StringView promises, StringView execpromises)
  10. {
  11. Syscall::SC_pledge_params params {
  12. { promises.characters_without_null_termination(), promises.length() },
  13. { execpromises.characters_without_null_termination(), execpromises.length() },
  14. };
  15. int rc = syscall(SC_pledge, &params);
  16. if (rc < 0)
  17. return Error::from_errno(-rc);
  18. return {};
  19. }
  20. ErrorOr<void> unveil(StringView path, StringView permissions)
  21. {
  22. Syscall::SC_unveil_params params {
  23. { path.characters_without_null_termination(), path.length() },
  24. { permissions.characters_without_null_termination(), permissions.length() },
  25. };
  26. int rc = syscall(SC_unveil, &params);
  27. if (rc < 0)
  28. return Error::from_errno(-rc);
  29. return {};
  30. }
  31. }