Skip to content

Commit

Permalink
shm: Use OnceLock instead of static mut
Browse files Browse the repository at this point in the history
Fixes warning on nightly Rust.
  • Loading branch information
ids1024 authored and cmeissl committed Sep 25, 2024
1 parent 66236e3 commit 950458c
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/wayland/shm/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
ptr,
sync::{
mpsc::{sync_channel, SyncSender},
Once, RwLock,
Once, OnceLock, RwLock,
},
thread,
};
Expand Down Expand Up @@ -46,9 +46,7 @@ static DROP_THIS: Lazy<SyncSender<InnerPool>> = Lazy::new(|| {

thread_local!(static SIGBUS_GUARD: Cell<(*const MemMap, bool)> = const { Cell::new((ptr::null_mut(), false)) });

/// SAFETY:
/// This will be only set in the `SIGBUS_INIT` closure, hence only once!
static mut OLD_SIGBUS_HANDLER: Option<libc::sigaction> = None;
static OLD_SIGBUS_HANDLER: OnceLock<libc::sigaction> = OnceLock::new();
static SIGBUS_INIT: Once = Once::new();

#[derive(Debug)]
Expand Down Expand Up @@ -313,22 +311,19 @@ unsafe fn place_sigbus_handler() {
action.sa_sigaction = sigbus_handler as _;
action.sa_flags = libc::SA_SIGINFO | libc::SA_NODEFER;

let old_action = OLD_SIGBUS_HANDLER.insert(mem::zeroed());
if libc::sigaction(libc::SIGBUS, &action, old_action) == -1 {
let mut old_action = mem::zeroed();
if libc::sigaction(libc::SIGBUS, &action, &mut old_action) == -1 {
let e = rustix::io::Errno::from_raw_os_error(errno::errno().0);
panic!("sigaction failed for SIGBUS handler: {:?}", e);
}
OLD_SIGBUS_HANDLER.set(old_action).map_err(|_| ()).unwrap();
}
}

unsafe fn reraise_sigbus() {
// reset the old sigaction
unsafe {
libc::sigaction(
libc::SIGBUS,
OLD_SIGBUS_HANDLER.as_ref().unwrap(),
ptr::null_mut(),
);
libc::sigaction(libc::SIGBUS, OLD_SIGBUS_HANDLER.get().unwrap(), ptr::null_mut());
libc::raise(libc::SIGBUS);
}
}
Expand Down

0 comments on commit 950458c

Please sign in to comment.