mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-30 15:55:29 +02:00
Use managarm special fastmem fallback
This commit is contained in:
parent
d8a8169eb2
commit
936e5b56eb
2 changed files with 17 additions and 2 deletions
|
|
@ -695,10 +695,21 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_)
|
||||||
backing_base = fallback_buffer->data();
|
backing_base = fallback_buffer->data();
|
||||||
virtual_base = nullptr;
|
virtual_base = nullptr;
|
||||||
#else
|
#else
|
||||||
|
bool has_memfd = true; // all platforms support it
|
||||||
|
#ifdef _WIN32
|
||||||
|
// EXCEPT WINDOWS who may not (Windows 8.1, 7, Vista, etc)
|
||||||
|
DynamicLibrary kernelbase_dll("KernelBase");
|
||||||
|
has_memfd = kernelbase_dll.IsOpen();
|
||||||
|
if (has_memfd) {
|
||||||
|
PFN_CreateFileMapping2 p{};
|
||||||
|
GetFuncAddress(kernelbase_dll, "CreateFileMapping2", p);
|
||||||
|
has_memfd = p != nullptr;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
// Try to allocate a fastmem arena.
|
// Try to allocate a fastmem arena.
|
||||||
// The implementation will fail with std::bad_alloc on errors.
|
// The implementation will fail with std::bad_alloc on errors.
|
||||||
impl = std::make_unique<HostMemory::Impl>(AlignUp(backing_size, PageAlignment), AlignUp(virtual_size, PageAlignment) + HugePageSize);
|
impl = std::make_unique<HostMemory::Impl>(AlignUp(backing_size, PageAlignment), AlignUp(virtual_size, PageAlignment) + HugePageSize);
|
||||||
if (impl->Init()) {
|
if (has_memfd && impl->Init()) {
|
||||||
backing_base = impl->backing_base;
|
backing_base = impl->backing_base;
|
||||||
virtual_base = impl->virtual_base;
|
virtual_base = impl->virtual_base;
|
||||||
if (virtual_base) {
|
if (virtual_base) {
|
||||||
|
|
@ -708,10 +719,12 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
impl.reset();
|
impl.reset();
|
||||||
LOG_WARNING(HW_Memory, "Platform can support fastmem, but can't create it");
|
LOG_WARNING(HW_Memory, "Platform doesn't support fastmem");
|
||||||
|
#ifdef _WIN32
|
||||||
fallback_buffer.emplace(backing_size);
|
fallback_buffer.emplace(backing_size);
|
||||||
backing_base = fallback_buffer->data();
|
backing_base = fallback_buffer->data();
|
||||||
virtual_base = nullptr;
|
virtual_base = nullptr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,9 @@ private:
|
||||||
u8* virtual_base{};
|
u8* virtual_base{};
|
||||||
size_t virtual_base_offset{};
|
size_t virtual_base_offset{};
|
||||||
// Windows requires it for kernels whom lack proper support for some functions!
|
// Windows requires it for kernels whom lack proper support for some functions!
|
||||||
|
#if defined(__OPENORBIS__) || defined(__managarm__) || defined(_WIN32) || defined(__EMSCRIPTEN__)
|
||||||
std::optional<Common::VirtualBuffer<u8>> fallback_buffer;
|
std::optional<Common::VirtualBuffer<u8>> fallback_buffer;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue