[Kernel] Fixup GetProcAddressByOrdinal

Now properly takes a global lock when populating guest_trampoline_map_
as opposed to taking and immediately releasing it
Also removes a redundant find() from guest_trampoline_map_
so map is not searched twice if the function has already been generated.
This commit is contained in:
Silent 2019-09-08 21:32:34 +02:00 committed by Rick Gibbed
parent 5795d25afe
commit 9205a6b062
1 changed files with 5 additions and 5 deletions

View File

@ -107,12 +107,12 @@ uint32_t KernelModule::GetProcAddressByOrdinal(uint16_t ordinal) {
} else {
if (export_entry->function_data.trampoline ||
export_entry->function_data.shim) {
global_critical_region_.Acquire();
auto global_lock = global_critical_region_.Acquire();
// See if the function has been generated already.
if (guest_trampoline_map_.find(ordinal) != guest_trampoline_map_.end()) {
auto entry = guest_trampoline_map_.find(ordinal);
return entry->second;
auto item = guest_trampoline_map_.find(ordinal);
if (item != guest_trampoline_map_.end()) {
return item->second;
}
cpu::GuestFunction::ExternHandler handler = nullptr;
@ -131,7 +131,7 @@ uint32_t KernelModule::GetProcAddressByOrdinal(uint16_t ordinal) {
export_entry->name, guest_addr);
// Register the function in our map.
guest_trampoline_map_[ordinal] = guest_addr;
guest_trampoline_map_.emplace(ordinal, guest_addr);
return guest_addr;
} else {
// Not implemented.