Skip to content

Add userland resume path and tty input flush on exec - #35

Merged
pradosh-arduino merged 2 commits into
mainfrom
codex/fix-os-userland-return-crash-and-tty-buffer-issue
Apr 2, 2026
Merged

Add userland resume path and tty input flush on exec#35
pradosh-arduino merged 2 commits into
mainfrom
codex/fix-os-userland-return-crash-and-tty-buffer-issue

Conversation

@pradosh-arduino

Copy link
Copy Markdown
Collaborator

Motivation

  • Ensure clean terminal state when launching a new userland program and provide a safe mechanism for userland to return control to the kernel outside the normal iretq path.
  • Preserve callee-saved registers and kernel stack context so the kernel can resume execution atomically when a userland process requests to return.

Description

  • Added tty_flush_input() to the TTY API (tty.h) and implemented it to clear the cooked ring buffer and reset the current line (tty.c).
  • Call tty_flush_input() from the shell exec command (exec.c) before invoking userland_exec to clear leftover input.
  • Introduced volatile resume state variables and a userland_should_return_kernel flag in userland.c, and save callee-saved registers (rbx, rbp, r12..r15) plus kernel rsp/rip before entering userland.
  • Updated userland_prepare_exit() to signal return by setting userland_should_return_kernel instead of directly patching a syscall frame.
  • Modified syscall entry assembly (syscalls-x86_64.asm) to check userland_should_return_kernel and, if set, restore saved registers and rsp/rip and jump directly to the saved kernel resume address; otherwise perform the normal iretq return.
  • Clear resume state after returning to kernel and ensure userland_running/exit code handling remains intact.

Testing

  • Built the kernel using make which completed successfully without compilation errors.
  • Booted the kernel under QEMU with a minimal automated smoke test that runs the shell and executes a small userland binary via exec, and observed the kernel print the process exit code and return to the shell, indicating the resume/exit path and TTY flush behaved as expected.

Codex Task

@pradosh-arduino
pradosh-arduino merged commit cff3ea1 into main Apr 2, 2026
2 checks passed
@pradosh-arduino
pradosh-arduino deleted the codex/fix-os-userland-return-crash-and-tty-buffer-issue branch April 2, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant