| 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/::cvtrust-analyzer cargo libseccomp 0.4.0 cvt().; |
| 7 | 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#; |
| 8 | use craterust-analyzer cargo libseccomp 0.4.0 crate/::{ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#, ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#, ScmpVersionrust-analyzer cargo libseccomp 0.4.0 version/ScmpVersion#}; |
| 9 | use libseccomp_sysrust-analyzer cargo libseccomp-sys 0.3.0 crate/::*; |
| 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_staterust-analyzer cargo libseccomp 0.4.0 functions/reset_global_state().() -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<()> { |
| 38 | cvtrust-analyzer cargo libseccomp 0.4.0 cvt().(unsafe { seccomp_resetrust-analyzer cargo libseccomp-sys 0.3.0 seccomp_reset().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core 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_archrust-analyzer cargo libseccomp 0.4.0 functions/get_syscall_name_from_arch().(arch: ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#, syscall: i32) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 56 | ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#::from_sysrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_sys().(syscall).get_name_by_archrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]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_namerust-analyzer cargo libseccomp 0.4.0 functions/get_syscall_from_name().(name: &str, arch: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#>) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<i32> { |
| 76 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#::from_name_by_archrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]from_name_by_arch().(name, arch.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#::Nativerust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#Native#))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..to_sysrust-analyzer cargo libseccomp 0.4.0 syscall/impl#[ScmpSyscall]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_versionrust-analyzer cargo libseccomp 0.4.0 functions/get_library_version().() -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<ScmpVersionrust-analyzer cargo libseccomp 0.4.0 version/ScmpVersion#> { |
| 82 | ScmpVersionrust-analyzer cargo libseccomp 0.4.0 version/ScmpVersion#::currentrust-analyzer cargo libseccomp 0.4.0 version/impl#[ScmpVersion]current().() |
| 83 | } |