Skip to content

Commit

Permalink
bugfix: Fix new warnings on nightly
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 committed Sep 22, 2024
1 parent 07a80aa commit af32a40
Showing 1 changed file with 43 additions and 49 deletions.
92 changes: 43 additions & 49 deletions src/backend/linux_raw/vdso_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,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 @@ -438,48 +438,46 @@ fn minimal_init() {
// 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 @@ -532,9 +530,7 @@ fn init() {
// SAFETY: 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 @@ -586,9 +582,7 @@ fn init() {
// SAFETY: 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 Down

0 comments on commit af32a40

Please sign in to comment.