ptrace_syscalls/
types.rs

1//! This module contains the lowel level types used in syscalls that are not defined in libc crate.
2
3#![allow(non_camel_case_types)]
4
5mod dst;
6
7pub use dst::*;
8
9use std::ffi::c_void;
10
11use nix::libc::{c_char, c_int, c_long, c_uint, c_ulong, c_ushort, ino64_t, off64_t, off_t, sigset_t, size_t};
12
13pub type key_serial_t = i32; // https://github.com/Distrotech/keyutils/blob/9d52b8ab86931fb5a66fa5b567ea01875f31016e/keyutils.h#L22
14
15#[derive(Debug, Clone, Copy, PartialEq)]
16#[repr(C)]
17pub struct cap_user_header {
18  pub version: u32,
19  pub pid: c_int,
20}
21
22#[derive(Debug, Clone, PartialEq)]
23#[repr(C)]
24pub struct cap_user_data {
25  pub effective: u32,
26  pub permitted: u32,
27  pub inheritable: u32,
28}
29
30#[derive(Debug, Clone, PartialEq)]
31#[repr(C)]
32pub struct futex_waitv {
33  pub val: u64,
34  pub uaddr: u64,
35  pub flags: u32,
36  pub __reserved: u32,
37}
38
39#[derive(Debug, Clone, PartialEq)]
40#[repr(C)]
41pub struct robust_list {
42  pub next: *mut robust_list,
43}
44
45#[derive(Debug, Clone, PartialEq)]
46#[repr(C)]
47pub struct robust_list_head {
48  pub list: robust_list,
49  pub futex_offset: c_long,
50  pub list_op_pending: *mut robust_list,
51}
52
53#[cfg(target_arch = "x86_64")]
54#[derive(Debug, Clone, PartialEq)]
55#[repr(C)]
56pub struct user_desc {
57  pub entry_number: c_uint,
58  pub base_addr: c_uint,
59  pub limit: c_uint,
60  pub bitflags: c_uint,
61}
62
63#[derive(Debug, Clone, PartialEq)]
64#[repr(C)]
65pub struct linux_dirent {
66  pub d_ino: c_ulong,
67  pub d_off: off_t,
68  pub d_reclen: c_ushort,
69  pub d_name: *mut c_char,
70}
71
72#[derive(Debug, Clone, PartialEq)]
73#[repr(C)]
74pub struct linux_dirent64 {
75  pub d_ino: ino64_t,
76  pub d_off: off64_t,
77  pub d_reclen: c_ushort,
78  pub d_type: c_char,
79  pub d_name: *mut c_char,
80}
81
82#[derive(Debug, Clone, PartialEq)]
83#[repr(C)]
84pub struct timezone {
85  pub tz_minuteswest: c_int,
86  pub tz_dsttime: c_int,
87}
88
89pub type aio_context_t = c_ulong;
90
91#[derive(Debug, Clone, PartialEq)]
92#[repr(C)]
93pub struct io_event {
94  pub data: u64,
95  pub obj: u64,
96  pub res: i64,
97  pub res2: i64,
98}
99
100#[derive(Debug, Clone, PartialEq)]
101#[repr(C)]
102pub struct __aio_sigset {
103  pub sigmask: *const sigset_t,
104  pub sigsetsize: size_t,
105}
106
107#[derive(Debug, Clone, PartialEq)]
108#[repr(C)]
109pub struct io_uring_params {
110  pub sq_entries: u32,
111  pub cq_entries: u32,
112  pub flags: u32,
113  pub sq_thread_cpu: u32,
114  pub sq_thread_idle: u32,
115  pub features: u32,
116  pub wq_fd: i32,
117  pub resv: [u32; 3],
118  pub sq_off: io_sqring_offsets,
119  pub cq_off: io_cqring_offsets,
120}
121
122#[derive(Debug, Clone, PartialEq)]
123#[repr(C)]
124pub struct io_sqring_offsets {
125  pub head: u32,
126  pub tail: u32,
127  pub ring_mask: u32,
128  pub ring_entries: u32,
129  pub flags: u32,
130  pub dropped: u32,
131  pub array: u32,
132  pub resv1: u32,
133  pub user_addr: u64,
134}
135
136#[derive(Debug, Clone, PartialEq)]
137#[repr(C)]
138pub struct io_cqring_offsets {
139  pub head: u32,
140  pub tail: u32,
141  pub ring_mask: u32,
142  pub ring_entries: u32,
143  pub overflow: u32,
144  pub cqes: u32,
145  pub flags: u32,
146  pub resv1: u32,
147  pub user_addr: u64,
148}
149
150#[derive(Debug, Clone, PartialEq)]
151#[repr(C)]
152pub struct kexec_segment {
153  pub buf: *mut c_void,
154  pub bufsz: size_t,
155  pub mem: *mut c_void,
156  pub memsz: size_t,
157}
158
159#[derive(Debug, Clone, Copy, PartialEq)]
160#[repr(C)]
161pub enum landlock_rule_type {
162  LANDLOCK_RULE_PATH_BENEATH = 1,
163  LANDLOCK_RULE_NET_PORT,
164}
165
166#[derive(Debug, Clone, PartialEq)]
167#[repr(C, packed)]
168pub struct landlock_path_beneath_attr {
169  pub allowed_access: u64,
170  pub parent_fd: i32,
171}
172
173#[derive(Debug, Clone, PartialEq)]
174#[repr(C)]
175pub struct landlock_ruleset_attr {
176  pub handled_access_fs: u64,
177}
178
179#[derive(Debug, Clone, PartialEq)]
180#[repr(C)]
181pub struct __mount_arg {
182  pub mnt_id: u64,
183  pub request_mask: u64,
184}
185
186// Can't make a sane struct with DST array member in rust
187// #[derive(Debug, Clone, PartialEq)]
188// #[repr(C)]
189// pub struct lsm_ctx {
190//   id: u64,
191//   flags: u64,
192//   len: u64,
193//   ctx_len: u64,
194//   ctx: [u8; ctx_len],
195// }
196
197pub type qid_t = c_uint;
198
199#[cfg(target_arch = "riscv64")]
200#[derive(Debug, Clone, PartialEq)]
201#[repr(C)]
202pub struct riscv_hwprobe {
203  pub key: i64,
204  pub value: u64,
205}
206
207#[derive(Debug, Clone, PartialEq)]
208#[repr(C)]
209pub struct mnt_id_req {
210  pub size: u32,
211  pub spare: u32,
212  pub mnt_id: u64,
213  pub param: u64,
214}
215
216#[derive(Debug, Clone, PartialEq)]
217#[repr(C)]
218pub struct ustat {
219  pub f_tfree: c_int,
220  pub f_tinode: ino64_t,
221  pub f_fname: [c_char; 6],
222  pub f_fpack: [c_char; 6],
223}
224
225#[derive(Debug, Clone, PartialEq)]
226#[repr(C)]
227pub struct cachestat_range {
228  pub off: u64,
229  pub len: u64,
230}
231
232#[derive(Debug, Clone, PartialEq)]
233#[repr(C)]
234pub struct cachestat {
235  pub nr_cache: u64,
236  pub nr_dirty: u64,
237  pub nr_writeback: u64,
238  pub nr_evicted: u64,
239  pub nr_recently_evicted: u64,
240}