summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Arch/x86/common/CPU.cpp5
-rw-r--r--Kernel/Arch/x86/common/Interrupts.cpp10
-rw-r--r--Kernel/Arch/x86/common/Processor.cpp2
-rw-r--r--Kernel/Devices/AsyncDeviceRequest.cpp2
-rw-r--r--Kernel/Devices/AsyncDeviceRequest.h2
-rw-r--r--Kernel/Devices/KCOVDevice.cpp6
-rw-r--r--Kernel/FileSystem/FIFO.cpp2
-rw-r--r--Kernel/FileSystem/InodeFile.cpp2
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp102
-rw-r--r--Kernel/GlobalProcessExposed.cpp8
-rw-r--r--Kernel/Memory/AddressSpace.cpp6
-rw-r--r--Kernel/Memory/Region.cpp2
-rw-r--r--Kernel/Net/IPv4Socket.cpp14
-rw-r--r--Kernel/Net/LocalSocket.cpp16
-rw-r--r--Kernel/Net/Socket.cpp4
-rw-r--r--Kernel/Process.cpp4
-rw-r--r--Kernel/Process.h44
-rw-r--r--Kernel/ProcessSpecificExposed.cpp4
-rw-r--r--Kernel/Syscalls/fcntl.cpp2
-rw-r--r--Kernel/Syscalls/ptrace.cpp2
-rw-r--r--Kernel/Syscalls/thread.cpp6
-rw-r--r--Kernel/TTY/MasterPTY.cpp6
-rw-r--r--Kernel/TTY/SlavePTY.cpp6
-rw-r--r--Kernel/TTY/TTY.cpp10
-rw-r--r--Kernel/ThreadBlockers.cpp8
-rw-r--r--Kernel/init.cpp8
26 files changed, 142 insertions, 141 deletions
diff --git a/Kernel/Arch/x86/common/CPU.cpp b/Kernel/Arch/x86/common/CPU.cpp
index a5685896c2..4d67fb13c1 100644
--- a/Kernel/Arch/x86/common/CPU.cpp
+++ b/Kernel/Arch/x86/common/CPU.cpp
@@ -22,9 +22,8 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const
{
// Switch back to the current process's page tables if there are any.
// Otherwise stack walking will be a disaster.
- auto process = Process::current();
- if (process)
- MM.enter_process_paging_scope(*process);
+ if (Process::has_current())
+ MM.enter_process_paging_scope(Process::current());
PANIC("Aborted");
}
diff --git a/Kernel/Arch/x86/common/Interrupts.cpp b/Kernel/Arch/x86/common/Interrupts.cpp
index 26abf88c4f..5f26402bfe 100644
--- a/Kernel/Arch/x86/common/Interrupts.cpp
+++ b/Kernel/Arch/x86/common/Interrupts.cpp
@@ -214,14 +214,14 @@ static void dump(const RegisterState& regs)
void handle_crash(RegisterState const& regs, char const* description, int signal, bool out_of_memory)
{
- auto process = Process::current();
- if (!process) {
+ if (!Process::has_current())
PANIC("{} with !current", description);
- }
+
+ auto& process = Process::current();
// If a process crashed while inspecting another process,
// make sure we switch back to the right page tables.
- MM.enter_process_paging_scope(*process);
+ MM.enter_process_paging_scope(process);
dmesgln("CRASH: CPU #{} {} in ring {}", Processor::id(), description, (regs.cs & 3));
dump(regs);
@@ -230,7 +230,7 @@ void handle_crash(RegisterState const& regs, char const* description, int signal
PANIC("Crash in ring 0");
}
- process->crash(signal, regs.ip(), out_of_memory);
+ process.crash(signal, regs.ip(), out_of_memory);
}
EH_ENTRY_NO_CODE(6, illegal_instruction);
diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp
index 8cc84f2314..ce6b89fe79 100644
--- a/Kernel/Arch/x86/common/Processor.cpp
+++ b/Kernel/Arch/x86/common/Processor.cpp
@@ -685,7 +685,7 @@ void Processor::flush_tlb_local(VirtualAddress vaddr, size_t page_count)
void Processor::flush_tlb(Memory::PageDirectory const* page_directory, VirtualAddress vaddr, size_t page_count)
{
- if (s_smp_enabled && (!Memory::is_user_address(vaddr) || Process::current()->thread_count() > 1))
+ if (s_smp_enabled && (!Memory::is_user_address(vaddr) || Process::current().thread_count() > 1))
smp_broadcast_flush_tlb(page_directory, vaddr, page_count);
else
flush_tlb_local(vaddr, page_count);
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);
diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp
index 4c349c6b79..be6d236d09 100644
--- a/Kernel/FileSystem/FIFO.cpp
+++ b/Kernel/FileSystem/FIFO.cpp
@@ -129,7 +129,7 @@ KResultOr<size_t> FIFO::read(FileDescription& fd, u64, UserOrKernelBuffer& buffe
KResultOr<size_t> FIFO::write(FileDescription& fd, u64, const UserOrKernelBuffer& buffer, size_t size)
{
if (!m_readers) {
- Thread::current()->send_signal(SIGPIPE, Process::current());
+ Thread::current()->send_signal(SIGPIPE, &Process::current());
return EPIPE;
}
if (!fd.is_blocking() && m_buffer->space_for_writing() == 0)
diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp
index e0425a3d60..8cfb21ef26 100644
--- a/Kernel/FileSystem/InodeFile.cpp
+++ b/Kernel/FileSystem/InodeFile.cpp
@@ -68,7 +68,7 @@ KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspa
switch (request) {
case FIBMAP: {
- if (!Process::current()->is_superuser())
+ if (!Process::current().is_superuser())
return EPERM;
auto user_block_number = static_ptr_cast<int*>(arg);
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index 3afe6bb43a..3c23ea0a6f 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -196,8 +196,8 @@ KResult VirtualFileSystem::utime(StringView path, Custody& base, time_t atime, t
return custody_or_error.error();
auto& custody = *custody_or_error.value();
auto& inode = custody.inode();
- auto current_process = Process::current();
- if (!current_process->is_superuser() && inode.metadata().uid != current_process->euid())
+ auto& current_process = Process::current();
+ if (!current_process.is_superuser() && inode.metadata().uid != current_process.euid())
return EACCES;
if (custody.is_readonly())
return EROFS;
@@ -244,19 +244,19 @@ KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::open(StringView pat
bool should_truncate_file = false;
- auto current_process = Process::current();
- if ((options & O_RDONLY) && !metadata.may_read(*current_process))
+ auto& current_process = Process::current();
+ if ((options & O_RDONLY) && !metadata.may_read(current_process))
return EACCES;
if (options & O_WRONLY) {
- if (!metadata.may_write(*current_process))
+ if (!metadata.may_write(current_process))
return EACCES;
if (metadata.is_directory())
return EISDIR;
should_truncate_file = options & O_TRUNC;
}
if (options & O_EXEC) {
- if (!metadata.may_execute(*current_process) || (custody.mount_flags() & MS_NOEXEC))
+ if (!metadata.may_execute(current_process) || (custody.mount_flags() & MS_NOEXEC))
return EACCES;
}
@@ -334,15 +334,15 @@ KResult VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custod
if (existing_file_or_error.error() != ENOENT)
return existing_file_or_error.error();
auto& parent_inode = parent_custody->inode();
- auto current_process = Process::current();
- if (!parent_inode.metadata().may_write(*current_process))
+ auto& current_process = Process::current();
+ if (!parent_inode.metadata().may_write(current_process))
return EACCES;
if (parent_custody->is_readonly())
return EROFS;
auto basename = KLexicalPath::basename(path);
dbgln("VirtualFileSystem::mknod: '{}' mode={} dev={} in {}", basename, mode, dev, parent_inode.identifier());
- return parent_inode.create_child(basename, mode, dev, current_process->euid(), current_process->egid()).result();
+ return parent_inode.create_child(basename, mode, dev, current_process.euid(), current_process.egid()).result();
}
KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
@@ -363,15 +363,15 @@ KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::create(StringView p
}
auto& parent_inode = parent_custody.inode();
- auto current_process = Process::current();
- if (!parent_inode.metadata().may_write(*current_process))
+ auto& current_process = Process::current();
+ if (!parent_inode.metadata().may_write(current_process))
return EACCES;
if (parent_custody.is_readonly())
return EROFS;
dbgln_if(VFS_DEBUG, "VirtualFileSystem::create: '{}' in {}", basename, parent_inode.identifier());
- uid_t uid = owner.has_value() ? owner.value().uid : current_process->euid();
- gid_t gid = owner.has_value() ? owner.value().gid : current_process->egid();
+ uid_t uid = owner.has_value() ? owner.value().uid : current_process.euid();
+ gid_t gid = owner.has_value() ? owner.value().gid : current_process.egid();
auto inode_or_error = parent_inode.create_child(basename, mode, 0, uid, gid);
if (inode_or_error.is_error())
return inode_or_error.error();
@@ -409,15 +409,15 @@ KResult VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
VERIFY(result.error() == ENOENT);
auto& parent_inode = parent_custody->inode();
- auto current_process = Process::current();
- if (!parent_inode.metadata().may_write(*current_process))
+ auto& current_process = Process::current();
+ if (!parent_inode.metadata().may_write(current_process))
return EACCES;
if (parent_custody->is_readonly())
return EROFS;
auto basename = KLexicalPath::basename(path);
dbgln_if(VFS_DEBUG, "VirtualFileSystem::mkdir: '{}' in {}", basename, parent_inode.identifier());
- return parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process->euid(), current_process->egid()).result();
+ return parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process.euid(), current_process.egid()).result();
}
KResult VirtualFileSystem::access(StringView path, int mode, Custody& base)
@@ -428,19 +428,19 @@ KResult VirtualFileSystem::access(StringView path, int mode, Custody& base)
auto& custody = *custody_or_error.value();
auto& inode = custody.inode();
auto metadata = inode.metadata();
- auto current_process = Process::current();
+ auto& current_process = Process::current();
if (mode & R_OK) {
- if (!metadata.may_read(*current_process))
+ if (!metadata.may_read(current_process))
return EACCES;
}
if (mode & W_OK) {
- if (!metadata.may_write(*current_process))
+ if (!metadata.may_write(current_process))
return EACCES;
if (custody.is_readonly())
return EROFS;
}
if (mode & X_OK) {
- if (!metadata.may_execute(*current_process))
+ if (!metadata.may_execute(current_process))
return EACCES;
}
return KSuccess;
@@ -455,7 +455,7 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::open_directory(StringView p
auto& inode = custody.inode();
if (!inode.is_directory())
return ENOTDIR;
- if (!inode.metadata().may_execute(*Process::current()))
+ if (!inode.metadata().may_execute(Process::current()))
return EACCES;
return custody;
}
@@ -464,8 +464,8 @@ KResult VirtualFileSystem::chmod(Custody& custody, mode_t mode)
{
auto& inode = custody.inode();
- auto current_process = Process::current();
- if (current_process->euid() != inode.metadata().uid && !current_process->is_superuser())
+ auto& current_process = Process::current();
+ if (current_process.euid() != inode.metadata().uid && !current_process.is_superuser())
return EPERM;
if (custody.is_readonly())
return EROFS;
@@ -531,15 +531,15 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
return EDIRINTOSELF;
}
- auto current_process = Process::current();
- if (!new_parent_inode.metadata().may_write(*current_process))
+ auto& current_process = Process::current();
+ if (!new_parent_inode.metadata().may_write(current_process))
return EACCES;
- if (!old_parent_inode.metadata().may_write(*current_process))
+ if (!old_parent_inode.metadata().may_write(current_process))
return EACCES;
if (old_parent_inode.metadata().is_sticky()) {
- if (!current_process->is_superuser() && old_inode.metadata().uid != current_process->euid())
+ if (!current_process.is_superuser() && old_inode.metadata().uid != current_process.euid())
return EACCES;
}
@@ -564,7 +564,7 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
if (&new_inode == &old_inode)
return KSuccess;
if (new_parent_inode.metadata().is_sticky()) {
- if (!current_process->is_superuser() && new_inode.metadata().uid != current_process->euid())
+ if (!current_process.is_superuser() && new_inode.metadata().uid != current_process.euid())
return EACCES;
}
if (new_inode.is_directory() && !old_inode.is_directory())
@@ -587,20 +587,20 @@ KResult VirtualFileSystem::chown(Custody& custody, uid_t a_uid, gid_t a_gid)
auto& inode = custody.inode();
auto metadata = inode.metadata();
- auto current_process = Process::current();
- if (current_process->euid() != metadata.uid && !current_process->is_superuser())
+ auto& current_process = Process::current();
+ if (current_process.euid() != metadata.uid && !current_process.is_superuser())
return EPERM;
uid_t new_uid = metadata.uid;
gid_t new_gid = metadata.gid;
if (a_uid != (uid_t)-1) {
- if (current_process->euid() != a_uid && !current_process->is_superuser())
+ if (current_process.euid() != a_uid && !current_process.is_superuser())
return EPERM;
new_uid = a_uid;
}
if (a_gid != (gid_t)-1) {
- if (!current_process->in_group(a_gid) && !current_process->is_superuser())
+ if (!current_process.in_group(a_gid) && !current_process.is_superuser())
return EPERM;
new_gid = a_gid;
}
@@ -632,13 +632,13 @@ static bool hard_link_allowed(const Inode& inode)
{
auto metadata = inode.metadata();
- if (Process::current()->euid() == metadata.uid)
+ if (Process::current().euid() == metadata.uid)
return true;
if (metadata.is_regular_file()
&& !metadata.is_setuid()
&& !(metadata.is_setgid() && metadata.mode & S_IXGRP)
- && metadata.may_write(*Process::current())) {
+ && metadata.may_write(Process::current())) {
return true;
}
@@ -666,7 +666,7 @@ KResult VirtualFileSystem::link(StringView old_path, StringView new_path, Custod
if (parent_inode.fsid() != old_inode.fsid())
return EXDEV;
- if (!parent_inode.metadata().may_write(*Process::current()))
+ if (!parent_inode.metadata().may_write(Process::current()))
return EACCES;
if (old_inode.is_directory())
@@ -699,12 +699,12 @@ KResult VirtualFileSystem::unlink(StringView path, Custody& base)
VERIFY(parent_custody);
auto& parent_inode = parent_custody->inode();
- auto current_process = Process::current();
- if (!parent_inode.metadata().may_write(*current_process))
+ auto& current_process = Process::current();
+ if (!parent_inode.metadata().may_write(current_process))
return EACCES;
if (parent_inode.metadata().is_sticky()) {
- if (!current_process->is_superuser() && inode.metadata().uid != current_process->euid())
+ if (!current_process.is_superuser() && inode.metadata().uid != current_process.euid())
return EACCES;
}
@@ -728,15 +728,15 @@ KResult VirtualFileSystem::symlink(StringView target, StringView linkpath, Custo
if (existing_custody_or_error.is_error() && existing_custody_or_error.error() != ENOENT)
return existing_custody_or_error.error();
auto& parent_inode = parent_custody->inode();
- auto current_process = Process::current();
- if (!parent_inode.metadata().may_write(*current_process))
+ auto& current_process = Process::current();
+ if (!parent_inode.metadata().may_write(current_process))
return EACCES;
if (parent_custody->is_readonly())
return EROFS;
auto basename = KLexicalPath::basename(linkpath);
dbgln_if(VFS_DEBUG, "VirtualFileSystem::symlink: '{}' (-> '{}') in {}", basename, target, parent_inode.identifier());
- auto inode_or_error = parent_inode.create_child(basename, S_IFLNK | 0644, 0, current_process->euid(), current_process->egid());
+ auto inode_or_error = parent_inode.create_child(basename, S_IFLNK | 0644, 0, current_process.euid(), current_process.egid());
if (inode_or_error.is_error())
return inode_or_error.error();
auto& inode = inode_or_error.value();
@@ -769,11 +769,12 @@ KResult VirtualFileSystem::rmdir(StringView path, Custody& base)
auto& parent_inode = parent_custody->inode();
auto parent_metadata = parent_inode.metadata();
- if (!parent_metadata.may_write(*Process::current()))
+ auto& current_process = Process::current();
+ if (!parent_metadata.may_write(current_process))
return EACCES;
if (parent_metadata.is_sticky()) {
- if (!Process::current()->is_superuser() && inode.metadata().uid != Process::current()->euid())
+ if (!current_process.is_superuser() && inode.metadata().uid != current_process.euid())
return EACCES;
}
@@ -821,8 +822,9 @@ Custody& VirtualFileSystem::root_custody()
UnveilNode const& VirtualFileSystem::find_matching_unveiled_path(StringView path)
{
- VERIFY(Process::current()->veil_state() != VeilState::None);
- auto& unveil_root = Process::current()->unveiled_paths();
+ auto& current_process = Process::current();
+ VERIFY(current_process.veil_state() != VeilState::None);
+ auto& unveil_root = current_process.unveiled_paths();
auto path_parts = KLexicalPath::parts(path);
return unveil_root.traverse_until_last_accessible_node(path_parts.begin(), path_parts.end());
@@ -830,7 +832,7 @@ UnveilNode const& VirtualFileSystem::find_matching_unveiled_path(StringView path
KResult VirtualFileSystem::validate_path_against_process_veil(Custody const& custody, int options)
{
- if (Process::current()->veil_state() == VeilState::None)
+ if (Process::current().veil_state() == VeilState::None)
return KSuccess;
auto absolute_path = custody.try_create_absolute_path();
if (!absolute_path)
@@ -840,7 +842,7 @@ KResult VirtualFileSystem::validate_path_against_process_veil(Custody const& cus
KResult VirtualFileSystem::validate_path_against_process_veil(StringView path, int options)
{
- if (Process::current()->veil_state() == VeilState::None)
+ if (Process::current().veil_state() == VeilState::None)
return KSuccess;
if (path == "/usr/lib/Loader.so")
return KSuccess;
@@ -919,7 +921,7 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path(StringView pat
static bool safe_to_follow_symlink(const Inode& inode, const InodeMetadata& parent_metadata)
{
auto metadata = inode.metadata();
- if (Process::current()->euid() == metadata.uid)
+ if (Process::current().euid() == metadata.uid)
return true;
if (!(parent_metadata.is_sticky() && parent_metadata.mode & S_IWOTH))
@@ -940,7 +942,7 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(S
return EINVAL;
GenericLexer path_lexer(path);
- auto current_process = Process::current();
+ auto& current_process = Process::current();
NonnullRefPtr<Custody> custody = path[0] == '/' ? root_custody() : base;
bool extra_iteration = path[path.length() - 1] == '/';
@@ -956,7 +958,7 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(S
if (!parent_metadata.is_directory())
return ENOTDIR;
// Ensure the current user is allowed to resolve paths inside this directory.
- if (!parent_metadata.may_execute(*current_process))
+ if (!parent_metadata.may_execute(current_process))
return EACCES;
bool have_more_parts = !path_lexer.is_eof() || extra_iteration;
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp
index 4d2abd4210..da82a06103 100644
--- a/Kernel/GlobalProcessExposed.cpp
+++ b/Kernel/GlobalProcessExposed.cpp
@@ -109,7 +109,7 @@ private:
obj.add("bytes_in", socket.bytes_in());
obj.add("packets_out", socket.packets_out());
obj.add("bytes_out", socket.bytes_out());
- if (Process::current()->is_superuser() || Process::current()->uid() == socket.origin_uid()) {
+ if (Process::current().is_superuser() || Process::current().uid() == socket.origin_uid()) {
obj.add("origin_pid", socket.origin_pid());
obj.add("origin_uid", socket.origin_uid());
obj.add("origin_gid", socket.origin_gid());
@@ -159,7 +159,7 @@ private:
obj.add("local_port", socket.local_port());
obj.add("peer_address", socket.peer_address().to_string());
obj.add("peer_port", socket.peer_port());
- if (Process::current()->is_superuser() || Process::current()->uid() == socket.origin_uid()) {
+ if (Process::current().is_superuser() || Process::current().uid() == socket.origin_uid()) {
obj.add("origin_pid", socket.origin_pid());
obj.add("origin_uid", socket.origin_uid());
obj.add("origin_gid", socket.origin_gid());
@@ -336,7 +336,7 @@ private:
ProcFSSelfProcessDirectory();
virtual bool acquire_link(KBufferBuilder& builder) override
{
- builder.appendff("{}", Process::current()->pid().value());
+ builder.appendff("{}", Process::current().pid().value());
return true;
}
};
@@ -737,7 +737,7 @@ private:
virtual bool output(KBufferBuilder& builder) override
{
- if (!Process::current()->is_superuser())
+ if (!Process::current().is_superuser())
return false;
builder.append(String::number(kernel_load_base));
return true;
diff --git a/Kernel/Memory/AddressSpace.cpp b/Kernel/Memory/AddressSpace.cpp
index 1467f5922e..3dc0d4cd43 100644
--- a/Kernel/Memory/AddressSpace.cpp
+++ b/Kernel/Memory/AddressSpace.cpp
@@ -53,7 +53,7 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
if (!whole_region->is_mmap())
return EPERM;
- PerformanceManager::add_unmap_perf_event(*Process::current(), whole_region->range());
+ PerformanceManager::add_unmap_perf_event(Process::current(), whole_region->range());
deallocate_region(*whole_region);
return KSuccess;
@@ -83,7 +83,7 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
new_region->map(page_directory());
}
- PerformanceManager::add_unmap_perf_event(*Process::current(), range_to_unmap);
+ PerformanceManager::add_unmap_perf_event(Process::current(), range_to_unmap);
return KSuccess;
}
@@ -133,7 +133,7 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
new_region->map(page_directory());
}
- PerformanceManager::add_unmap_perf_event(*Process::current(), range_to_unmap);
+ PerformanceManager::add_unmap_perf_event(Process::current(), range_to_unmap);
return KSuccess;
}
diff --git a/Kernel/Memory/Region.cpp b/Kernel/Memory/Region.cpp
index 7ddb9f5d2e..7937dda73f 100644
--- a/Kernel/Memory/Region.cpp
+++ b/Kernel/Memory/Region.cpp
@@ -52,7 +52,7 @@ Region::~Region()
KResultOr<NonnullOwnPtr<Region>> Region::try_clone()
{
- VERIFY(Process::current());
+ VERIFY(Process::has_current());
if (m_shared) {
VERIFY(!m_stack);
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index 9ca1731153..7b5c50c7a2 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -118,9 +118,9 @@ KResult IPv4Socket::bind(Userspace<const sockaddr*> user_address, socklen_t addr
return set_so_error(EINVAL);
auto requested_local_port = ntohs(address.sin_port);
- if (!Process::current()->is_superuser()) {
+ if (!Process::current().is_superuser()) {
if (requested_local_port > 0 && requested_local_port < 1024) {
- dbgln("UID {} attempted to bind {} to port {}", Process::current()->uid(), class_name(), requested_local_port);
+ dbgln("UID {} attempted to bind {} to port {}", Process::current().uid(), class_name(), requested_local_port);
return set_so_error(EACCES);
}
}
@@ -603,7 +603,7 @@ KResult IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> a
switch (request) {
case SIOCADDRT:
- if (!Process::current()->is_superuser())
+ if (!Process::current().is_superuser())
return EPERM;
if (route.rt_gateway.sa_family != AF_INET)
return EAFNOSUPPORT;
@@ -628,7 +628,7 @@ KResult IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> a
switch (request) {
case SIOCSARP:
- if (!Process::current()->is_superuser())
+ if (!Process::current().is_superuser())
return EPERM;
if (arp_req.arp_pa.sa_family != AF_INET)
return EAFNOSUPPORT;
@@ -636,7 +636,7 @@ KResult IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> a
return KSuccess;
case SIOCDARP:
- if (!Process::current()->is_superuser())
+ if (!Process::current().is_superuser())
return EPERM;
if (arp_req.arp_pa.sa_family != AF_INET)
return EAFNOSUPPORT;
@@ -663,7 +663,7 @@ KResult IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> a
switch (request) {
case SIOCSIFADDR:
- if (!Process::current()->is_superuser())
+ if (!Process::current().is_superuser())
return EPERM;
if (ifr.ifr_addr.sa_family != AF_INET)
return EAFNOSUPPORT;
@@ -671,7 +671,7 @@ KResult IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> a
return KSuccess;
case SIOCSIFNETMASK:
- if (!Process::current()->is_superuser())
+ if (!Process::current().is_superuser())
return EPERM;
if (ifr.ifr_addr.sa_family != AF_INET)
return EAFNOSUPPORT;
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index 7d23684d77..322d390913 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -61,7 +61,7 @@ KResultOr<SocketPair> LocalSocket::create_connected_pair(int type)
socket->m_address.sun_family = AF_LOCAL;
memcpy(socket->m_address.sun_path, "[socketpair]", 13);
- auto& process = *Process::current();
+ auto& process = Process::current();
socket->m_acceptor = { process.pid().value(), process.uid(), process.gid() };
socket->set_connected(true);
@@ -80,9 +80,9 @@ LocalSocket::LocalSocket(int type, NonnullOwnPtr<DoubleBuffer> client_buffer, No
, m_for_client(move(client_buffer))
, m_for_server(move(server_buffer))
{
- auto current_process = Process::current();
- m_prebind_uid = current_process->euid();
- m_prebind_gid = current_process->egid();
+ auto& current_process = Process::current();
+ m_prebind_uid = current_process.euid();
+ m_prebind_gid = current_process.egid();
m_prebind_mode = 0666;
m_for_client->set_unblock_callback([this]() {
@@ -137,7 +137,7 @@ KResult LocalSocket::bind(Userspace<const sockaddr*> user_address, socklen_t add
mode_t mode = S_IFSOCK | (m_prebind_mode & 0777);
UidAndGid owner { m_prebind_uid, m_prebind_gid };
- auto result = VirtualFileSystem::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current()->current_directory(), owner);
+ auto result = VirtualFileSystem::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current().current_directory(), owner);
if (result.is_error()) {
if (result.error() == EEXIST)
return set_so_error(EADDRINUSE);
@@ -179,7 +179,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace<const socka
dbgln_if(LOCAL_SOCKET_DEBUG, "LocalSocket({}) connect({})", this, safe_address);
- auto description_or_error = VirtualFileSystem::the().open(safe_address, O_RDWR, 0, Process::current()->current_directory());
+ auto description_or_error = VirtualFileSystem::the().open(safe_address, O_RDWR, 0, Process::current().current_directory());
if (description_or_error.is_error())
return set_so_error(ECONNREFUSED);
@@ -445,8 +445,8 @@ KResult LocalSocket::chown(FileDescription&, uid_t uid, gid_t gid)
if (m_file)
return m_file->chown(uid, gid);
- auto current_process = Process::current();
- if (!current_process->is_superuser() && (current_process->euid() != uid || !current_process->in_group(gid)))
+ auto& current_process = Process::current();
+ if (!current_process.is_superuser() && (current_process.euid() != uid || !current_process.in_group(gid)))
return set_so_error(EPERM);
m_prebind_uid = uid;
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp
index a3c13316ad..f67339dfb3 100644
--- a/Kernel/Net/Socket.cpp
+++ b/Kernel/Net/Socket.cpp
@@ -34,7 +34,7 @@ Socket::Socket(int domain, int type, int protocol)
, m_type(type)
, m_protocol(protocol)
{
- auto& process = *Process::current();
+ auto& process = Process::current();
m_origin = { process.pid().value(), process.uid(), process.gid() };
}
@@ -57,7 +57,7 @@ RefPtr<Socket> Socket::accept()
dbgln_if(SOCKET_DEBUG, "Socket({}) de-queueing connection", this);
auto client = m_pending.take_first();
VERIFY(!client->is_connected());
- auto& process = *Process::current();
+ auto& process = Process::current();
client->m_acceptor = { process.pid().value(), process.uid(), process.gid() };
client->m_connected = true;
client->m_role = Role::Accepted;
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 61143fd994..0fdc1bec95 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -389,7 +389,7 @@ void create_signal_trampoline()
void Process::crash(int signal, FlatPtr ip, bool out_of_memory)
{
VERIFY(!is_dead());
- VERIFY(Process::current() == this);
+ VERIFY(&Process::current() == this);
if (out_of_memory) {
dbgln("\033[31;1mOut of memory\033[m, killing: {}", *this);
@@ -720,7 +720,7 @@ void Process::terminate_due_to_signal(u8 signal)
{
VERIFY_INTERRUPTS_DISABLED();
VERIFY(signal < 32);
- VERIFY(Process::current() == this);
+ VERIFY(&Process::current() == this);
dbgln("Terminating {} due to signal {}", *this, signal);
{
ProtectedDataMutationScope scope { *this };
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 6c0d57b58c..176582fbc2 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -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)
}
diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp
index f322497459..d000ae45a3 100644
--- a/Kernel/ProcessSpecificExposed.cpp
+++ b/Kernel/ProcessSpecificExposed.cpp
@@ -24,7 +24,7 @@ KResultOr<size_t> Process::procfs_get_thread_stack(ThreadID thread_id, KBufferBu
auto thread = Thread::from_tid(thread_id);
if (!thread)
return KResult(ESRCH);
- bool show_kernel_addresses = Process::current()->is_superuser();
+ bool show_kernel_addresses = Process::current().is_superuser();
bool kernel_address_added = false;
for (auto address : Processor::capture_stack_trace(*thread, 1024)) {
if (!show_kernel_addresses && !Memory::is_user_address(VirtualAddress { address })) {
@@ -213,7 +213,7 @@ KResult Process::procfs_get_virtual_memory_stats(KBufferBuilder& builder) const
{
ScopedSpinLock lock(address_space().get_lock());
for (auto& region : address_space().regions()) {
- if (!region->is_user() && !Process::current()->is_superuser())
+ if (!region->is_user() && !Process::current().is_superuser())
continue;
auto region_object = array.add_object();
region_object.add("readable", region->is_readable());
diff --git a/Kernel/Syscalls/fcntl.cpp b/Kernel/Syscalls/fcntl.cpp
index 61a9a6ef99..c2d59bda0f 100644
--- a/Kernel/Syscalls/fcntl.cpp
+++ b/Kernel/Syscalls/fcntl.cpp
@@ -47,7 +47,7 @@ KResultOr<FlatPtr> Process::sys$fcntl(int fd, int cmd, u32 arg)
case F_GETLK:
return description->get_flock(Userspace<flock*>(arg));
case F_SETLK:
- return description->apply_flock(*Process::current(), Userspace<const flock*>(arg));
+ return description->apply_flock(Process::current(), Userspace<const flock*>(arg));
default:
return EINVAL;
}
diff --git a/Kernel/Syscalls/ptrace.cpp b/Kernel/Syscalls/ptrace.cpp
index 32919cd7d5..f9e9ffed48 100644
--- a/Kernel/Syscalls/ptrace.cpp
+++ b/Kernel/Syscalls/ptrace.cpp
@@ -20,7 +20,7 @@ static KResultOr<u32> handle_ptrace(const Kernel::Syscall::SC_ptrace_params& par
{
ScopedSpinLock scheduler_lock(g_scheduler_lock);
if (params.request == PT_TRACE_ME) {
- if (Process::current()->tracer())
+ if (Process::current().tracer())
return EBUSY;
caller.set_wait_for_tracer_at_next_execve(true);
diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp
index ec4b567f03..7a8fcbe3ec 100644
--- a/Kernel/Syscalls/thread.cpp
+++ b/Kernel/Syscalls/thread.cpp
@@ -168,12 +168,8 @@ KResultOr<FlatPtr> Process::sys$kill_thread(pid_t tid, int signal)
if (!thread || thread->pid() != pid())
return ESRCH;
- auto process = Process::current();
- if (!process)
- return ESRCH;
-
if (signal != 0)
- thread->send_signal(signal, process);
+ thread->send_signal(signal, &Process::current());
return 0;
}
diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp
index dea6557f91..1abd5ca61f 100644
--- a/Kernel/TTY/MasterPTY.cpp
+++ b/Kernel/TTY/MasterPTY.cpp
@@ -41,9 +41,9 @@ MasterPTY::MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer)
, m_buffer(move(buffer))
{
m_pts_name = String::formatted("/dev/pts/{}", m_index);
- auto process = Process::current();
- set_uid(process->uid());
- set_gid(process->gid());
+ auto& process = Process::current();
+ set_uid(process.uid());
+ set_gid(process.gid());
m_buffer->set_unblock_callback([this]() {
if (m_slave)
diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp
index 664a3050f1..4655badf9c 100644
--- a/Kernel/TTY/SlavePTY.cpp
+++ b/Kernel/TTY/SlavePTY.cpp
@@ -39,9 +39,9 @@ SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
, m_index(index)
{
m_tty_name = String::formatted("/dev/pts/{}", m_index);
- auto process = Process::current();
- set_uid(process->uid());
- set_gid(process->gid());
+ auto& process = Process::current();
+ set_uid(process.uid());
+ set_gid(process.gid());
set_size(80, 25);
SlavePTY::all_instances().with([&](auto& list) { list.append(*this); });
diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp
index 598eba8e85..7073b5a554 100644
--- a/Kernel/TTY/TTY.cpp
+++ b/Kernel/TTY/TTY.cpp
@@ -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;
diff --git a/Kernel/ThreadBlockers.cpp b/Kernel/ThreadBlockers.cpp
index 30894af6ba..e967704dc5 100644
--- a/Kernel/ThreadBlockers.cpp
+++ b/Kernel/ThreadBlockers.cpp
@@ -599,7 +599,7 @@ Thread::WaitBlocker::WaitBlocker(int wait_options, idtype_t id_type, pid_t id, K
switch (id_type) {
case P_PID: {
m_waitee = Process::from_pid(m_waitee_id);
- if (!m_waitee || m_waitee->ppid() != Process::current()->pid()) {
+ if (!m_waitee || m_waitee->ppid() != Process::current().pid()) {
m_result = ECHILD;
m_error = true;
}
@@ -622,7 +622,7 @@ Thread::WaitBlocker::WaitBlocker(int wait_options, idtype_t id_type, pid_t id, K
// NOTE: unblock may be called within set_block_condition, in which
// case it means that we already have a match without having to block.
// In that case set_block_condition will return false.
- if (m_error || !set_block_condition(Process::current()->wait_block_condition()))
+ if (m_error || !set_block_condition(Process::current().wait_block_condition()))
m_should_block = false;
}
@@ -630,7 +630,7 @@ void Thread::WaitBlocker::not_blocking(bool timeout_in_past)
{
VERIFY(timeout_in_past || !m_should_block);
if (!m_error)
- Process::current()->wait_block_condition().try_unblock(*this);
+ Process::current().wait_block_condition().try_unblock(*this);
}
void Thread::WaitBlocker::was_unblocked(bool)
@@ -643,7 +643,7 @@ void Thread::WaitBlocker::was_unblocked(bool)
}
if (try_unblock)
- Process::current()->wait_block_condition().try_unblock(*this);
+ Process::current().wait_block_condition().try_unblock(*this);
// If we were interrupted by SIGCHLD (which gets special handling
// here) we're not going to return with EINTR. But we're going to
diff --git a/Kernel/init.cpp b/Kernel/init.cpp
index 61c5fec4ab..1ffafa1cd5 100644
--- a/Kernel/init.cpp
+++ b/Kernel/init.cpp
@@ -262,7 +262,7 @@ void init_stage2(void*)
// This is a little bit of a hack. We can't register our process at the time we're
// creating it, but we need to be registered otherwise finalization won't be happy.
// The colonel process gets away without having to do this because it never exits.
- Process::register_new(*Process::current());
+ Process::register_new(Process::current());
WorkQueue::initialize();
@@ -352,14 +352,14 @@ void init_stage2(void*)
if (boot_profiling) {
dbgln("Starting full system boot profiling");
- MutexLocker mutex_locker(Process::current()->big_lock());
- auto result = Process::current()->sys$profiling_enable(-1, ~0ull);
+ MutexLocker mutex_locker(Process::current().big_lock());
+ auto result = Process::current().sys$profiling_enable(-1, ~0ull);
VERIFY(!result.is_error());
}
NetworkTask::spawn();
- Process::current()->sys$exit(0);
+ Process::current().sys$exit(0);
VERIFY_NOT_REACHED();
}