aboutsummaryrefslogtreecommitdiffstats
path: root/yjit/src/asm
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2023-03-28 17:21:40 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2023-03-29 14:53:49 -0400
commit93b6997103b34750b2d84df07e09586fe1de0649 (patch)
tree14520ad62418b506c2509fd351e5760bdff249a8 /yjit/src/asm
parenta8c6ba23a6a95272edd6179737d4f98d7b2cdf6e (diff)
downloadruby-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.rs16
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.