1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:57:35 +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

@ -11,7 +11,7 @@ namespace Kernel {
AsyncDeviceRequest::AsyncDeviceRequest(Device& device)
: m_device(device)
, m_process(*Process::current())
, m_process(Process::current())
{
}

View file

@ -129,7 +129,7 @@ private:
{
if (buffer.is_kernel_buffer())
return true;
return m_process == Process::current();
return m_process == &Process::current();
}
[[nodiscard]] static bool is_completed_result(RequestResult result)

View file

@ -48,8 +48,7 @@ void KCOVDevice::free_thread()
void KCOVDevice::free_process()
{
auto process = Process::current();
auto pid = process->pid();
auto pid = Process::current().pid();
auto maybe_kcov_instance = proc_instance->get(pid);
if (!maybe_kcov_instance.has_value())
@ -64,8 +63,7 @@ void KCOVDevice::free_process()
KResultOr<NonnullRefPtr<FileDescription>> KCOVDevice::open(int options)
{
auto process = Process::current();
auto pid = process->pid();
auto pid = Process::current().pid();
if (proc_instance->get(pid).has_value())
return EBUSY; // This process already open()ed the kcov device
auto kcov_instance = new KCOVInstance(pid);