1#![allow(non_camel_case_types)]
2use std::ffi::{c_char, c_int, c_uint, c_void};
7
8pub type scmp_filter_ctx = *mut c_void;
10
11#[repr(C)]
13pub struct seccomp_data {
14 pub nr: c_int,
15 pub arch: u32,
16 pub instruction_pointer: u64,
17 pub args: [u64; 6],
18}
19
20#[repr(C)]
22pub struct seccomp_notif {
23 pub id: u64,
24 pub pid: u32,
25 pub flags: u32,
26 pub data: seccomp_data,
27}
28
29#[repr(C)]
31pub struct seccomp_notif_resp {
32 pub id: u64,
33 pub val: i64,
34 pub error: i32,
35 pub flags: u32,
36}
37
38pub static SCMP_ACT_KILL_PROCESS: u32 = 0x80000000;
40
41pub static SCMP_ACT_KILL_THREAD: u32 = 0x00000000;
43
44pub static SCMP_ACT_TRAP: u32 = 0x00030000;
46
47pub static SCMP_ACT_NOTIFY: u32 = 0x7fc00000;
49
50pub static SCMP_ACT_LOG: u32 = 0x7ffc0000;
52
53pub static SCMP_ACT_ALLOW: u32 = 0x7fff0000;
55
56#[repr(C)]
58pub enum scmp_filter_attr {
59 SCMP_FLTATR_ACT_BADARCH = 2,
60 SCMP_FLTATR_CTL_NNP = 3,
61 SCMP_FLTATR_CTL_TSYNC = 4,
62 SCMP_FLTATR_API_TSKIP = 5,
63 SCMP_FLTATR_CTL_LOG = 6,
64 SCMP_FLTATR_CTL_SSB = 7,
65 SCMP_FLTATR_CTL_OPTIMIZE = 8,
66 SCMP_FLTATR_API_SYSRAWRC = 9,
67}
68
69#[link(name = "seccomp")]
70unsafe extern "C" {
71
72 pub fn seccomp_api_get() -> c_uint;
85
86 pub fn seccomp_init(def_action: u32) -> scmp_filter_ctx;
88
89 pub fn seccomp_release(ctx: scmp_filter_ctx);
91
92 pub fn seccomp_attr_set(ctx: scmp_filter_ctx, attr: scmp_filter_attr, value: u32) -> c_int;
94
95 pub fn seccomp_syscall_resolve_name(name: *const c_char) -> c_int;
97
98 pub fn seccomp_syscall_resolve_num_arch(arch_token: u32, num: c_int) -> *mut c_char;
100
101 pub fn seccomp_syscall_resolve_name_arch(arch_token: u32, name: *const c_char) -> c_int;
102
103 pub fn seccomp_arch_native() -> u32;
105
106 pub fn seccomp_rule_add(
108 ctx: scmp_filter_ctx,
109 action: u32,
110 syscall: c_int,
111 arg_cnt: c_uint,
112 ...
113 ) -> c_int;
114
115 pub fn seccomp_set_priority(ctx: scmp_filter_attr, syscall: c_int, priority: u8) -> c_int;
117
118 pub fn seccomp_export_bpf(ctx: scmp_filter_ctx, fd: c_int) -> c_int;
120
121 pub fn seccomp_load(ctx: scmp_filter_ctx) -> c_int;
123
124 pub fn seccomp_notify_alloc(
126 req: *mut *mut seccomp_notif,
127 resp: *mut *mut seccomp_notif_resp,
128 ) -> c_int;
129
130 pub fn seccomp_notify_free(req: *mut seccomp_notif, resp: *mut seccomp_notif_resp);
132
133 pub fn seccomp_notify_receive(fd: c_int, req: *mut seccomp_notif) -> c_int;
135
136 pub fn seccomp_notify_respond(fd: c_int, resp: *mut seccomp_notif_resp) -> c_int;
138
139 pub fn seccomp_notify_id_valid(fd: c_int, id: u64) -> c_int;
141
142 pub fn seccomp_notify_fd(ctx: scmp_filter_ctx) -> c_int;
144}