Skip to content

refactor(kernel): decouple process/cpu arch boundary and unify TrapFrame/PerCpu/Context - #13

Merged
imtsuki merged 7 commits into
masterfrom
refactor/process-cpu-arch-decouple
Nov 13, 2026
Merged

imtsuki merged 7 commits into
masterfrom
refactor/process-cpu-arch-decouple

Conversation

@imtsuki

@imtsuki imtsuki commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Dedicated PerCpu (%gs) & Clean GDT/TSS:
    • Added arch::x86_64::percpu::PerCpu bound to KernelGsBase (kernel_rsp, user_rsp_scratch, user_cs, user_ss), replacing hardcoded TSS byte offsets (0x4, 0x1c), hardcoded segment selectors (0x1b, 0x23), and redundant push_kernel_stack / pop_kernel_stack TSS scratch-slot shuffling with offset_of!(PerCpu, ...) and arch::set_kernel_stack.
  • Unified TrapFrame & Pure Callee-Saved Context:
    • Replaced arch/x86_64/macros.rs (#[repr(packed)] SyscallStackFrame) and the separate InterruptStackFrameValue bootstrap path with a single #[repr(C)] TrapFrame + trap_return trampoline (arch/x86_64/trapframe.rs) shared across initial Ring 3 entry and syscall exit.
    • Slimmed Context (arch/x86_64/context.rs) down to pure kernel callee-saved registers (rsp, r15, r14, r13, r12, rbp, rbx), delegating address space switching to AddressSpace::activate() / paging::activate_kernel_page_table().
  • Guarded 16 KiB KernelStack & Safe User Memory Operations:
    • Introduced KernelStack (16 KiB stack + 4 KiB unmapped guard page, recycled on Drop) and AddressSpace::{map_user_range, copy_to_user, write_user_u64} in arch/x86_64/paging.rs.
  • Clean Process / Cpu / Scheduler Ownership & Zero Aliasing &mut UB:
    • Removed all x86_64 / gdt leaks and syscall::process reverse dependencies from process.rs and cpu.rs, eliminated my_cpu() -> &'static mut Cpu / my_proc() -> &'static mut Process aliasing &mut UB, removed fake impl Clone for Process and boot dbg! noise, and wired up a clean RUN_QUEUE round-robin scheduler (enqueue, run, yield_now, exit_current).

Verification

  • cargo check passes cleanly for both frame-allocator-bitmap and frame-allocator-buddy with zero warnings.
  • Booted and verified interactive /init shell (SYS_YIELD, SYS_GETPID, mknod, open, read, write, canonical TTY backspace editing) in QEMU under both debug and release profiles.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T22:35:10.958621Z e97d2a9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@imtsuki imtsuki changed the title refactor(process): decouple arch context/paging and eliminate aliasing &mut UB refactor(kernel): decouple process/cpu arch boundary and unify TrapFrame/PerCpu/Context Nov 13, 2026
@imtsuki
imtsuki merged commit 11cd605 into master Nov 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant