x86_64: thread: copy fs- and gs-base pointers to cloned thread context

This commit is contained in:
2026-04-19 19:36:16 +01:00
parent c7c497cd66
commit 3584f6831b
2 changed files with 13 additions and 5 deletions
+3 -1
View File
@@ -34,7 +34,9 @@ extern kern_status_t ml_thread_prepare_user_context(
/* prepare the stack so that ml_thread_switch_user can jump to usermode
* with the specified register context */
extern kern_status_t ml_thread_clone_user_context(
const struct ml_cpu_context *ctx,
const struct ml_cpu_context *src_regs,
const struct ml_thread *src_ml,
struct ml_thread *dest_ml,
uintptr_t return_value,
virt_addr_t *kernel_sp);
+10 -4
View File
@@ -81,16 +81,22 @@ extern kern_status_t ml_thread_prepare_user_context(
}
kern_status_t ml_thread_clone_user_context(
const struct ml_cpu_context *src_ctx,
const struct ml_cpu_context *src_regs,
const struct ml_thread *src_ml,
struct ml_thread *dest_ml,
uintptr_t return_value,
virt_addr_t *kernel_sp)
{
(*kernel_sp) -= sizeof(struct ml_cpu_context);
struct ml_cpu_context *ctx = (struct ml_cpu_context *)(*kernel_sp);
memcpy(ctx, src_ctx, sizeof *ctx);
struct ml_cpu_context *regs = (struct ml_cpu_context *)(*kernel_sp);
memcpy(regs, src_regs, sizeof *regs);
ctx->rax = return_value;
regs->rax = return_value;
dest_ml->tr_fsbase = src_ml->tr_fsbase;
dest_ml->tr_gsbase = src_ml->tr_gsbase;
printk("clone cs=%x, ss=%x, rip=%zx", regs->cs, regs->ss, regs->rip);
return KERN_OK;
}