xref: /DragonOS/kernel/src/arch/x86_64/kprobe.rs (revision 7b0ef10895108a0de5ff5ef3d2f93f40cf2e33a5)
1 use crate::arch::interrupt::TrapFrame;
2 
3 pub fn setup_single_step(frame: &mut TrapFrame, step_addr: usize) {
4     frame.rflags |= 0x100;
5     frame.set_pc(step_addr);
6 }
7 
8 pub fn clear_single_step(frame: &mut TrapFrame, return_addr: usize) {
9     frame.rflags &= !0x100;
10     frame.set_pc(return_addr);
11 }
12 
13 #[repr(C)]
14 #[derive(Debug, Copy, Clone)]
15 pub struct KProbeContext {
16     pub r15: ::core::ffi::c_ulong,
17     pub r14: ::core::ffi::c_ulong,
18     pub r13: ::core::ffi::c_ulong,
19     pub r12: ::core::ffi::c_ulong,
20     pub rbp: ::core::ffi::c_ulong,
21     pub rbx: ::core::ffi::c_ulong,
22     pub r11: ::core::ffi::c_ulong,
23     pub r10: ::core::ffi::c_ulong,
24     pub r9: ::core::ffi::c_ulong,
25     pub r8: ::core::ffi::c_ulong,
26     pub rax: ::core::ffi::c_ulong,
27     pub rcx: ::core::ffi::c_ulong,
28     pub rdx: ::core::ffi::c_ulong,
29     pub rsi: ::core::ffi::c_ulong,
30     pub rdi: ::core::ffi::c_ulong,
31     pub orig_rax: ::core::ffi::c_ulong,
32     pub rip: ::core::ffi::c_ulong,
33     pub cs: ::core::ffi::c_ulong,
34     pub eflags: ::core::ffi::c_ulong,
35     pub rsp: ::core::ffi::c_ulong,
36     pub ss: ::core::ffi::c_ulong,
37 }
38 
39 impl From<&TrapFrame> for KProbeContext {
40     fn from(trap_frame: &TrapFrame) -> Self {
41         Self {
42             r15: trap_frame.r15,
43             r14: trap_frame.r14,
44             r13: trap_frame.r13,
45             r12: trap_frame.r12,
46             rbp: trap_frame.rbp,
47             rbx: trap_frame.rbx,
48             r11: trap_frame.r11,
49             r10: trap_frame.r10,
50             r9: trap_frame.r9,
51             r8: trap_frame.r8,
52             rax: trap_frame.rax,
53             rcx: trap_frame.rcx,
54             rdx: trap_frame.rdx,
55             rsi: trap_frame.rsi,
56             rdi: trap_frame.rdi,
57             orig_rax: 0,
58             rip: trap_frame.rip,
59             cs: trap_frame.cs,
60             eflags: trap_frame.rflags,
61             rsp: trap_frame.rsp,
62             ss: trap_frame.ss,
63         }
64     }
65 }
66