mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:38:12 +00:00
LibSystem: Add pledge() and unveil() wrappers that return ErrorOr<void>
These will be more ergonomic to use together with TRY(). :^)
This commit is contained in:
parent
0d679bf348
commit
dc486fa3f9
3 changed files with 53 additions and 0 deletions
36
Userland/Libraries/LibSystem/Wrappers.cpp
Normal file
36
Userland/Libraries/LibSystem/Wrappers.cpp
Normal file
|
@ -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, ¶ms);
|
||||
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, ¶ms);
|
||||
if (rc < 0)
|
||||
return Error::from_errno(-rc);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue