double faulting in thread start while pushing thread's general registers
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
5a4f8a561e
commit
2522ece23f
@ -53,23 +53,28 @@ impl Thread {
|
|||||||
unsafe {
|
unsafe {
|
||||||
Thread {
|
Thread {
|
||||||
id: ThreadId::new(),
|
id: ThreadId::new(),
|
||||||
rsp: alloc(Layout::new::<[u8; STACK_SIZE]>()) as u64,
|
rsp: alloc(Layout::new::<[u8; STACK_SIZE]>()) as u64 + STACK_SIZE as u64 - 0x80,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start(&mut self, rip: u64) {
|
pub async fn start(&mut self, rip: u64) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
*RUNNING_THREAD.lock().await = self.id;
|
||||||
asm!(
|
asm!(
|
||||||
"pusha", // Save current thread regs
|
"push rax", // Save current thread regs
|
||||||
|
"push rbx",
|
||||||
|
"push rcx",
|
||||||
|
"push rdx",
|
||||||
|
"push rbp",
|
||||||
|
"push rsi",
|
||||||
|
"push rdi",
|
||||||
|
|
||||||
"push rsp", // Recover current rsp
|
"push rsp", // Recover current rsp
|
||||||
"pop {out}",
|
"pop {out}",
|
||||||
out = out(reg) self.rsp, // Save current rsp
|
out = out(reg) KERNEL_THREAD.lock().await.rsp, // Save current rsp
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
*RUNNING_THREAD.lock().await = self.id;
|
|
||||||
unsafe {
|
|
||||||
asm!(
|
asm!(
|
||||||
"push {rsp}",
|
"push {rsp}",
|
||||||
"pop rsp",
|
"pop rsp",
|
||||||
@ -83,10 +88,17 @@ impl Thread {
|
|||||||
pub async fn run(&mut self) {
|
pub async fn run(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(
|
asm!(
|
||||||
"pusha", // Save current thread regs
|
"push rax", // Save current thread regs
|
||||||
|
"push rbx",
|
||||||
|
"push rcx",
|
||||||
|
"push rdx",
|
||||||
|
"push rbp",
|
||||||
|
"push rsi",
|
||||||
|
"push rdi",
|
||||||
|
|
||||||
"push rsp", // Recover current rsp
|
"push rsp", // Recover current rsp
|
||||||
"pop {out}",
|
"pop {out}",
|
||||||
out = out(reg) self.rsp, // Save current rsp
|
out = out(reg) KERNEL_THREAD.lock().await.rsp, // Save current rsp
|
||||||
);
|
);
|
||||||
|
|
||||||
*RUNNING_THREAD.lock().await = self.id; // change running thread
|
*RUNNING_THREAD.lock().await = self.id; // change running thread
|
||||||
@ -94,7 +106,14 @@ impl Thread {
|
|||||||
asm!(
|
asm!(
|
||||||
"push {rsp}", // Set stack pointer to the new thread
|
"push {rsp}", // Set stack pointer to the new thread
|
||||||
"pop rsp",
|
"pop rsp",
|
||||||
"popa", // Restore new thread regs
|
|
||||||
|
"pop rdi", // Restore new thread regs
|
||||||
|
"pop rsi",
|
||||||
|
"pop rbp",
|
||||||
|
"pop rdx",
|
||||||
|
"pop rcx",
|
||||||
|
"pop rbx",
|
||||||
|
"pop rax",
|
||||||
rsp = in(reg) self.rsp,
|
rsp = in(reg) self.rsp,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user