1use crate::prelude::*;
2use std::os::raw::c_int;
3use std::ffi::CStr;
4
5pub fn in_kernel_mode(cpu: &mut CPUState) -> bool {
7 unsafe {
8 panda_sys::panda_in_kernel_mode_external(cpu)
9 }
10}
11
12pub fn in_kernel_code_linux(cpu: &mut CPUState) -> bool {
14 unsafe {
15 panda_sys::panda_in_kernel_code_linux_external(cpu)
16 }
17}
18
19pub fn current_asid(cpu: &mut CPUState) -> target_ulong {
21 unsafe {
22 panda_sys::panda_current_asid(cpu)
23 }
24}
25
26pub fn current_pc(cpu: &mut CPUState) -> target_ulong {
28 unsafe {
29 panda_sys::panda_current_pc(cpu)
30 }
31}
32
33pub fn current_sp(cpu: &mut CPUState) -> target_ulong {
35 unsafe {
36 panda_sys::panda_current_sp_external(cpu)
37 }
38}
39
40pub fn current_sp_masked_pagesize(cpu: &mut CPUState, page_size: target_ulong) -> target_ulong {
42 unsafe {
43 panda_sys::panda_current_sp_masked_pagesize_external(cpu, page_size)
44 }
45}
46
47pub fn current_ksp(cpu: &mut CPUState) -> target_ulong {
49 unsafe {
50 panda_sys::panda_current_ksp_external(cpu)
51 }
52}
53
54pub fn get_ret_val(cpu: &mut CPUState) -> target_ulong {
56 unsafe {
57 panda_sys::panda_get_retval_external(cpu)
58 }
59}
60
61pub fn enter_priv(cpu: &mut CPUState) -> bool {
65 unsafe {
66 panda_sys::enter_priv(cpu)
67 }
68}
69
70pub fn exit_priv(cpu: &mut CPUState) {
73 unsafe {
74 panda_sys::exit_priv(cpu)
75 }
76}
77
78pub fn argc() -> c_int {
80 unsafe {
81 panda_sys::panda_argc
82 }
83}
84
85pub fn argv() -> Vec<String> {
87 let mut rs_argv = Vec::new();
88
89 for char_ptr in unsafe { panda_sys::panda_argv }.iter() {
90 if let Ok(str_slice) = unsafe { CStr::from_ptr(*char_ptr) }.to_str() {
91 rs_argv.push(str_slice.to_owned());
92 }
93 }
94
95 rs_argv
96}