Debian Codegraph @

src/syscall.rs

raw symbols SCIP
1 // SPDX-License-Identifier: Apache-2.0 or MIT
2 //
3 // Copyright 2021 Sony Group Corporation
4 //
5
6 use craterust-analyzer cargo libseccomp 0.4.0 crate/::errorrust-analyzer cargo libseccomp 0.4.0 error/::{Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#, SeccompErrorrust-analyzer cargo libseccomp 0.4.0 error/SeccompError#};
7 use craterust-analyzer cargo libseccomp 0.4.0 crate/::ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#;
8 use libseccomp_sysrust-analyzer cargo libseccomp-sys 0.3.0 crate/::*;
9 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#;
10 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
11 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#;
12
13 #[cfg(feature = "const-syscall")]
14 cfg_ifrust-analyzer cargo cfg-if 1.0.4 crate/::cfg_ifrust-analyzer cargo cfg-if 1.0.4 cfg_if!! {
15 if #[cfg(target_arch = "x86_64")] {
16 mod x86_64rust-analyzer cargo libseccomp 0.4.0 syscall/x86_64/;
17 use x86_64rust-analyzer cargo libseccomp 0.4.0 syscall/x86_64/::SYSCALLSrust-analyzer cargo libseccomp 0.4.0 syscall/x86_64/SYSCALLS.;
18 } else if #[cfg(target_arch = "aarch64")] {
19 mod aarch64;
20 use aarch64::SYSCALLS;
21 } else if #[cfg(target_arch = "arm")] {
22 mod arm;
23 use arm::SYSCALLS;
24 } else if #[cfg(target_arch = "loongarch64")] {
25 mod loongarch64;
26 use loongarch64::SYSCALLS;
27 } else if #[cfg(target_arch = "m68k")] {
28 mod m68k;
29 use m68k::SYSCALLS;
30 } else if #[cfg(target_arch = "mips")] {
31 mod mips;
32 use mips::SYSCALLS;
33 } else if #[cfg(target_arch = "mips64")] {
34 mod mips64;
35 use mips64::SYSCALLS;
36 } else if #[cfg(target_arch = "powerpc")] {
37 mod powerpc;
38 use powerpc::SYSCALLS;
39 } else if #[cfg(target_arch = "powerpc64")] {
40 mod powerpc64;
41 use powerpc64::SYSCALLS;
42 } else if #[cfg(target_arch = "riscv64")] {
43 mod riscv64;
44 use riscv64::SYSCALLS;
45 } else if #[cfg(target_arch = "s390x")] {
46 mod s390x;
47 use s390x::SYSCALLS;
48 } else if #[cfg(target_arch = "x86")] {
49 mod x86;
50 use x86::SYSCALLS;
51 } else {
52 compile_error!("Looks like your target_arch is not supported by libseccomp.");
53 }
54 }
55
56 /// A raw syscall as used by the OS.
57 pub type RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall# = libcrust-analyzer cargo libc 0.2.189 crate/::c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#;
58
59 /// Represents a syscall number.
60 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
61 pub struct ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall# {
62 nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr.: i32,
63 }
64 impl ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall# {
65 pub(craterust-analyzer cargo libseccomp 0.4.0 crate/) fn to_sysrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]to_sys().(self) -> i32 {
66 self.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr.
67 }
68
69 pub(craterust-analyzer cargo libseccomp 0.4.0 crate/) fn from_sysrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_sys().(nr: i32) -> Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall] {
70 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall] { nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr. }
71 }
72
73 /// Resolves a syscall name to `ScmpSyscall`.
74 ///
75 /// This function returns a `ScmpSyscall` that can be passed to
76 /// [`add_rule`](crate::ScmpFilterContext::add_rule) like functions.
77 /// Or `ScmpSyscall::from(libseccomp_sys::__NR_SCMP_ERROR)` if name is unknown.
78 ///
79 /// Unlike [`from_name`](Self::from_name) this function does not any FFI call
80 /// and can therefore be `const`.
81 ///
82 /// # Arguments
83 ///
84 /// * `name` - The name of a syscall
85 ///
86 /// # Examples
87 ///
88 /// ```
89 /// # use libseccomp::*;
90 /// let syscall = ScmpSyscall::new("chroot");
91 /// ```
92 #[cfg(feature = "const-syscall")]
93 #[cfg_attr(docsrs, doc(cfg(feature = "const-syscall")))]
94 pub const fn newrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]new().(name: &str) -> Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall] {
95 let mut i = 0;
96 let nr = loop {
97 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().SYSCALLSrust-analyzer cargo libseccomp 0.4.0 syscall/x86_64/SYSCALLS..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
98 break libseccomp_sysrust-analyzer cargo libseccomp-sys 0.3.0 crate/::__NR_SCMP_ERRORrust-analyzer cargo libseccomp-sys 0.3.0 __NR_SCMP_ERROR.;
99 }
100 if strcmprust-analyzer cargo libseccomp 0.4.0 syscall/strcmp().(SYSCALLSrust-analyzer cargo libseccomp 0.4.0 syscall/x86_64/SYSCALLS.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..0, name) {
101 break SYSCALLSrust-analyzer cargo libseccomp 0.4.0 syscall/x86_64/SYSCALLS.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..1;
102 }
103 i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
104 };
105
106 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall] { nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr. }
107 }
108
109 /// Resolves a syscall name to `ScmpSyscall`.
110 ///
111 /// This function returns a `ScmpSyscall` that can be passed to
112 /// [`add_rule`](crate::ScmpFilterContext::add_rule) like functions.
113 ///
114 /// This function corresponds to
115 /// [`seccomp_syscall_resolve_name`](https://man7.org/linux/man-pages/man3/seccomp_syscall_resolve_name.3.html).
116 ///
117 /// # Arguments
118 ///
119 /// * `name` - The name of a syscall
120 ///
121 /// # Errors
122 ///
123 /// If an invalid string for the syscall name is specified or a syscall with that
124 /// name is not found, an error will be returned.
125 ///
126 /// # Examples
127 ///
128 /// ```
129 /// # use libseccomp::*;
130 /// let syscall = ScmpSyscall::from_name("chroot")?;
131 /// # Ok::<(), Box<dyn std::error::Error>>(())
132 /// ```
133 pub fn from_namerust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name().(name: &str) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]> {
134 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]::from_name_by_archrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name_by_arch().(name, ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#::Nativerust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#Native#)
135 }
136
137 /// Resolves a syscall name to `ScmpSyscall`.
138 ///
139 /// NOTE: If you call this function with a foreign architecture token and pass the result
140 /// to [`add_rule*`](crate::ScmpFilterContext::add_rule) functions you get unexpected results.
141 ///
142 /// This function returns a `ScmpSyscall` for the specified architecture.
143 ///
144 /// This function corresponds to
145 /// [`seccomp_syscall_resolve_name_arch`](https://man7.org/linux/man-pages/man3/seccomp_syscall_resolve_name_arch.3.html).
146 ///
147 /// # Arguments
148 ///
149 /// * `name` - The name of a syscall
150 /// * `arch` - An architecture token
151 ///
152 /// # Errors
153 ///
154 /// If an invalid string for the syscall name is specified or a syscall with that
155 /// name is not found, an error will be returned.
156 ///
157 /// # Examples
158 ///
159 /// ```
160 /// # use libseccomp::*;
161 /// let syscall = ScmpSyscall::from_name_by_arch("chroot", ScmpArch::Aarch64)?;
162 /// # Ok::<(), Box<dyn std::error::Error>>(())
163 /// ```
164 pub fn from_name_by_archrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name_by_arch().(name: &str, arch: ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]> {
165 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]::from_name_by_implrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name_by_impl().(seccomp_syscall_resolve_name_archrust-analyzer cargo libseccomp-sys 0.3.0 seccomp_syscall_resolve_name_arch()., name, arch)
166 }
167
168 /// Resolves a syscall name to `ScmpSyscall`.
169 ///
170 /// This function returns a `ScmpSyscall` for the specified architecture
171 /// rewritten if necessary.
172 ///
173 /// This function corresponds to
174 /// [`seccomp_syscall_resolve_name_rewrite`](https://man7.org/linux/man-pages/man3/seccomp_syscall_resolve_name_rewrite.3.html).
175 ///
176 /// # Arguments
177 ///
178 /// * `name` - The name of a syscall
179 /// * `arch` - An architecture token
180 ///
181 /// # Errors
182 ///
183 /// If an invalid string for the syscall name is specified or a syscall with that
184 /// name is not found, an error will be returned.
185 ///
186 /// # Examples
187 ///
188 /// ```
189 /// # use libseccomp::*;
190 /// let syscall = ScmpSyscall::from_name_by_arch_rewrite("socketcall", ScmpArch::X32)?;
191 /// # Ok::<(), Box<dyn std::error::Error>>(())
192 /// ```
193 pub fn from_name_by_arch_rewriterust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name_by_arch_rewrite().(name: &str, arch: ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]> {
194 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]::from_name_by_implrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name_by_impl().(seccomp_syscall_resolve_name_rewriterust-analyzer cargo libseccomp-sys 0.3.0 seccomp_syscall_resolve_name_rewrite()., name, arch)
195 }
196
197 fn from_name_by_implrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name_by_impl().(
198 resolve_name_func: unsafe extern "C" fn(arch_token: u32, name: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#) -> i32,
199 name: &str,
200 arch: ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#,
201 ) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]> {
202 let mut buf = [0_u8; 64];
203 if name.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&b'\0') {
204 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(SeccompErrorrust-analyzer cargo libseccomp 0.4.0 error/SeccompError#::with_msgrust-analyzer cargo libseccomp 0.4.0 error/impl#[SeccompError]with_msg().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
205 "Bad syscall name '{name}': Contains nul-byte.",
206 )));
207 }
208 if buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().name.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() {
209 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(SeccompErrorrust-analyzer cargo libseccomp 0.4.0 error/SeccompError#::with_msgrust-analyzer cargo libseccomp 0.4.0 error/impl#[SeccompError]with_msg().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
210 "Bad syscall name '{name}': Too long.",
211 )));
212 }
213 buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#name.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(name.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
214 debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().name.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., b'\0');
215
216 let nr = unsafe { resolve_name_func(arch.to_sysrust-analyzer cargo libseccomp 0.4.0 arch/impl#[ScmpArch]to_sys().(), buf.as_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]as_slice().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().()) };
217 if nr rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().__NR_SCMP_ERRORrust-analyzer cargo libseccomp-sys 0.3.0 __NR_SCMP_ERROR. {
218 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(SeccompErrorrust-analyzer cargo libseccomp 0.4.0 error/SeccompError#::with_msgrust-analyzer cargo libseccomp 0.4.0 error/impl#[SeccompError]with_msg().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
219 "Could not resolve syscall name {}",
220 name
221 )));
222 }
223
224 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall] { nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr. })
225 }
226
227 /// Resolves this `ScmpSyscall` to it's name for the native architecture.
228 ///
229 /// This function returns a string containing the name of the syscall.
230 ///
231 /// This function corresponds to
232 /// [`seccomp_syscall_resolve_num_arch`](https://man7.org/linux/man-pages/man3/seccomp_syscall_resolve_num_arch.3.html).
233 ///
234 /// # Errors
235 ///
236 /// If the syscall is unrecognized or an issue is encountered getting the
237 /// name of the syscall, an error will be returned.
238 ///
239 /// # Examples
240 ///
241 /// ```
242 /// # use libseccomp::*;
243 /// assert_eq!(
244 /// ScmpSyscall::from_name("mount")?.get_name()?,
245 /// String::from("mount")
246 /// );
247 /// # Ok::<(), Box<dyn std::error::Error>>(())
248 /// ```
249 pub fn get_namerust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]get_name().(self) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
250 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]::get_name_by_archrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]get_name_by_arch().(self, ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#::Nativerust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#Native#)
251 }
252
253 /// Resolves this `ScmpSyscall` to it's name for a given architecture.
254 ///
255 /// This function returns a string containing the name of the syscall.
256 ///
257 /// This function corresponds to
258 /// [`seccomp_syscall_resolve_num_arch`](https://man7.org/linux/man-pages/man3/seccomp_syscall_resolve_num_arch.3.html).
259 ///
260 /// # Arguments
261 ///
262 /// * `arch` - A valid architecture token
263 ///
264 /// # Errors
265 ///
266 /// If the syscall is unrecognized or an issue is encountered getting the
267 /// name of the syscall, an error will be returned.
268 ///
269 /// # Examples
270 ///
271 /// ```
272 /// # use libseccomp::*;
273 /// assert_eq!(
274 /// ScmpSyscall::from_name_by_arch("mount", ScmpArch::Mips)?
275 /// .get_name_by_arch(ScmpArch::Mips)?,
276 /// String::from("mount"),
277 /// );
278 /// # Ok::<(), Box<dyn std::error::Error>>(())
279 /// ```
280 pub fn get_name_by_archrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]get_name_by_arch().(self, arch: ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
281 let ret = unsafe { seccomp_syscall_resolve_num_archrust-analyzer cargo libseccomp-sys 0.3.0 seccomp_syscall_resolve_num_arch().(arch.to_sysrust-analyzer cargo libseccomp 0.4.0 arch/impl#[ScmpArch]to_sys().(), self.to_sysrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]to_sys().()) };
282 if ret.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() {
283 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(SeccompErrorrust-analyzer cargo libseccomp 0.4.0 error/SeccompError#::with_msgrust-analyzer cargo libseccomp 0.4.0 error/impl#[SeccompError]with_msg().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
284 "Could not resolve syscall number {}",
285 self.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr.
286 )));
287 }
288
289 let name = unsafe { CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(ret) }.to_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_str().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
290 unsafe { libcrust-analyzer cargo libc 0.2.189 crate/::freerust-analyzer cargo libc 0.2.189 free().(ret as *mut libcrust-analyzer cargo libc 0.2.189 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#) };
291
292 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(name)
293 }
294
295 /// Returns `true` if this syscall is `__NR_SCMP_ERROR` (`-1`), otherwise `false`.
296 pub fn is_errorrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]is_error().(&self) -> bool {
297 self.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().libseccomp_sysrust-analyzer cargo libseccomp-sys 0.3.0 crate/::__NR_SCMP_ERRORrust-analyzer cargo libseccomp-sys 0.3.0 __NR_SCMP_ERROR.
298 }
299
300 /// Returns `true` if this syscall is `__NR_SCMP_UNDEF` (`-2`), otherwise `false`.
301 pub fn is_undefrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]is_undef().(&self) -> bool {
302 self.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().libseccomp_sysrust-analyzer cargo libseccomp-sys 0.3.0 crate/::__NR_SCMP_UNDEFrust-analyzer cargo libseccomp-sys 0.3.0 __NR_SCMP_UNDEF.
303 }
304
305 /// Creates a `ScmpSyscall` from a `RawSyscall`.
306 pub fn from_raw_syscallrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_raw_syscall().(raw_syscall: RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall#) -> Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall] {
307 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]::fromrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall][`From<i32>`]from().(raw_syscall)
308 }
309
310 /// Returns the `RawSyscall` of this `ScmpSyscall`.
311 pub fn as_raw_syscallrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]as_raw_syscall().(self) -> RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall# {
312 self.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr.
313 }
314 }
315
316 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall#> for ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall# {
317 /// Creates a `ScmpSyscall` from the specified syscall number.
318 ///
319 /// # Arguments
320 ///
321 /// * `nr` - The number of syscall
322 fn fromrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall][`From<i32>`]from().(nr: RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall#) -> Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall][`From<i32>`] {
323 Selfrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall][`From<i32>`]::from_sysrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_sys().(nr)
324 }
325 }
326
327 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#> for RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall# {
328 /// Gets the syscall number of a syscall.
329 ///
330 /// # Arguments
331 ///
332 /// * `syscall` - The syscall
333 fn fromrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[i32][`From<ScmpSyscall>`]from().(syscall: ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#) -> RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall# {
334 syscall.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr.
335 }
336 }
337
338 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall#> for ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall# {
339 fn eqrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall][`PartialEq<i32>`]eq().(&self, other: &RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall#) -> bool {
340 self.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other
341 }
342 }
343
344 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#> for RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall# {
345 fn eqrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[i32][`PartialEq<ScmpSyscall>`]eq().(&self, other: &ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#) -> bool {
346 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().other.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr.
347 }
348 }
349
350 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall# {
351 fn fmtrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
352 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.nrrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#nr.)
353 }
354 }
355
356 /// Compare two strings
357 ///
358 /// This is a helper function because `&str == &str` is not `const` yet.
359 ///
360 /// This function returns the same as `lhs == rhs`.
361 #[cfg(feature = "const-syscall")]
362 const fn strcmprust-analyzer cargo libseccomp 0.4.0 syscall/strcmp().(lhs: &str, rhs: &str) -> bool {
363 if lhs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().rhs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() {
364 return false;
365 }
366 let (lhs, rhs) = (lhs.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), rhs.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
367 let mut i = 0;
368 while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().lhs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() && i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().rhs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
369 if lhs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().rhs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). {
370 return false;
371 }
372 i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
373 }
374 true
375 }