DANGER DANGER. Switching to global critical region.
This changes almost all locks held by guest threads to use a single global critical region. This emulates the behavior on the PPC of disabling interrupts (by calls like KeRaiseIrqlToDpcLevel or masking interrupts), and prevents deadlocks from occuring when threads are suspended or otherwise blocked. This has performance implications and a pass is needed to ensure the locking is as granular as possible. It could also break everything because it's fundamentally unsound. We'll see.
This commit is contained in:
@@ -129,7 +129,7 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code,
|
||||
uint8_t* code_address = nullptr;
|
||||
UnwindReservation unwind_reservation;
|
||||
{
|
||||
std::lock_guard<xe::mutex> allocation_lock(allocation_mutex_);
|
||||
auto global_lock = global_critical_region_.Acquire();
|
||||
|
||||
low_mark = generated_code_offset_;
|
||||
|
||||
@@ -192,7 +192,7 @@ uint32_t X64CodeCache::PlaceData(const void* data, size_t length) {
|
||||
size_t high_mark;
|
||||
uint8_t* data_address = nullptr;
|
||||
{
|
||||
std::lock_guard<xe::mutex> allocation_lock(allocation_mutex_);
|
||||
auto global_lock = global_critical_region_.Acquire();
|
||||
|
||||
// Reserve code.
|
||||
// Always move the code to land on 16b alignment.
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -91,9 +90,9 @@ class X64CodeCache : public CodeCache {
|
||||
std::wstring file_name_;
|
||||
xe::memory::FileMappingHandle mapping_ = nullptr;
|
||||
|
||||
// Must be held when manipulating the offsets or counts of anything, to keep
|
||||
// the tables consistent and ordered.
|
||||
xe::mutex allocation_mutex_;
|
||||
// NOTE: the global critical region must be held when manipulating the offsets
|
||||
// or counts of anything, to keep the tables consistent and ordered.
|
||||
xe::global_critical_region global_critical_region_;
|
||||
|
||||
// Value that the indirection table will be initialized with upon commit.
|
||||
uint32_t indirection_default_value_ = 0xFEEDF00D;
|
||||
|
||||
Reference in New Issue
Block a user