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

Improve syscall implementation #284

Merged
merged 8 commits into from
Aug 28, 2023

Conversation

wipawel
Copy link
Contributor

@wipawel wipawel commented Aug 22, 2023

Note: This PR is based on #282. Please review and merge #282 first or focus only on the new bits.

Main change is a split of the syscall implementation with proper
assembly routines: syscall_handler_entry() and simplified
syscall_exit() and a simplified C-level syscall handler function.
The syscall_exit() is implemented and handled fully in asm.

The syscall() usermode function implements typical syscall ABI,
passing syscall number via AX register and the rest of parameters
via SI, DX, DI, R8 and R9. The assembly entry point rearranges the
registers to fix the C-level handler function API.
Only 5 arguments to the syscall can be provided.
Usermode upon calling syscall() takes are of callee saved registers by
saving/restoring them via usermode stack (only reminder of unused
registers is preserved as the rest is considered implicitely clobbered).

Additionally SYSCALL_PRINTF has been improved to support variadic
number of arguments (it passes the va_list args to the kernel mode).

@wipawel wipawel added improvement A small enhancement, that makes already implemented features better cleanup labels Aug 22, 2023
@wipawel wipawel requested a review from a team as a code owner August 22, 2023 15:18
sktt
sktt previously approved these changes Aug 23, 2023
Copy link
Contributor

@sktt sktt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, added a couple of remarks "just because".

common/usermode.c Show resolved Hide resolved
common/usermode.c Show resolved Hide resolved
@wipawel wipawel force-pushed the syscall_fix branch 2 times, most recently from 375dbdb to 974476d Compare August 24, 2023 12:27
arch/x86/asm-offsets.c Outdated Show resolved Hide resolved
arch/x86/asm-offsets.c Outdated Show resolved Hide resolved
Copy link
Contributor

@minipli-oss minipli-oss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great series, thanks a lot for doing this! Only needs a tiny bit more polishing.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
The terminate_user_task() is used upon exception when in usermode.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
Main change is a split of the syscall implementation with proper
assembly routines: syscall_handler_entry() and simplified
syscall_exit() and a simplified C-level syscall handler function.
The syscall_exit() is implemented and handled fully in asm.

The syscall() usermode function implements typical syscall ABI,
passing syscall number via AX register and the rest of parameters
via SI, DX, DI, R8 and R9. The assembly entry point rearranges the
registers to fix the C-level handler function API.
Only 5 arguments to the syscall can be provided.
Usermode upon calling syscall() takes are of callee saved registers by
saving/restoring them via usermode stack (only reminder of unused
registers is preserved as the rest is considered implicitely clobbered).

Additionally SYSCALL_PRINTF has been improved to support variadic
number of arguments (it passes the va_list args to the kernel mode).

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
In 64bit mode push 64bit 0 value on the stack as the aligning error
code and overwrite upper 32 bits of it with vector value.

In 32bit mode push 32bit 0 value on the stack as the aligning error
code and push vector value additionally.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
Copy link
Contributor

@minipli-oss minipli-oss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@wipawel wipawel merged commit 740626e into KernelTestFramework:mainline Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup improvement A small enhancement, that makes already implemented features better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants