diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /third_party/rust/nix/src/sys/prctl.rs | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/nix/src/sys/prctl.rs')
-rw-r--r-- | third_party/rust/nix/src/sys/prctl.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/third_party/rust/nix/src/sys/prctl.rs b/third_party/rust/nix/src/sys/prctl.rs index 995382cb0c..42324beab2 100644 --- a/third_party/rust/nix/src/sys/prctl.rs +++ b/third_party/rust/nix/src/sys/prctl.rs @@ -50,7 +50,9 @@ pub fn get_child_subreaper() -> Result<bool> { // prctl writes into this var let mut subreaper: c_int = 0; - let res = unsafe { libc::prctl(libc::PR_GET_CHILD_SUBREAPER, &mut subreaper, 0, 0, 0) }; + let res = unsafe { + libc::prctl(libc::PR_GET_CHILD_SUBREAPER, &mut subreaper, 0, 0, 0) + }; Errno::result(res).map(|_| subreaper != 0) } @@ -78,7 +80,9 @@ pub fn get_keepcaps() -> Result<bool> { /// Clear the thread memory corruption kill policy and use the system-wide default pub fn clear_mce_kill() -> Result<()> { - let res = unsafe { libc::prctl(libc::PR_MCE_KILL, libc::PR_MCE_KILL_CLEAR, 0, 0, 0) }; + let res = unsafe { + libc::prctl(libc::PR_MCE_KILL, libc::PR_MCE_KILL_CLEAR, 0, 0, 0) + }; Errno::result(res).map(drop) } @@ -151,10 +155,11 @@ pub fn get_name() -> Result<CString> { let res = unsafe { libc::prctl(libc::PR_GET_NAME, &buf, 0, 0, 0) }; - let len = buf.iter().position(|&c| c == 0).unwrap_or(buf.len()); - let name = CStr::from_bytes_with_nul(&buf[..=len]).map_err(|_| Errno::EINVAL)?; - - Errno::result(res).map(|_| name.to_owned()) + Errno::result(res).and_then(|_| { + CStr::from_bytes_until_nul(&buf) + .map(CStr::to_owned) + .map_err(|_| Errno::EINVAL) + }) } /// Sets the timer slack value for the calling thread. Timer slack is used by the kernel to group @@ -174,14 +179,16 @@ pub fn get_timerslack() -> Result<i32> { /// Disable all performance counters attached to the calling process. pub fn task_perf_events_disable() -> Result<()> { - let res = unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_DISABLE, 0, 0, 0, 0) }; + let res = + unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_DISABLE, 0, 0, 0, 0) }; Errno::result(res).map(drop) } /// Enable all performance counters attached to the calling process. pub fn task_perf_events_enable() -> Result<()> { - let res = unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_ENABLE, 0, 0, 0, 0) }; + let res = + unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_ENABLE, 0, 0, 0, 0) }; Errno::result(res).map(drop) } |