Skip to content

Commit

Permalink
bugfix: Fix new warnings on nightly (#1173)
Browse files Browse the repository at this point in the history
static mut is now discouraged; however it appears that the places we use
static mut can be removed pretty easily.

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull authored Sep 23, 2024
1 parent 4e29b83 commit 75cb9d1
Showing 1 changed file with 48 additions and 56 deletions.
104 changes: 48 additions & 56 deletions src/backend/linux_raw/vdso_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,17 @@ fn init_syscall() -> SyscallType {
/// placeholder type, and cast it as needed.
struct Function;
#[cfg(feature = "time")]
static mut CLOCK_GETTIME: AtomicPtr<Function> = AtomicPtr::new(null_mut());
static CLOCK_GETTIME: AtomicPtr<Function> = AtomicPtr::new(null_mut());
#[cfg(feature = "process")]
#[cfg(any(
target_arch = "x86_64",
target_arch = "x86",
target_arch = "riscv64",
target_arch = "powerpc64"
))]
static mut GETCPU: AtomicPtr<Function> = AtomicPtr::new(null_mut());
static GETCPU: AtomicPtr<Function> = AtomicPtr::new(null_mut());
#[cfg(target_arch = "x86")]
static mut SYSCALL: AtomicPtr<Function> = AtomicPtr::new(null_mut());
static SYSCALL: AtomicPtr<Function> = AtomicPtr::new(null_mut());

#[cfg(feature = "time")]
unsafe extern "C" fn rustix_clock_gettime_via_syscall(
Expand Down Expand Up @@ -435,52 +435,50 @@ rustix_int_0x80:
);

fn minimal_init() {
// SAFETY: Store default function addresses in static storage so that if we
// Store default function addresses in static storage so that if we
// end up making any system calls while we read the vDSO, they'll work. If
// the memory happens to already be initialized, this is redundant, but not
// harmful.
unsafe {
#[cfg(feature = "time")]
{
CLOCK_GETTIME
.compare_exchange(
null_mut(),
rustix_clock_gettime_via_syscall as *mut Function,
Relaxed,
Relaxed,
)
.ok();
}
#[cfg(feature = "time")]
{
CLOCK_GETTIME
.compare_exchange(
null_mut(),
rustix_clock_gettime_via_syscall as *mut Function,
Relaxed,
Relaxed,
)
.ok();
}

#[cfg(feature = "process")]
#[cfg(any(
target_arch = "x86_64",
target_arch = "x86",
target_arch = "riscv64",
target_arch = "powerpc64"
))]
{
GETCPU
.compare_exchange(
null_mut(),
rustix_getcpu_via_syscall as *mut Function,
Relaxed,
Relaxed,
)
.ok();
}
#[cfg(feature = "process")]
#[cfg(any(
target_arch = "x86_64",
target_arch = "x86",
target_arch = "riscv64",
target_arch = "powerpc64"
))]
{
GETCPU
.compare_exchange(
null_mut(),
rustix_getcpu_via_syscall as *mut Function,
Relaxed,
Relaxed,
)
.ok();
}

#[cfg(target_arch = "x86")]
{
SYSCALL
.compare_exchange(
null_mut(),
rustix_int_0x80 as *mut Function,
Relaxed,
Relaxed,
)
.ok();
}
#[cfg(target_arch = "x86")]
{
SYSCALL
.compare_exchange(
null_mut(),
rustix_int_0x80 as *mut Function,
Relaxed,
Relaxed,
)
.ok();
}
}

Expand Down Expand Up @@ -530,12 +528,10 @@ fn init() {
if ok {
assert!(!ptr.is_null());

// SAFETY: Store the computed function addresses in static
// Store the computed function addresses in static
// storage so that we don't need to compute it again (but if
// we do, it doesn't hurt anything).
unsafe {
CLOCK_GETTIME.store(ptr.cast(), Relaxed);
}
CLOCK_GETTIME.store(ptr.cast(), Relaxed);
}
}

Expand Down Expand Up @@ -584,12 +580,10 @@ fn init() {
if ok {
assert!(!ptr.is_null());

// SAFETY: Store the computed function addresses in static
// Store the computed function addresses in static
// storage so that we don't need to compute it again (but if
// we do, it doesn't hurt anything).
unsafe {
GETCPU.store(ptr.cast(), Relaxed);
}
GETCPU.store(ptr.cast(), Relaxed);
}
}

Expand All @@ -599,11 +593,9 @@ fn init() {
let ptr = vdso.sym(cstr!("LINUX_2.5"), cstr!("__kernel_vsyscall"));
assert!(!ptr.is_null());

// SAFETY: As above, store the computed function addresses in
// As above, store the computed function addresses in
// static storage.
unsafe {
SYSCALL.store(ptr.cast(), Relaxed);
}
SYSCALL.store(ptr.cast(), Relaxed);
}
}
}

0 comments on commit 75cb9d1

Please sign in to comment.