From 17d447ff6fc03fb73ed7e74742c4f27e595f690f Mon Sep 17 00:00:00 2001 From: Harry Cheng Date: Mon, 29 Jul 2019 18:54:54 +0800 Subject: [PATCH] Add vsyscall emulation --- kernel/src/arch/x86_64/interrupt/handler.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kernel/src/arch/x86_64/interrupt/handler.rs b/kernel/src/arch/x86_64/interrupt/handler.rs index 0996b53..e1892a2 100644 --- a/kernel/src/arch/x86_64/interrupt/handler.rs +++ b/kernel/src/arch/x86_64/interrupt/handler.rs @@ -133,6 +133,10 @@ fn page_fault(tf: &mut TrapFrame) { asm!("mov %cr2, $0" : "=r" (addr)); } + if vsyscall(addr, tf) { + return; + } + bitflags! { struct PageError: u8 { const PRESENT = 1 << 0; @@ -162,6 +166,20 @@ fn page_fault(tf: &mut TrapFrame) { error(tf); } +fn vsyscall(addr: usize, tf: &mut TrapFrame) -> bool { + let id: usize = match addr { + 0xffffffffff600000 => 96, + _ => return false + }; + debug!("vsyscall emulation"); + let caller = unsafe { (tf.rsp as *mut u32).read() }; + let ret = crate::syscall::syscall(id, [tf.rdi, tf.rsi, tf.rdx, tf.r10, tf.r8, tf.r9], tf); + tf.rip = caller as usize; + tf.rax = ret as usize; + tf.rsp += 8; + true +} + fn keyboard() { use crate::arch::driver::keyboard; use pc_keyboard::{DecodedKey, KeyCode};