mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-01 15:16:22 +00:00
Common/MemArena: Add function for getting page size and alignment
This commit is contained in:
parent
6ca486ffb2
commit
d6405669e3
5 changed files with 62 additions and 0 deletions
|
@ -115,6 +115,16 @@ public:
|
||||||
///
|
///
|
||||||
void UnmapFromMemoryRegion(void* view, size_t size);
|
void UnmapFromMemoryRegion(void* view, size_t size);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Return the system's page size.
|
||||||
|
///
|
||||||
|
size_t GetPageSize() const;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Return the system's required page alignment.
|
||||||
|
///
|
||||||
|
size_t GetPageAlignment() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WindowsMemoryRegion* EnsureSplitRegionForMapping(void* address, size_t size);
|
WindowsMemoryRegion* EnsureSplitRegionForMapping(void* address, size_t size);
|
||||||
|
|
|
@ -144,6 +144,16 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
|
||||||
NOTICE_LOG_FMT(MEMMAP, "mmap failed");
|
NOTICE_LOG_FMT(MEMMAP, "mmap failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageSize() const
|
||||||
|
{
|
||||||
|
return sysconf(_SC_PAGESIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageAlignment() const
|
||||||
|
{
|
||||||
|
return GetPageSize();
|
||||||
|
}
|
||||||
|
|
||||||
LazyMemoryRegion::LazyMemoryRegion() = default;
|
LazyMemoryRegion::LazyMemoryRegion() = default;
|
||||||
|
|
||||||
LazyMemoryRegion::~LazyMemoryRegion()
|
LazyMemoryRegion::~LazyMemoryRegion()
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include "Common/MemArena.h"
|
#include "Common/MemArena.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "Common/Assert.h"
|
#include "Common/Assert.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
|
@ -163,6 +165,16 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageSize() const
|
||||||
|
{
|
||||||
|
return getpagesize();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageAlignment() const
|
||||||
|
{
|
||||||
|
return GetPageSize();
|
||||||
|
}
|
||||||
|
|
||||||
LazyMemoryRegion::LazyMemoryRegion() = default;
|
LazyMemoryRegion::LazyMemoryRegion() = default;
|
||||||
|
|
||||||
LazyMemoryRegion::~LazyMemoryRegion()
|
LazyMemoryRegion::~LazyMemoryRegion()
|
||||||
|
|
|
@ -110,6 +110,16 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
|
||||||
NOTICE_LOG_FMT(MEMMAP, "mmap failed");
|
NOTICE_LOG_FMT(MEMMAP, "mmap failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageSize() const
|
||||||
|
{
|
||||||
|
return sysconf(_SC_PAGESIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageAlignment() const
|
||||||
|
{
|
||||||
|
return GetPageSize();
|
||||||
|
}
|
||||||
|
|
||||||
LazyMemoryRegion::LazyMemoryRegion() = default;
|
LazyMemoryRegion::LazyMemoryRegion() = default;
|
||||||
|
|
||||||
LazyMemoryRegion::~LazyMemoryRegion()
|
LazyMemoryRegion::~LazyMemoryRegion()
|
||||||
|
|
|
@ -438,6 +438,26 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
|
||||||
UnmapViewOfFile(view);
|
UnmapViewOfFile(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageSize() const
|
||||||
|
{
|
||||||
|
SYSTEM_INFO si;
|
||||||
|
GetSystemInfo(&si);
|
||||||
|
return si.dwPageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t MemArena::GetPageAlignment() const
|
||||||
|
{
|
||||||
|
SYSTEM_INFO si;
|
||||||
|
GetSystemInfo(&si);
|
||||||
|
if (!m_memory_functions.m_address_MapViewOfFile3)
|
||||||
|
{
|
||||||
|
// In this case, we can only map pages that are 64K aligned.
|
||||||
|
// See https://devblogs.microsoft.com/oldnewthing/20031008-00/?p=42223
|
||||||
|
return std::max<size_t>(si.dwPageSize, 64 * 1024);
|
||||||
|
}
|
||||||
|
return si.dwPageSize;
|
||||||
|
}
|
||||||
|
|
||||||
LazyMemoryRegion::LazyMemoryRegion()
|
LazyMemoryRegion::LazyMemoryRegion()
|
||||||
{
|
{
|
||||||
InitWindowsMemoryFunctions(&m_memory_functions);
|
InitWindowsMemoryFunctions(&m_memory_functions);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue