diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2023-03-28 17:21:40 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2023-03-29 14:53:49 -0400 |
commit | 93b6997103b34750b2d84df07e09586fe1de0649 (patch) | |
tree | 14520ad62418b506c2509fd351e5760bdff249a8 /yjit/src/asm | |
parent | a8c6ba23a6a95272edd6179737d4f98d7b2cdf6e (diff) | |
download | ruby-93b6997103b34750b2d84df07e09586fe1de0649.tar.gz |
YJIT: Fix overlapping &mut in Assembler::code_gc()
Making overlapping `&mut`s triggers Undefined Bahavior. This function
previously had them through `cb` and `ocb` aliasing with `self` or live
references in the caller.
To fix the overlap, take `ocb` as a parameter and don't use `get_inline_cb()`
in the body of the function.
Diffstat (limited to 'yjit/src/asm')
-rw-r--r-- | yjit/src/asm/mod.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/yjit/src/asm/mod.rs b/yjit/src/asm/mod.rs index bf18dd5672..346ada7719 100644 --- a/yjit/src/asm/mod.rs +++ b/yjit/src/asm/mod.rs @@ -583,7 +583,7 @@ impl CodeBlock { } /// Code GC. Free code pages that are not on stack and reuse them. - pub fn code_gc(&mut self) { + pub fn code_gc(&mut self, ocb: &mut OutlinedCb) { // The previous code GC failed to free any pages. Give up. if self.freed_pages.as_ref() == &Some(vec![]) { return; @@ -631,15 +631,11 @@ impl CodeBlock { freed_pages.append(&mut virtual_pages); if let Some(&first_page) = freed_pages.first() { - let mut cb = CodegenGlobals::get_inline_cb(); - cb.write_pos = cb.get_page_pos(first_page); - cb.dropped_bytes = false; - cb.clear_comments(); - - let mut ocb = CodegenGlobals::get_outlined_cb().unwrap(); - ocb.write_pos = ocb.get_page_pos(first_page); - ocb.dropped_bytes = false; - ocb.clear_comments(); + for cb in [&mut *self, ocb.unwrap()] { + cb.write_pos = cb.get_page_pos(first_page); + cb.dropped_bytes = false; + cb.clear_comments(); + } } // Track which pages are free. |