Debian Codegraph @

src/functions.rs

raw symbols SCIP
1 // SPDX-License-Identifier: Apache-2.0 or MIT
2 //
3 // Copyright 2021 Sony Group Corporation
4 //
5
6 use crate::cvt;
7 use crate::error::Result;
8 use crate::{ScmpArch, ScmpSyscall, ScmpVersion};
9 use libseccomp_sys::*;
10
11 /// Resets the libseccomp library's global state.
12 ///
13 /// This function resets the (internal) global state of the libseccomp library,
14 /// this includes any notification file descriptors retrieved by
15 /// [`get_notify_fd`](crate::ScmpFilterContext::get_notify_fd).
16 /// Normally you do not need this but it may be required to continue using
17 /// the libseccomp library after a `fork()`/`clone()` to ensure the API level
18 /// and user notification state is properly reset.
19 ///
20 /// This function corresponds to
21 /// [`seccomp_reset`](https://man7.org/linux/man-pages/man3/seccomp_reset.3.html).
22 ///
23 /// # Errors
24 ///
25 /// If the linked libseccomp library is older than v2.5.1 this function will
26 /// return an error.
27 ///
28 /// # Examples
29 ///
30 /// ```
31 /// # use libseccomp::*;
32 /// # if check_version(ScmpVersion::from((2, 5, 1)))? {
33 /// reset_global_state()?;
34 /// # }
35 /// # Ok::<(), Box<dyn std::error::Error>>(())
36 /// ```
37 pub fn reset_global_state() -> Result<()> {
38 cvt(unsafe { seccomp_reset(std::ptr::null_mut(), 0) })
39 }
40
41 /// Retrieves the name of a syscall from its number for a given architecture.
42 ///
43 /// This function returns a string containing the name of the syscall.
44 ///
45 /// # Arguments
46 ///
47 /// * `arch` - A valid architecture token
48 /// * `syscall` - The number of syscall
49 ///
50 /// # Errors
51 ///
52 /// If the syscall is unrecognized or an issue occurs or an issue is
53 /// encountered getting the name of the syscall, an error will be returned.
54 #[deprecated(since = "0.2.3", note = "Use ScmpSyscall::get_name_by_arch instead.")]
55 pub fn get_syscall_name_from_arch(arch: ScmpArch, syscall: i32) -> Result<String> {
56 ScmpSyscall::from_sys(syscall).get_name_by_arch(arch)
57 }
58
59 /// Gets the number of a syscall by name for a given architecture's ABI.
60 ///
61 /// This function returns the number of the syscall.
62 ///
63 /// # Arguments
64 ///
65 /// * `name` - The name of a syscall
66 /// * `arch` - An architecture token as `Option` type
67 /// If arch argument is `None`, the functions returns the number of a syscall
68 /// on the kernel's native architecture.
69 ///
70 /// # Errors
71 ///
72 /// If an invalid string for the syscall name is specified or a syscall with that
73 /// name is not found, an error will be returned.
74 #[deprecated(since = "0.2.3", note = "Use ScmpSyscall::from_name* instead.")]
75 pub fn get_syscall_from_name(name: &str, arch: Option<ScmpArch>) -> Result<i32> {
76 Ok(ScmpSyscall::from_name_by_arch(name, arch.unwrap_or(ScmpArch::Native))?.to_sys())
77 }
78
79 /// Deprecated alias for [`ScmpVersion::current()`].
80 #[deprecated(since = "0.2.0", note = "Use ScmpVersion::current().")]
81 pub fn get_library_version() -> Result<ScmpVersion> {
82 ScmpVersion::current()
83 }