Skip to content

Commit

Permalink
allow static_mut_refs where reasoning about them is easy
Browse files Browse the repository at this point in the history
  • Loading branch information
copy committed Dec 20, 2024
1 parent b5edf12 commit 253e950
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/rust/cpu/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,7 @@ pub unsafe fn full_clear_tlb() {
valid_tlb_entries_count = 0;

if CHECK_TLB_INVARIANTS {
#[allow(static_mut_refs)]
for &entry in tlb_data.iter() {
dbg_assert!(entry == 0);
}
Expand Down Expand Up @@ -2141,6 +2142,7 @@ pub unsafe fn clear_tlb() {
valid_tlb_entries_count = global_page_offset;

if CHECK_TLB_INVARIANTS {
#[allow(static_mut_refs)]
for &entry in tlb_data.iter() {
dbg_assert!(entry == 0 || 0 != entry & TLB_GLOBAL);
}
Expand Down Expand Up @@ -2181,6 +2183,7 @@ pub unsafe fn trigger_gp_jit(code: i32, eip_offset_in_page: i32) {

#[no_mangle]
pub unsafe fn trigger_fault_end_jit() {
#[allow(static_mut_refs)]
let (code, error_code) = jit_fault.take().unwrap();
if DEBUG {
if cpu_exception_hook(code) {
Expand Down Expand Up @@ -2924,11 +2927,12 @@ pub unsafe fn cycle_internal() {
);

if cfg!(feature = "profiler") {
dbg_assert!(match ::cpu::cpu::debug_last_jump {
dbg_assert!(match debug_last_jump {
LastJump::Compiled { .. } => true,
_ => false,
});
let last_jump_addr = ::cpu::cpu::debug_last_jump.phys_address().unwrap();
#[allow(static_mut_refs)]
let last_jump_addr = debug_last_jump.phys_address().unwrap();
let last_jump_opcode = if last_jump_addr != 0 {
read32s(last_jump_addr)
}
Expand Down
8 changes: 4 additions & 4 deletions src/rust/cpu/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ pub fn svga_allocate_memory(size: u32) -> u32 {
dbg_assert!(vga_mem8.is_null());
};
let layout = alloc::Layout::from_size_align(size as usize, 0x1000).unwrap();
let ptr = unsafe { alloc::alloc(layout) as u32 };
let ptr = unsafe { alloc::alloc(layout) };
dbg_assert!(
size & (1 << 12 << 6) == 0,
"size not aligned to dirty_bitmap"
);
unsafe {
vga_mem8 = ptr as *mut u8;
vga_mem8 = ptr;
vga_memory_size = size;
vga::dirty_bitmap.resize((size >> 12 >> 6) as usize, 0);
vga::set_dirty_bitmap_size(size >> 12 >> 6);
};
ptr
ptr as u32
}

#[no_mangle]
Expand Down
11 changes: 8 additions & 3 deletions src/rust/cpu/vga.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#![allow(non_upper_case_globals)]
#![allow(static_mut_refs)]

// Safety of allow(static_mut_refs) in this file:
// These following two globals are not passed anywhere, only built-in function are called on them
static mut dirty_bitmap: Vec<u64> = Vec::new();
static mut dest_buffer: Vec<u32> = Vec::new();

use cpu::global_pointers;
use cpu::memory;

use std::ptr;

pub static mut dirty_bitmap: Vec<u64> = Vec::new();
pub static mut dest_buffer: Vec<u32> = Vec::new();

#[no_mangle]
pub unsafe fn svga_allocate_dest_buffer(size: u32) -> u32 {
dest_buffer.resize(size as usize, 0);
dest_buffer.as_mut_ptr() as u32
}

pub unsafe fn set_dirty_bitmap_size(size: u32) { dirty_bitmap.resize(size as usize, 0); }

pub unsafe fn mark_dirty(addr: u32) {
let page = (addr - memory::VGA_LFB_ADDRESS) >> 12;
dbg_assert!(((page >> 6) as usize) < dirty_bitmap.len());
Expand Down
2 changes: 2 additions & 0 deletions src/rust/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,9 @@ pub fn check_missed_entry_points(phys_address: u32, state_flags: CachedStateFlag
return;
}

#[allow(static_mut_refs)]
let last_jump_type = unsafe { cpu::debug_last_jump.name() };
#[allow(static_mut_refs)]
let last_jump_addr = unsafe { cpu::debug_last_jump.phys_address() }.unwrap_or(0);
let last_jump_opcode =
if last_jump_addr != 0 { memory::read32s(last_jump_addr) } else { 0 };
Expand Down
1 change: 1 addition & 0 deletions src/rust/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub fn stat_increment_by(stat: stat, by: u64) {
#[no_mangle]
pub fn profiler_init() {
unsafe {
#[allow(static_mut_refs)]
for x in stat_array.iter_mut() {
*x = 0
}
Expand Down

0 comments on commit 253e950

Please sign in to comment.