Skip to content

Commit

Permalink
Kernel: Rename {ss,esp}_if_crossRing to userspace_{ss,esp}
Browse files Browse the repository at this point in the history
These were always so awkwardly named.
  • Loading branch information
awesomekling committed Jan 9, 2020
1 parent f007a63 commit 17ef5bc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Kernel/Arch/i386/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ static void dump(const RegisterDump& regs)
ss = regs.ss;
esp = regs.esp;
} else {
ss = regs.ss_if_crossRing;
esp = regs.esp_if_crossRing;
ss = regs.userspace_ss;
esp = regs.userspace_esp;
}

kprintf("exception code: %04x (isr: %04x)\n", regs.exception_code, regs.isr_number);
Expand Down Expand Up @@ -247,8 +247,8 @@ void page_fault_handler(RegisterDump regs)
#endif

bool faulted_in_userspace = (regs.cs & 3) == 3;
if (faulted_in_userspace && !MM.validate_user_stack(current->process(), VirtualAddress(regs.esp_if_crossRing))) {
dbgprintf("Invalid stack pointer: %p\n", regs.esp_if_crossRing);
if (faulted_in_userspace && !MM.validate_user_stack(current->process(), VirtualAddress(regs.userspace_esp))) {
dbgprintf("Invalid stack pointer: %p\n", regs.userspace_esp);
handle_crash(regs, "Bad stack on page fault", SIGSTKFLT);
ASSERT_NOT_REACHED();
}
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Arch/i386/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ struct [[gnu::packed]] RegisterDump
u32 eip;
u32 cs;
u32 eflags;
u32 esp_if_crossRing;
u32 ss_if_crossRing;
u32 userspace_esp;
u32 userspace_ss;
};

struct [[gnu::aligned(16)]] FPUState
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ pid_t Process::sys$fork(RegisterDump& regs)
child_tss.ecx = regs.ecx;
child_tss.edx = regs.edx;
child_tss.ebp = regs.ebp;
child_tss.esp = regs.esp_if_crossRing;
child_tss.esp = regs.userspace_esp;
child_tss.esi = regs.esi;
child_tss.edi = regs.edi;
child_tss.eflags = regs.eflags;
Expand All @@ -597,7 +597,7 @@ pid_t Process::sys$fork(RegisterDump& regs)
child_tss.es = regs.es;
child_tss.fs = regs.fs;
child_tss.gs = regs.gs;
child_tss.ss = regs.ss_if_crossRing;
child_tss.ss = regs.userspace_ss;

#ifdef FORK_DEBUG
dbgprintf("fork: child will begin executing at %w:%x with stack %w:%x, kstack %w:%x\n", child_tss.cs, child_tss.eip, child_tss.ss, child_tss.esp, child_tss.ss0, child_tss.esp0);
Expand Down Expand Up @@ -1180,7 +1180,7 @@ int Process::sys$sigreturn(RegisterDump& registers)
SmapDisabler disabler;

//Here, we restore the state pushed by dispatch signal and asm_signal_trampoline.
u32* stack_ptr = (u32*)registers.esp_if_crossRing;
u32* stack_ptr = (u32*)registers.userspace_esp;
u32 smuggled_eax = *stack_ptr;

//pop the stored eax, ebp, return address, handler and signal code
Expand All @@ -1199,7 +1199,7 @@ int Process::sys$sigreturn(RegisterDump& registers)
registers.eflags = *stack_ptr;
stack_ptr++;

registers.esp_if_crossRing = registers.esp;
registers.userspace_esp = registers.esp;
return smuggled_eax;
}

Expand Down
4 changes: 2 additions & 2 deletions Kernel/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ void Scheduler::timer_tick(RegisterDump& regs)
outgoing_tss.ss = regs.ss;

if ((outgoing_tss.cs & 3) != 0) {
outgoing_tss.ss = regs.ss_if_crossRing;
outgoing_tss.esp = regs.esp_if_crossRing;
outgoing_tss.ss = regs.userspace_ss;
outgoing_tss.esp = regs.userspace_esp;
}
prepare_for_iret_to_new_process();

Expand Down
4 changes: 2 additions & 2 deletions Kernel/Syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void syscall_handler(RegisterDump regs)

auto& process = current->process();

if (!MM.validate_user_stack(process, VirtualAddress(regs.esp_if_crossRing))) {
dbgprintf("Invalid stack pointer: %p\n", regs.esp_if_crossRing);
if (!MM.validate_user_stack(process, VirtualAddress(regs.userspace_esp))) {
dbgprintf("Invalid stack pointer: %p\n", regs.userspace_esp);
handle_crash(regs, "Bad stack on syscall entry", SIGSTKFLT);
ASSERT_NOT_REACHED();
}
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ ShouldUnblockThread Thread::dispatch_signal(u8 signal)
set_state(Skip1SchedulerPass);
} else {
auto& regs = get_register_dump_from_stack();
u32* stack = &regs.esp_if_crossRing;
u32* stack = &regs.userspace_esp;
setup_stack(regs, stack);
regs.eip = g_return_to_ring3_from_signal_trampoline.get();
}
Expand Down

0 comments on commit 17ef5bc

Please sign in to comment.