1use crate::plugin_import;
3use crate::plugins::glib::{GBox, GBoxedSlice};
4use crate::sys::{target_pid_t, target_ptr_t, target_ulong, CPUState};
5
6use std::borrow::Cow;
7use std::ffi::CStr;
8
9use glib_sys::GArray;
10
11plugin_import! {
12 static OSI: Osi = extern "osi" {
13 fn get_process_handles(cpu: *mut CPUState) -> GBoxedSlice<OsiProcHandle>;
14 fn get_current_thread(cpu: *mut CPUState) -> GBox<OsiThread>;
15 fn get_modules(cpu: *mut CPUState) -> GBoxedSlice<OsiModule>;
16 fn get_mappings(cpu: *mut CPUState, p: *mut OsiProc) -> GBoxedSlice<OsiModule>;
17 fn get_processes(cpu: *mut CPUState) -> GBoxedSlice<OsiProc>;
18 fn get_current_process(cpu: *mut CPUState) -> Option<GBox<OsiProc>>;
19 fn get_one_module(osimodules: *mut GArray, idx: ::std::os::raw::c_uint) -> *mut OsiModule;
20 fn get_one_proc(osiprocs: *mut GArray, idx: ::std::os::raw::c_uint) -> *mut OsiProc;
21 fn cleanup_garray(g: *mut GArray);
22 fn get_current_process_handle(cpu: *mut CPUState) -> GBox<OsiProcHandle>;
23 fn get_process(cpu: *mut CPUState, h: *const OsiProcHandle) -> GBox<OsiProc>;
24 fn get_process_pid(cpu: *mut CPUState, h: *const OsiProcHandle) -> target_pid_t;
25 fn get_process_ppid(cpu: *mut CPUState, h: *const OsiProcHandle) -> target_pid_t;
26 fn in_shared_object(cpu: *mut CPUState, h: *const OsiProc) -> bool;
27 };
28}
29
30#[doc = " Minimal handle for a process. Contains a unique identifier \\p asid"]
31#[doc = " and a task descriptor pointer \\p taskd that can be used to retrieve the full"]
32#[doc = " details of the process."]
33#[repr(C)]
34#[derive(Debug, Copy, Clone)]
35pub struct osi_proc_handle_struct {
36 pub taskd: target_ptr_t,
37 pub asid: target_ptr_t,
38}
39#[doc = " Minimal handle for a process. Contains a unique identifier \\p asid"]
40#[doc = " and a task descriptor pointer \\p taskd that can be used to retrieve the full"]
41#[doc = " details of the process."]
42pub type OsiProcHandle = osi_proc_handle_struct;
43#[doc = " Minimal information about a process thread."]
44#[doc = " Address space and open resources are shared between threads"]
45#[doc = " of the same process. This information is stored in OsiProc."]
46#[repr(C)]
47#[derive(Debug, Copy, Clone)]
48pub struct osi_thread_struct {
49 pub pid: target_pid_t,
50 pub tid: target_pid_t,
51}
52#[doc = " Minimal information about a process thread."]
53#[doc = " Address space and open resources are shared between threads"]
54#[doc = " of the same process. This information is stored in OsiProc."]
55pub type OsiThread = osi_thread_struct;
56#[doc = " Represents a page in the address space of a process."]
57#[doc = ""]
58#[doc = " This has not been implemented/used so far."]
59#[repr(C)]
60#[derive(Debug, Copy, Clone)]
61pub struct osi_page_struct {
62 pub start: target_ptr_t,
63 pub len: target_ulong,
64}
65#[doc = " Represents a page in the address space of a process."]
66#[doc = ""]
67#[doc = " This has not been implemented/used so far."]
68pub type OsiPage = osi_page_struct;
69#[doc = " Represents information about a guest OS module (kernel module"]
70#[doc = " or shared library)."]
71#[repr(C)]
72#[derive(Debug, Copy, Clone)]
73pub struct osi_module_struct {
74 pub modd: target_ptr_t,
75 pub base: target_ptr_t,
76 pub size: target_ptr_t,
77 pub file: *mut ::std::os::raw::c_char,
78 pub name: *mut ::std::os::raw::c_char,
79}
80#[doc = " Represents information about a guest OS module (kernel module"]
81#[doc = " or shared library)."]
82pub type OsiModule = osi_module_struct;
83#[doc = " Detailed information for a process."]
84#[repr(C)]
85#[derive(Debug, Copy, Clone)]
86pub struct osi_proc_struct {
87 pub taskd: target_ptr_t,
88 pub pgd: target_ptr_t,
89 pub asid: target_ptr_t,
90 pub pid: target_pid_t,
91 pub ppid: target_pid_t,
92 pub name: *mut ::std::os::raw::c_char,
93 pub pages: *mut OsiPage,
94 pub create_time: u64,
95}
96#[doc = " Detailed information for a process."]
97pub type OsiProc = osi_proc_struct;
98
99impl osi_proc_struct {
100 pub fn get_name(&self) -> Cow<str> {
101 if self.name.is_null() {
102 "".into()
103 } else {
104 unsafe { CStr::from_ptr(self.name) }.to_string_lossy()
105 }
106 }
107}