mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
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.
This commit is contained in:
parent
5d5a3708c4
commit
ba1a6ca971
2 changed files with 44 additions and 17 deletions
|
@ -893,4 +893,38 @@ KResult Process::try_set_coredump_property(StringView key, StringView value)
|
||||||
return ENOMEM;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,6 +509,9 @@ public:
|
||||||
|
|
||||||
VirtualAddress signal_trampoline() const { return m_protected_values.signal_trampoline; }
|
VirtualAddress signal_trampoline() const { return m_protected_values.signal_trampoline; }
|
||||||
|
|
||||||
|
void require_promise(Pledge);
|
||||||
|
void require_no_promises();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class MemoryManager;
|
friend class MemoryManager;
|
||||||
friend class Scheduler;
|
friend class Scheduler;
|
||||||
|
@ -955,26 +958,16 @@ inline ProcessID Thread::pid() const
|
||||||
return m_process->pid();
|
return m_process->pid();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REQUIRE_NO_PROMISES \
|
#define REQUIRE_PROMISE(promise) \
|
||||||
do { \
|
do { \
|
||||||
if (Process::current().has_promises()) { \
|
Process::current().require_promise(Pledge::promise); \
|
||||||
dbgln("Has made a promise"); \
|
|
||||||
Process::current().crash(SIGABRT, 0); \
|
|
||||||
VERIFY_NOT_REACHED(); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define REQUIRE_PROMISE(promise) \
|
#define REQUIRE_NO_PROMISES \
|
||||||
do { \
|
do { \
|
||||||
if (Process::current().has_promises() \
|
Process::current().require_no_promises(); \
|
||||||
&& !Process::current().has_promised(Pledge::promise)) { \
|
|
||||||
dbgln("Has not pledged {}", #promise); \
|
|
||||||
(void)Process::current().try_set_coredump_property( \
|
|
||||||
"pledge_violation"sv, #promise); \
|
|
||||||
Process::current().crash(SIGABRT, 0); \
|
|
||||||
VERIFY_NOT_REACHED(); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define VERIFY_PROCESS_BIG_LOCK_ACQUIRED(process) \
|
#define VERIFY_PROCESS_BIG_LOCK_ACQUIRED(process) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue