diff --git a/Userland/Libraries/LibSystem/CMakeLists.txt b/Userland/Libraries/LibSystem/CMakeLists.txt index 61ffa0622f..c45501ad18 100644 --- a/Userland/Libraries/LibSystem/CMakeLists.txt +++ b/Userland/Libraries/LibSystem/CMakeLists.txt @@ -1,4 +1,5 @@ set(SOURCES + Wrappers.cpp syscall.cpp ) diff --git a/Userland/Libraries/LibSystem/Wrappers.cpp b/Userland/Libraries/LibSystem/Wrappers.cpp new file mode 100644 index 0000000000..7045d7c786 --- /dev/null +++ b/Userland/Libraries/LibSystem/Wrappers.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace System { + +ErrorOr pledge(StringView promises, StringView execpromises) +{ + Syscall::SC_pledge_params params { + { promises.characters_without_null_termination(), promises.length() }, + { execpromises.characters_without_null_termination(), execpromises.length() }, + }; + int rc = syscall(SC_pledge, ¶ms); + if (rc < 0) + return Error::from_errno(-rc); + return {}; +} + +ErrorOr unveil(StringView path, StringView permissions) +{ + Syscall::SC_unveil_params params { + { path.characters_without_null_termination(), path.length() }, + { permissions.characters_without_null_termination(), permissions.length() }, + }; + int rc = syscall(SC_unveil, ¶ms); + if (rc < 0) + return Error::from_errno(-rc); + return {}; +} + +} diff --git a/Userland/Libraries/LibSystem/Wrappers.h b/Userland/Libraries/LibSystem/Wrappers.h new file mode 100644 index 0000000000..bc32d10681 --- /dev/null +++ b/Userland/Libraries/LibSystem/Wrappers.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace System { + +ErrorOr pledge(StringView promises, StringView execpromises); +ErrorOr unveil(StringView path, StringView permissions); + +}