summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-22 15:43:57 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-22 18:34:08 +0100
commitdc486fa3f90d7922c1a24e6f2e990dd35a76da26 (patch)
treeb83689f194f9da62622b1be9008754ae127c41e8
parent0d679bf34892b8e4577798d7e877af40f3cea0e8 (diff)
downloadserenity-dc486fa3f90d7922c1a24e6f2e990dd35a76da26.zip
LibSystem: Add pledge() and unveil() wrappers that return ErrorOr<void>
These will be more ergonomic to use together with TRY(). :^)
-rw-r--r--Userland/Libraries/LibSystem/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibSystem/Wrappers.cpp36
-rw-r--r--Userland/Libraries/LibSystem/Wrappers.h16
3 files changed, 53 insertions, 0 deletions
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 <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibSystem/Wrappers.h>
+#include <LibSystem/syscall.h>
+
+namespace System {
+
+ErrorOr<void> 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, &params);
+ if (rc < 0)
+ return Error::from_errno(-rc);
+ return {};
+}
+
+ErrorOr<void> 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, &params);
+ 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 <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Error.h>
+
+namespace System {
+
+ErrorOr<void> pledge(StringView promises, StringView execpromises);
+ErrorOr<void> unveil(StringView path, StringView permissions);
+
+}