mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-26 22:29:00 +02:00
swap handling
This commit is contained in:
parent
43c7b288a8
commit
a034d7a8c2
4 changed files with 43 additions and 3 deletions
|
|
@ -678,6 +678,7 @@ private:
|
||||||
|
|
||||||
HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) : backing_size(backing_size_), virtual_size(virtual_size_) {
|
HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) : backing_size(backing_size_), virtual_size(virtual_size_) {
|
||||||
#ifdef __OPENORBIS__
|
#ifdef __OPENORBIS__
|
||||||
|
Common::InitSwap();
|
||||||
LOG_WARNING(HW_Memory, "Platform doesn't support fastmem");
|
LOG_WARNING(HW_Memory, "Platform doesn't support fastmem");
|
||||||
fallback_buffer.emplace(backing_size);
|
fallback_buffer.emplace(backing_size);
|
||||||
backing_base = fallback_buffer->data();
|
backing_base = fallback_buffer->data();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __OPENORBIS__
|
||||||
|
#include <csignal>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/virtual_buffer.h"
|
#include "common/virtual_buffer.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
|
|
@ -33,7 +37,7 @@ void* AllocateMemoryPages(std::size_t size) noexcept {
|
||||||
void* addr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE);
|
void* addr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE);
|
||||||
ASSERT(addr != nullptr);
|
ASSERT(addr != nullptr);
|
||||||
#elif defined(__OPENORBIS__)
|
#elif defined(__OPENORBIS__)
|
||||||
void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_VOID | MAP_PRIVATE, -1, 0);
|
||||||
ASSERT(addr != MAP_FAILED);
|
ASSERT(addr != MAP_FAILED);
|
||||||
#else
|
#else
|
||||||
void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||||
|
|
@ -53,4 +57,26 @@ void FreeMemoryPages(void* addr, [[maybe_unused]] std::size_t size) noexcept {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __OPENORBIS__
|
||||||
|
static struct sigaction old_sa_segv;
|
||||||
|
static void SwapHandler(int sig, siginfo_t* si, void* raw_context) {
|
||||||
|
void* a_addr = reinterpret_cast<void*>(uintptr_t(si->si_addr) & ~0xfff);
|
||||||
|
mmap(a_addr, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||||
|
//mprotect(a_addr, 4096, PROT_READ | PROT_WRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InitSwap() noexcept {
|
||||||
|
struct sigaction sa;
|
||||||
|
sa.sa_handler = NULL;
|
||||||
|
sa.sa_sigaction = &SwapHandler;
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = SA_SIGINFO | SA_RESTART;
|
||||||
|
return sigaction(SIGSEGV, &sa, &old_sa_segv) == 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
bool InitSwap() noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ namespace Common {
|
||||||
|
|
||||||
void* AllocateMemoryPages(std::size_t size) noexcept;
|
void* AllocateMemoryPages(std::size_t size) noexcept;
|
||||||
void FreeMemoryPages(void* base, std::size_t size) noexcept;
|
void FreeMemoryPages(void* base, std::size_t size) noexcept;
|
||||||
|
bool InitSwap() noexcept;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class VirtualBuffer final {
|
class VirtualBuffer final {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __OPENORBIS__
|
#ifdef __OPENORBIS__
|
||||||
|
#include <orbis/SystemService.h>
|
||||||
# define STUB_WEAK(name) extern "C" void name() { printf("called " #name); asm volatile("ud2"); }
|
# define STUB_WEAK(name) extern "C" void name() { printf("called " #name); asm volatile("ud2"); }
|
||||||
STUB_WEAK(__cxa_thread_atexit)
|
STUB_WEAK(__cxa_thread_atexit)
|
||||||
STUB_WEAK(__assert)
|
STUB_WEAK(__assert)
|
||||||
|
|
@ -441,10 +442,20 @@ int main(int argc, char** argv) {
|
||||||
[](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
|
[](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
system.RegisterExitCallback([&] {
|
auto const exit_fn = [&] {
|
||||||
|
#ifdef __OPENORBIS__
|
||||||
|
sceSystemServiceLoadExec("EXIT", nullptr);
|
||||||
|
#else
|
||||||
// Just exit right away.
|
// Just exit right away.
|
||||||
exit(0);
|
exit(0);
|
||||||
});
|
#endif
|
||||||
|
};
|
||||||
|
system.RegisterExitCallback(exit_fn);
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
Common::Linux::StartGamemode();
|
||||||
|
#endif
|
||||||
|
|
||||||
void(system.Run());
|
void(system.Run());
|
||||||
if (system.DebuggerEnabled()) {
|
if (system.DebuggerEnabled()) {
|
||||||
system.InitializeDebugger();
|
system.InitializeDebugger();
|
||||||
|
|
@ -456,6 +467,7 @@ int main(int argc, char** argv) {
|
||||||
void(system.Pause());
|
void(system.Pause());
|
||||||
system.ShutdownMainProcess();
|
system.ShutdownMainProcess();
|
||||||
detached_tasks.WaitForAllTasks();
|
detached_tasks.WaitForAllTasks();
|
||||||
|
exit_fn();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue