mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
Kernel: Move syscall precondition validates to MM
Move these to MM to simplify the flow of the syscall handler. While here, also make sure we hold the process space lock for the duration of the validation to avoid potential issues where another thread attempts to modify the process space during the validation. This will allow us to move the validation out of the big process lock scope in a future change. Additionally utilize the new no_lock variants of functions to avoid unnecessary recursive process space spinlock acquisitions.
This commit is contained in:
parent
af543328ea
commit
27e1120dff
3 changed files with 50 additions and 35 deletions
|
@ -199,39 +199,7 @@ NEVER_INLINE void syscall_handler(TrapFrame* trap)
|
|||
// NOTE: We take the big process lock before inspecting memory regions.
|
||||
process.big_lock().lock();
|
||||
|
||||
VirtualAddress userspace_sp;
|
||||
#if ARCH(I386)
|
||||
userspace_sp = VirtualAddress { regs.userspace_esp };
|
||||
#else
|
||||
userspace_sp = VirtualAddress { regs.userspace_rsp };
|
||||
#endif
|
||||
if (!MM.validate_user_stack(process.space(), userspace_sp)) {
|
||||
dbgln("Invalid stack pointer: {:p}", userspace_sp);
|
||||
handle_crash(regs, "Bad stack on syscall entry", SIGSTKFLT);
|
||||
}
|
||||
|
||||
VirtualAddress ip;
|
||||
#if ARCH(I386)
|
||||
ip = VirtualAddress { regs.eip };
|
||||
#else
|
||||
ip = VirtualAddress { regs.rip };
|
||||
#endif
|
||||
|
||||
auto* calling_region = MM.find_user_region_from_vaddr(process.space(), ip);
|
||||
if (!calling_region) {
|
||||
dbgln("Syscall from {:p} which has no associated region", ip);
|
||||
handle_crash(regs, "Syscall from unknown region", SIGSEGV);
|
||||
}
|
||||
|
||||
if (calling_region->is_writable()) {
|
||||
dbgln("Syscall from writable memory at {:p}", ip);
|
||||
handle_crash(regs, "Syscall from writable memory", SIGSEGV);
|
||||
}
|
||||
|
||||
if (process.space().enforces_syscall_regions() && !calling_region->is_syscall_region()) {
|
||||
dbgln("Syscall from non-syscall region");
|
||||
handle_crash(regs, "Syscall from non-syscall region", SIGSEGV);
|
||||
}
|
||||
MM.validate_syscall_preconditions(process.space(), regs);
|
||||
|
||||
FlatPtr function;
|
||||
FlatPtr arg1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue