Skip to content

Commit 4bb2ec5

Browse files
committed
ZJIT: Assert with_write_ptr patches the half it is on
with_write_ptr saves and restores the current half's write position, so a callback that switched halves in the middle would carry the patch site off into the other half's saved position and hand back an empty written range, which remove_gc_offsets reads. Nothing does that today -- invalidation and call-site regeneration each emit one jump or call and have no side exits -- so make it an assertion rather than support it.
1 parent fe932fd commit 4bb2ec5

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

zjit/src/asm/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ impl CodeBlock {
223223

224224
/// Invoke a callback with write_ptr temporarily adjusted to a given address
225225
pub fn with_write_ptr(&mut self, code_ptr: CodePtr, callback: impl Fn(&mut CodeBlock)) -> Range<CodePtr> {
226+
// The callback overwrites existing code in place, so it must not be one that
227+
// switches halves: a `set_outlined` in the middle would carry `code_ptr` off
228+
// into the other half's saved position and hand back an empty written range,
229+
// which remove_gc_offsets reads.
230+
// Everything that patches (invalidation jumps, call-site regeneration) emits
231+
// a single jump or call and has no side exits, so there is nothing to switch.
232+
debug_assert!(!self.outlined, "with_write_ptr patches the half it is already on");
233+
226234
// Temporarily update the write_pos. Ignore the dropped_bytes flag at the old address.
227235
let old_write_pos = self.write_pos;
228236
let old_dropped_bytes = self.dropped_bytes;

0 commit comments

Comments
 (0)