diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-04 22:26:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-04 23:11:04 +0200 |
commit | ba1a6ca971fcdd8ff145af995d2cbb963ec3f3c3 (patch) | |
tree | b5f19ba40eb3c9ca08b1a8dd84d9c94c342411c4 /Kernel/Process.cpp | |
parent | 5d5a3708c459afb2a5de1cafc5afa3c6e5b6fee7 (diff) | |
download | serenity-ba1a6ca971fcdd8ff145af995d2cbb963ec3f3c3.zip |
Kernel: Move pledge verification into Process member functions
REQUIRE_PROMISE and REQUIRE_NO_PROMISES were macros for some reason,
and used all over the place.
This patch adds require_promise(Pledge) and require_no_promises()
to Process and makes the macros call these on the current process
instead of inlining code everywhere.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r-- | Kernel/Process.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 8ce170aa7e..37d400b9d9 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -893,4 +893,38 @@ KResult Process::try_set_coredump_property(StringView key, StringView value) return ENOMEM; }; +static constexpr StringView to_string(Pledge promise) +{ +#define __ENUMERATE_PLEDGE_PROMISE(x) \ + case Pledge::x: \ + return #x; + switch (promise) { + ENUMERATE_PLEDGE_PROMISES + } +#undef __ENUMERATE_PLEDGE_PROMISE + VERIFY_NOT_REACHED(); +} + +void Process::require_no_promises() +{ + if (!has_promises()) + return; + dbgln("Has made a promise"); + Process::current().crash(SIGABRT, 0); + VERIFY_NOT_REACHED(); +} + +void Process::require_promise(Pledge promise) +{ + if (!has_promises()) + return; + + if (has_promised(promise)) + return; + + dbgln("Has not pledged {}", to_string(promise)); + (void)try_set_coredump_property("pledge_violation"sv, to_string(promise)); + crash(SIGABRT, 0); +} + } |