Skip to content

Commit

Permalink
Save some additional registers when switching contexts.
Browse files Browse the repository at this point in the history
There's probably a performance hit related to doing this, but it seems wise if we want to resume processes. Still working on getting xsave to work for saving registers instead.

Change-Id: I0975f72bf9bdfac8f275c7ca9c2cf2f3fa5984df
  • Loading branch information
jul-sh committed Jun 27, 2024
1 parent 3920e52 commit f5ab16b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions oak_restricted_kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ struct UserContext {
r9: u64,
r10: u64,
r11: u64,
r12: u64,
r13: u64,
r14: u64,
r15: u64,
rbp: u64,
ymm: [[u64; 4]; 16],
}

Expand Down Expand Up @@ -186,6 +191,10 @@ extern "C" fn syscall_entrypoint() {
"mov gs:[{OFFSET_R9}], r9",
"mov gs:[{OFFSET_R10}], r10",
"mov gs:[{OFFSET_R11}], r11",
"mov gs:[{OFFSET_R12}], r12",
"mov gs:[{OFFSET_R13}], r13",
"mov gs:[{OFFSET_R14}], r14",
"mov gs:[{OFFSET_R15}], r15",

// Save AVX registers to GsData
"vmovups gs:[{OFFSET_YMM} + 0*32], YMM0",
Expand Down Expand Up @@ -249,6 +258,10 @@ extern "C" fn syscall_entrypoint() {
"mov r9, gs:[{OFFSET_R9}]",
"mov r10, gs:[{OFFSET_R10}]",
"mov r11, gs:[{OFFSET_R11}]", // restore user RFLAGS
"mov r12, gs:[{OFFSET_R12}]",
"mov r13, gs:[{OFFSET_R13}]",
"mov r14, gs:[{OFFSET_R14}]",
"mov r15, gs:[{OFFSET_R15}]",

// Restore user RSP in preparation for SYSRET.
"mov rsp, gs:[{OFFSET_RSP}]",
Expand All @@ -268,6 +281,10 @@ extern "C" fn syscall_entrypoint() {
OFFSET_R9 = const(offset_of!(GsData, user_ctx.r9)),
OFFSET_R10 = const(offset_of!(GsData, user_ctx.r10)),
OFFSET_R11 = const(offset_of!(GsData, user_ctx.r11)),
OFFSET_R12 = const(offset_of!(GsData, user_ctx.r12)),
OFFSET_R13 = const(offset_of!(GsData, user_ctx.r13)),
OFFSET_R14 = const(offset_of!(GsData, user_ctx.r14)),
OFFSET_R15 = const(offset_of!(GsData, user_ctx.r15)),
OFFSET_YMM = const(offset_of!(GsData, user_ctx.ymm)),
options(noreturn)
}
Expand Down

0 comments on commit f5ab16b

Please sign in to comment.