core: memory: page_table: Make PageTable class thread safe.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <tuple>
|
||||
|
||||
#include "common/common_types.h"
|
||||
@@ -47,7 +48,8 @@ struct SpecialRegion {
|
||||
* A (reasonably) fast way of allowing switchable and remappable process address spaces. It loosely
|
||||
* mimics the way a real CPU page table works.
|
||||
*/
|
||||
struct PageTable {
|
||||
class PageTable {
|
||||
public:
|
||||
PageTable();
|
||||
~PageTable() noexcept;
|
||||
|
||||
@@ -62,12 +64,42 @@ struct PageTable {
|
||||
* a given address space.
|
||||
*
|
||||
* @param address_space_width_in_bits The address size width in bits.
|
||||
* @param page_size_in_bits The page size in bits.
|
||||
* @param has_attribute Whether or not this page has any backing attributes.
|
||||
* @param page_size_in_bits The page size in bits.
|
||||
*/
|
||||
void Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits,
|
||||
bool has_attribute);
|
||||
void Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits);
|
||||
|
||||
struct Entry {
|
||||
u8* const pointer;
|
||||
const u64 backing_addr;
|
||||
const Common::PageType attribute;
|
||||
};
|
||||
|
||||
VirtualBuffer<u8*>& GetPointers() {
|
||||
return pointers;
|
||||
}
|
||||
|
||||
u64 GetBackingAddr(std::size_t base) {
|
||||
std::lock_guard<std::mutex> lock(guard);
|
||||
return backing_addr[base];
|
||||
}
|
||||
|
||||
Entry GetEntry(std::size_t base) {
|
||||
std::lock_guard<std::mutex> lock(guard);
|
||||
return {
|
||||
.pointer = pointers[base],
|
||||
.backing_addr = backing_addr[base],
|
||||
.attribute = attributes[base],
|
||||
};
|
||||
}
|
||||
|
||||
void SetEntry(std::size_t base, const Entry& entry) {
|
||||
std::lock_guard<std::mutex> lock(guard);
|
||||
pointers[base] = entry.pointer;
|
||||
backing_addr[base] = entry.backing_addr;
|
||||
attributes[base] = entry.attribute;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Vector of memory pointers backing each page. An entry can only be non-null if the
|
||||
* corresponding entry in the `attributes` vector is of type `Memory`.
|
||||
@@ -77,6 +109,8 @@ struct PageTable {
|
||||
VirtualBuffer<u64> backing_addr;
|
||||
|
||||
VirtualBuffer<PageType> attributes;
|
||||
|
||||
std::mutex guard;
|
||||
};
|
||||
|
||||
} // namespace Common
|
||||
|
||||
Reference in New Issue
Block a user