From dc486fa3f90d7922c1a24e6f2e990dd35a76da26 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 22 Nov 2021 15:43:57 +0100 Subject: LibSystem: Add pledge() and unveil() wrappers that return ErrorOr These will be more ergonomic to use together with TRY(). :^) --- Userland/Libraries/LibSystem/CMakeLists.txt | 1 + Userland/Libraries/LibSystem/Wrappers.cpp | 36 +++++++++++++++++++++++++++++ Userland/Libraries/LibSystem/Wrappers.h | 16 +++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 Userland/Libraries/LibSystem/Wrappers.cpp create mode 100644 Userland/Libraries/LibSystem/Wrappers.h 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); + +} -- cgit v1.2.3