diff --git a/crates/celox-vpi/src/lib.rs b/crates/celox-vpi/src/lib.rs index ada92725bbd..412fadba113 100644 --- a/crates/celox-vpi/src/lib.rs +++ b/crates/celox-vpi/src/lib.rs @@ -1550,6 +1550,11 @@ unsafe fn write_snapshot_value( if value.is_null() || reference.is_null() { return; } + // Safety: checked non-null above; the callback owns its value record. + let value = unsafe { &mut *value }; + if value.format == VPI_SUPPRESS_VAL { + return; + } // Safety: the caller has selected this host and keeps the callback's // object handle live through dispatch. let handle = unsafe { &mut *reference }; @@ -1558,16 +1563,16 @@ unsafe fn write_snapshot_value( }; let metadata = borrow_cell(&host.runtime, |runtime| { let runtime = runtime.as_ref()?.state(); - runtime - .reflection() - .signal(id.root) - .and_then(|signal| Some((id.width(runtime)?, signal.signed))) + let width = id.width(runtime)?; + let signed = value.format == VPI_INT_VAL + && width > 0 + && width < 32 + && runtime.reflection().signal(id.root)?.signed; + Some((width, signed)) }); let Some((width, signed)) = metadata else { return; }; - // Safety: checked non-null above; the caller owns writable value storage. - let value = unsafe { &mut *value }; encode_snapshot_value(handle, value, snapshot, width, signed); } @@ -1587,12 +1592,16 @@ pub unsafe extern "C" fn vpi_get_value(reference: VpiHandle, value: *mut VpiValu let Some(host) = selected_host() else { return; }; + // Safety: selection above rejects foreign-thread calls before accessing + // caller storage, which is non-null and writable on the owning thread. + let value = unsafe { &mut *value }; + if value.format == VPI_SUPPRESS_VAL { + return; + } // Safety: the caller supplies a live handle; selection above rejects // foreign-thread/unbound calls before dereferencing it. let handle = unsafe { &mut *reference }; if let HandleKind::Constant(integer) = handle.kind { - // Safety: checked non-null above; caller owns the `VpiValue` allocation. - let value = unsafe { &mut *value }; if value.format == VPI_INT_VAL { value.value.integer = integer; } @@ -1604,14 +1613,16 @@ pub unsafe extern "C" fn vpi_get_value(reference: VpiHandle, value: *mut VpiValu let Some((snapshot, width)) = value_snapshot_at(&host, id) else { return; }; - let signed = borrow_cell(&host.runtime, |runtime| { - runtime - .as_ref() - .and_then(|runtime| runtime.state().reflection().signal(id.root)) - .is_some_and(|signal| signal.signed) - }); - // Safety: checked non-null above; caller owns the `VpiValue` allocation. - encode_snapshot_value(handle, unsafe { &mut *value }, &snapshot, width, signed); + let signed = value.format == VPI_INT_VAL + && width > 0 + && width < 32 + && borrow_cell(&host.runtime, |runtime| { + runtime + .as_ref() + .and_then(|runtime| runtime.state().reflection().signal(id.root)) + .is_some_and(|signal| signal.signed) + }); + encode_snapshot_value(handle, value, &snapshot, width, signed); } fn decode_digit(digit: u8, radix_bits: u32) -> Option<(u8, u8)> { diff --git a/flake.lock b/flake.lock index 7ff4b0c07e7..5bb3d979704 100644 --- a/flake.lock +++ b/flake.lock @@ -68,17 +68,17 @@ "xezim": { "flake": false, "locked": { - "lastModified": 1793160411, - "narHash": "sha256-bDcUa26tHiq0Q2Z7kOOQpSLDtnqgHhYia07KL4q8nHs=", + "lastModified": 1793192344, + "narHash": "sha256-MM6g4LbdEjYdItX1Gy6xuWM7V6WffoMkwcQheBkO3V0=", "owner": "aionhw", "repo": "xezim", - "rev": "d491f9480123895e064ee4b37173a9d0f5d7383b", + "rev": "bbbc57cd542cc022b9eb5673df5d95d558c86c32", "type": "github" }, "original": { "owner": "aionhw", "repo": "xezim", - "rev": "d491f9480123895e064ee4b37173a9d0f5d7383b", + "rev": "bbbc57cd542cc022b9eb5673df5d95d558c86c32", "type": "github" } } diff --git a/flake.nix b/flake.nix index 1ea755e177e..6cba661ecc9 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ # The xezim reference simulator for the shared test suite, pinned by # revision so that Renovate proposes updates. xezim = { - url = "github:aionhw/xezim/d491f9480123895e064ee4b37173a9d0f5d7383b"; + url = "github:aionhw/xezim/bbbc57cd542cc022b9eb5673df5d95d558c86c32"; flake = false; }; };