Remove page_fault

This commit is contained in:
Fabian 2020-12-31 19:14:30 -06:00
parent 90517dcc7c
commit 88613c3f27
2 changed files with 42 additions and 39 deletions

View file

@ -517,7 +517,7 @@ fn gen_safe_read(
ctx.builder.get_local(&address_local);
ctx.builder
.const_i32(ctx.start_of_current_instruction as i32);
.const_i32(ctx.start_of_current_instruction as i32 & 0xFFF);
match bits {
BitSize::BYTE => {
gen_call_fn2_ret(ctx.builder, "safe_read8_slow_jit");
@ -535,19 +535,22 @@ fn gen_safe_read(
gen_call_fn2_ret(ctx.builder, "safe_read128s_slow_jit");
},
}
ctx.builder.set_local(&entry_local);
ctx.builder.tee_local(&entry_local);
ctx.builder.const_i32(1);
ctx.builder.and_i32();
if cfg!(feature = "profiler") && cfg!(feature = "profiler_instrument") {
ctx.builder.load_u8(global_pointers::PAGE_FAULT);
ctx.builder.if_void();
gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);
ctx.builder.block_end();
ctx.builder.get_local(&entry_local);
ctx.builder.const_i32(1);
ctx.builder.and_i32();
}
// -2 for the exit-with-pagefault block, +1 for leaving the nested if from this function
let br_offset = ctx.current_brtable_depth - 2 + 1;
ctx.builder.load_u8(global_pointers::PAGE_FAULT);
ctx.builder.br_if(br_offset);
ctx.builder.br_if(ctx.current_brtable_depth - 2 + 1);
ctx.builder.block_end();
@ -660,7 +663,7 @@ fn gen_safe_write(
},
}
ctx.builder
.const_i32(ctx.start_of_current_instruction as i32);
.const_i32(ctx.start_of_current_instruction as i32 & 0xFFF);
match bits {
BitSize::BYTE => {
gen_call_fn3_ret(ctx.builder, "safe_write8_slow_jit");
@ -678,19 +681,22 @@ fn gen_safe_write(
gen_call_fn4_i32_i64_i64_i32_ret(ctx.builder, "safe_write128_slow_jit");
},
}
ctx.builder.set_local(&entry_local);
ctx.builder.tee_local(&entry_local);
ctx.builder.const_i32(1);
ctx.builder.and_i32();
if cfg!(feature = "profiler") && cfg!(feature = "profiler_instrument") {
ctx.builder.load_u8(global_pointers::PAGE_FAULT);
ctx.builder.if_void();
gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);
ctx.builder.block_end();
ctx.builder.get_local(&entry_local);
ctx.builder.const_i32(1);
ctx.builder.and_i32();
}
// -2 for the exit-with-pagefault block, +1 for leaving the nested if from this function
let br_offset = ctx.current_brtable_depth - 2 + 1;
ctx.builder.load_u8(global_pointers::PAGE_FAULT);
ctx.builder.br_if(br_offset);
ctx.builder.br_if(ctx.current_brtable_depth - 2 + 1);
ctx.builder.block_end();
@ -799,7 +805,7 @@ pub fn gen_safe_read_write(
ctx.builder.get_local(&address_local);
ctx.builder
.const_i32(ctx.start_of_current_instruction as i32);
.const_i32(ctx.start_of_current_instruction as i32 & 0xFFF);
match bits {
BitSize::BYTE => {
@ -814,17 +820,21 @@ pub fn gen_safe_read_write(
BitSize::QWORD => dbg_assert!(false),
BitSize::DQWORD => dbg_assert!(false),
}
ctx.builder.set_local(&entry_local);
ctx.builder.tee_local(&entry_local);
ctx.builder.const_i32(1);
ctx.builder.and_i32();
if cfg!(feature = "profiler") && cfg!(feature = "profiler_instrument") {
ctx.builder.load_u8(global_pointers::PAGE_FAULT);
ctx.builder.if_void();
gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);
ctx.builder.block_end();
ctx.builder.get_local(&entry_local);
ctx.builder.const_i32(1);
ctx.builder.and_i32();
}
// -2 for the exit-with-pagefault block, +2 for leaving the two nested ifs from this function
ctx.builder.load_u8(global_pointers::PAGE_FAULT);
// -2 for the exit-with-pagefault block, +1 for leaving the two nested ifs from this function
ctx.builder.br_if(ctx.current_brtable_depth - 2 + 1);
ctx.builder.block_end();
@ -887,8 +897,8 @@ pub fn gen_safe_read_write(
BitSize::DQWORD => dbg_assert!(false),
}
ctx.builder.drop_();
ctx.builder.load_u8(global_pointers::PAGE_FAULT);
ctx.builder.const_i32(1);
ctx.builder.and_i32();
ctx.builder.if_void();
{

View file

@ -2265,8 +2265,7 @@ pub unsafe fn safe_read_slow_jit(addr: i32, bitsize: i32, start_eip: i32, is_wri
} {
Err(()) => {
*previous_ip = *instruction_pointer & !0xFFF | start_eip & 0xFFF;
*page_fault = true;
return 0; // TODO: Return value so that jit code fails when accidentally accessing this
return 1;
},
Ok(addr) => addr,
};
@ -2280,12 +2279,10 @@ pub unsafe fn safe_read_slow_jit(addr: i32, bitsize: i32, start_eip: i32, is_wri
} {
Err(()) => {
*previous_ip = *instruction_pointer & !0xFFF | start_eip & 0xFFF;
*page_fault = true;
return 0; // TODO: Return value so that jit code fails when accidentally accessing this
return 1;
},
Ok(addr) => addr,
};
*page_fault = false;
// TODO: Could check if virtual pages point to consecutive physical and go to fast path
// do read, write into scratch buffer
@ -2298,20 +2295,21 @@ pub unsafe fn safe_read_slow_jit(addr: i32, bitsize: i32, start_eip: i32, is_wri
for s in addr_high..(addr_high + (addr + bitsize / 8 & 0xFFF) as u32) {
*(scratch as *mut u8).offset((0x1000 | s & 0xFFF) as isize) = read8(s) as u8
}
((scratch - mem8 as u32) as i32) ^ addr
(((scratch - mem8 as u32) as i32) ^ addr) & !0xFFF
}
else if in_mapped_range(addr_low) {
*page_fault = false;
let scratch = jit_paging_scratch_buffer.0.as_mut_ptr() as u32;
dbg_assert!(scratch & 0xFFF == 0);
for s in addr_low..(addr_low + bitsize as u32 / 8) {
*(scratch as *mut u8).offset((s & 0xFFF) as isize) = read8(s) as u8
}
((scratch - mem8 as u32) as i32) ^ addr
(((scratch - mem8 as u32) as i32) ^ addr) & !0xFFF
}
else {
*page_fault = false;
addr_low as i32 ^ addr
(addr_low as i32 ^ addr) & !0xFFF
}
}
@ -2360,8 +2358,7 @@ pub unsafe fn safe_write_slow_jit(
let addr_low = match translate_address_write_jit(addr) {
Err(()) => {
*previous_ip = *instruction_pointer & !0xFFF | start_eip & 0xFFF;
*page_fault = true;
return 0; // TODO: Return value so that jit code fails when accidentally accessing this
return 1;
},
Ok(addr) => addr,
};
@ -2370,11 +2367,10 @@ pub unsafe fn safe_write_slow_jit(
Err(()) => {
*previous_ip = *instruction_pointer & !0xFFF | start_eip & 0xFFF;
*page_fault = true;
return 0; // TODO: Return value so that jit code fails when accidentally accessing this
return 1;
},
Ok(addr) => addr,
};
*page_fault = false;
// TODO: Could check if virtual pages point to consecutive physical and go to fast path
// do write, return dummy pointer for fast path to write into
@ -2400,11 +2396,9 @@ pub unsafe fn safe_write_slow_jit(
let scratch = jit_paging_scratch_buffer.0.as_mut_ptr() as u32;
dbg_assert!(scratch & 0xFFF == 0);
(scratch as i32 - mem8 as i32) ^ addr
((scratch as i32 - mem8 as i32) ^ addr) & !0xFFF
}
else if in_mapped_range(addr_low) {
*page_fault = false;
match bitsize {
128 => write128(
addr_low,
@ -2421,12 +2415,11 @@ pub unsafe fn safe_write_slow_jit(
let scratch = jit_paging_scratch_buffer.0.as_mut_ptr() as u32;
dbg_assert!(scratch & 0xFFF == 0);
(scratch as i32 - mem8 as i32) ^ addr
((scratch as i32 - mem8 as i32) ^ addr) & !0xFFF
}
else {
::jit::jit_dirty_page(::jit::get_jit_state(), Page::page_of(addr_low));
*page_fault = false;
addr_low as i32 ^ addr
(addr_low as i32 ^ addr) & !0xFFF
}
}