[x64] Simplify padding of code / unwind reservation in code cache.

This commit is contained in:
gibbed 2019-08-25 16:17:13 -05:00 committed by Rick Gibbed
parent a422166123
commit 920b5c5839
1 changed files with 7 additions and 8 deletions

View File

@ -138,7 +138,8 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code,
// unwind table requires entries AND code to be sorted in order. // unwind table requires entries AND code to be sorted in order.
size_t low_mark; size_t low_mark;
size_t high_mark; size_t high_mark;
uint8_t* code_address = nullptr; size_t code_offset;
uint8_t* code_address;
UnwindReservation unwind_reservation; UnwindReservation unwind_reservation;
{ {
auto global_lock = global_critical_region_.Acquire(); auto global_lock = global_critical_region_.Acquire();
@ -147,7 +148,8 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code,
// Reserve code. // Reserve code.
// Always move the code to land on 16b alignment. // Always move the code to land on 16b alignment.
code_address = generated_code_base_ + generated_code_offset_; code_offset = generated_code_offset_;
code_address = generated_code_base_ + code_offset;
generated_code_offset_ += xe::round_up(func_info.code_size.total, 16); generated_code_offset_ += xe::round_up(func_info.code_size.total, 16);
// Reserve unwind info. // Reserve unwind info.
@ -155,7 +157,7 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code,
// need it, and a few extra bytes of padding isn't the worst thing. // need it, and a few extra bytes of padding isn't the worst thing.
unwind_reservation = unwind_reservation =
RequestUnwindReservation(generated_code_base_ + generated_code_offset_); RequestUnwindReservation(generated_code_base_ + generated_code_offset_);
generated_code_offset_ += unwind_reservation.data_size; generated_code_offset_ += xe::round_up(unwind_reservation.data_size, 16);
high_mark = generated_code_offset_; high_mark = generated_code_offset_;
@ -189,11 +191,8 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code,
std::memcpy(code_address, machine_code, func_info.code_size.total); std::memcpy(code_address, machine_code, func_info.code_size.total);
// Fill unused slots with 0xCC // Fill unused slots with 0xCC
std::memset( std::memset(code_address + func_info.code_size.total, 0xCC,
code_address + func_info.code_size.total, 0xCC, generated_code_offset_ - code_offset);
xe::round_up(func_info.code_size.total + unwind_reservation.data_size,
16) -
func_info.code_size.total);
// Notify subclasses of placed code. // Notify subclasses of placed code.
PlaceCode(guest_address, machine_code, func_info, code_address, PlaceCode(guest_address, machine_code, func_info, code_address,