Skip to content

Commit

Permalink
fix time on x86_64 macos
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Jan 5, 2024
1 parent fdb1d56 commit b236448
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## madsim [0.2.24] - 2024-01-05

### Fixed

- Fix intercepting time on x86_64 macOS, Rust 1.75.0.

## rdkafka [0.3.1] - 2024-01-05

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion madsim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim"
version = "0.2.23"
version = "0.2.24"
edition = "2021"
authors = ["Runji Wang <[email protected]>"]
description = "Deterministic Simulator for distributed systems."
Expand Down
7 changes: 5 additions & 2 deletions madsim/src/sim/time/system_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ unsafe extern "C" fn gettimeofday(tp: *mut libc::timeval, tz: *mut libc::c_void)
}
}

/// Override the libc `clock_gettime` function. For Linux and ARM64 macOS.
/// Override the libc `clock_gettime` function.
/// For Linux, ARM64 macOS (since 1.67) and x86_64 macOS (since 1.75).
#[no_mangle]
#[inline(never)]
unsafe extern "C" fn clock_gettime(
Expand Down Expand Up @@ -86,12 +87,14 @@ unsafe extern "C" fn clock_gettime(
}
}

/// Override the `mach_absolute_time` function. For `Instant` on x86_64 macOS.
/// Override the `mach_absolute_time` function. For `Instant` on macOS before Rust 1.75.
#[no_mangle]
#[inline(never)]
#[cfg(target_os = "macos")]
// not used on ARM64 macOS after https://github.com/rust-lang/rust/pull/103594
#[rustversion::attr(since(1.67), cfg(not(target_arch = "aarch64")))]
// not used on x86_64 macOS after https://github.com/rust-lang/rust/pull/116238
#[rustversion::attr(since(1.75), cfg(not(target_arch = "x86_64")))]
extern "C" fn mach_absolute_time() -> u64 {
if let Some(time) = super::TimeHandle::try_current() {
// inside a madsim context, use the simulated time.
Expand Down

0 comments on commit b236448

Please sign in to comment.