Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper mechanism around syscall / sysret #244

Open
MarcoCicognani opened this issue Apr 13, 2021 · 3 comments
Open

Add wrapper mechanism around syscall / sysret #244

MarcoCicognani opened this issue Apr 13, 2021 · 3 comments

Comments

@MarcoCicognani
Copy link

Hi!
How i can easily access the pushed registers from an InterruptStackFrame instance?
I need this to read/write the saved values, for example, for system calls arguments

@phil-opp
Copy link
Member

The InterruptStackFrame does not contain any general purpose registers. These need to be pushed separately. If you're using the x86-interrupt calling convention, the compiler will do this automatically for all registers that the function uses. However, there is no defined order, so you cannot access them.

So you probably need a custom assembly entry point for system calls. To make this easier, you can require in your OS that some/all registers can be overwritten on system calls so that the userspace application has to take care of saving/restoring them. This is possible because system calls are initiated by the userspace application, unlike hardware interrupts and exceptions. Then the assembly entry point can be just a thin mov rdi, rax; call func; iretq wrapper around an extern "C func(rax_value: u64)" Rust function.

@josephlr
Copy link
Contributor

josephlr commented May 6, 2021

@phil-opp is correct here. In general, it's not very ergonomic to use interrupts for system calls (as it requires dealing with the indeterminate order the registers are pushed/popped from the stack). The easier way is to just use the SYSCALL/SYSRET instructions, which avoid a lot of the pitfalls of interrupt based syscalls (hence why Linux and Windows generally prefer this method).

This crate provides support for setting up the Star, LStar, and SFMask registers, but does not provide any wrappers around syscall or sysret.

@MarcoCicognani, would Rust wrappers around the syscall/sysret instructions help address your issue?

@MarcoCicognani
Copy link
Author

Hi @josephlr!
Thanks for your answer, I completely agree with you!
Yes, a rust wrapper for syscall/sysret will help a lot

@josephlr josephlr changed the title InterruptStackFrame's Pushed Registers Add wrapper mechanism around syscall / sysret Mar 26, 2022
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

No branches or pull requests

3 participants