1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 19:15:07 +00:00
serenity/Userland/Libraries/LibSystem/Wrappers.cpp
Andreas Kling 4e530135d5 AK+LibSystem+LibMain: Add Error::from_syscall() for syscall failures
This creates an error that contains the name of the syscall that failed.
This allows error handlers to print out the name of the call if they
want to. :^)
2021-11-22 19:28:31 +01:00

38 lines
1.1 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibSystem/Wrappers.h>
#include <LibSystem/syscall.h>
#define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc) \
if ((rc) < 0) { \
return Error::from_syscall(syscall_name, rc); \
} \
return {};
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);
HANDLE_SYSCALL_RETURN_VALUE("pledge"sv, rc);
}
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);
HANDLE_SYSCALL_RETURN_VALUE("unveil"sv, rc);
}
}