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
commit cf271183b4
Notes: sideshowbarker 2024-07-18 05:28:05 +09:00
26 changed files with 142 additions and 141 deletions

View file

@ -43,9 +43,9 @@ void TTY::set_default_termios()
KResultOr<size_t> TTY::read(FileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
if (Process::current()->pgid() != pgid()) {
if (Process::current().pgid() != pgid()) {
// FIXME: Should we propagate this error path somehow?
[[maybe_unused]] auto rc = Process::current()->send_signal(SIGTTIN, nullptr);
[[maybe_unused]] auto rc = Process::current().send_signal(SIGTTIN, nullptr);
return EINTR;
}
if (m_input_buffer.size() < static_cast<size_t>(size))
@ -82,8 +82,8 @@ KResultOr<size_t> TTY::read(FileDescription&, u64, UserOrKernelBuffer& buffer, s
KResultOr<size_t> TTY::write(FileDescription&, u64, const UserOrKernelBuffer& buffer, size_t size)
{
if (m_termios.c_lflag & TOSTOP && Process::current()->pgid() != pgid()) {
[[maybe_unused]] auto rc = Process::current()->send_signal(SIGTTOU, nullptr);
if (m_termios.c_lflag & TOSTOP && Process::current().pgid() != pgid()) {
[[maybe_unused]] auto rc = Process::current().send_signal(SIGTTOU, nullptr);
return EINTR;
}
@ -457,7 +457,7 @@ KResult TTY::set_termios(const termios& t)
KResult TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg)
{
REQUIRE_PROMISE(tty);
auto& current_process = *Process::current();
auto& current_process = Process::current();
Userspace<termios*> user_termios;
Userspace<winsize*> user_winsize;