1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 06:38:10 +00:00

Kernel: Make Process::current() return a Process& instead of Process*

This has several benefits:
1) We no longer just blindly derefence a null pointer in various places
2) We will get nicer runtime error messages if the current process does
turn out to be null in the call location
3) GCC no longer complains about possible nullptr dereferences when
compiling without KUBSAN
This commit is contained in:
Idan Horowitz 2021-08-19 22:45:07 +03:00 committed by Andreas Kling
parent 1259dc3623
commit cf271183b4
26 changed files with 142 additions and 141 deletions

View file

@ -145,10 +145,16 @@ public:
public:
class ProcessProcFSTraits;
inline static Process* current()
inline static Process& current()
{
auto current_thread = Processor::current_thread();
return current_thread ? &current_thread->process() : nullptr;
VERIFY(current_thread);
return current_thread->process();
}
inline static bool has_current()
{
return Processor::current_thread();
}
template<typename EntryFunction>
@ -948,25 +954,25 @@ inline ProcessID Thread::pid() const
return m_process->pid();
}
#define REQUIRE_NO_PROMISES \
do { \
if (Process::current()->has_promises()) { \
dbgln("Has made a promise"); \
Process::current()->crash(SIGABRT, 0); \
VERIFY_NOT_REACHED(); \
} \
#define REQUIRE_NO_PROMISES \
do { \
if (Process::current().has_promises()) { \
dbgln("Has made a promise"); \
Process::current().crash(SIGABRT, 0); \
VERIFY_NOT_REACHED(); \
} \
} while (0)
#define REQUIRE_PROMISE(promise) \
do { \
if (Process::current()->has_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(); \
} \
#define REQUIRE_PROMISE(promise) \
do { \
if (Process::current().has_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)
}