diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-08-19 22:45:07 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-19 23:49:53 +0200 |
commit | cf271183b4befeba7c96bd6ca25246b899e836bb (patch) | |
tree | 0361e7378750c2c4e45e5e01e273d6fe416555af /Kernel/Devices | |
parent | 1259dc362376e8011d20d4d9e2fcc49d5b7f9dc9 (diff) | |
download | serenity-cf271183b4befeba7c96bd6ca25246b899e836bb.zip |
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
Diffstat (limited to 'Kernel/Devices')
-rw-r--r-- | Kernel/Devices/AsyncDeviceRequest.cpp | 2 | ||||
-rw-r--r-- | Kernel/Devices/AsyncDeviceRequest.h | 2 | ||||
-rw-r--r-- | Kernel/Devices/KCOVDevice.cpp | 6 |
3 files changed, 4 insertions, 6 deletions
diff --git a/Kernel/Devices/AsyncDeviceRequest.cpp b/Kernel/Devices/AsyncDeviceRequest.cpp index 9df77452d3..a18a93bebd 100644 --- a/Kernel/Devices/AsyncDeviceRequest.cpp +++ b/Kernel/Devices/AsyncDeviceRequest.cpp @@ -11,7 +11,7 @@ namespace Kernel { AsyncDeviceRequest::AsyncDeviceRequest(Device& device) : m_device(device) - , m_process(*Process::current()) + , m_process(Process::current()) { } diff --git a/Kernel/Devices/AsyncDeviceRequest.h b/Kernel/Devices/AsyncDeviceRequest.h index d5914fdfd7..48ca3a5b26 100644 --- a/Kernel/Devices/AsyncDeviceRequest.h +++ b/Kernel/Devices/AsyncDeviceRequest.h @@ -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) diff --git a/Kernel/Devices/KCOVDevice.cpp b/Kernel/Devices/KCOVDevice.cpp index c1dd8b2fb0..4a2fc5243d 100644 --- a/Kernel/Devices/KCOVDevice.cpp +++ b/Kernel/Devices/KCOVDevice.cpp @@ -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); |