Skip to content

Commit

Permalink
Common: Remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TellowKrinkle committed Aug 21, 2024
1 parent 0635a0f commit 882fabf
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 96 deletions.
9 changes: 0 additions & 9 deletions common/HostSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,11 @@ static __fi PageProtectionMode PageAccess_Any()
// --------------------------------------------------------------------------------------
namespace HostSys
{
// Maps a block of memory for use as a recompiled code buffer.
// Returns NULL on allocation failure.
extern void* Mmap(void* base, size_t size, const PageProtectionMode& mode);

// Unmaps a block allocated by SysMmap
extern void Munmap(void* base, size_t size);

extern void MemProtect(void* baseaddr, size_t size, const PageProtectionMode& mode);

extern std::string GetFileMappingName(const char* prefix);
extern void* CreateSharedMemory(const char* name, size_t size);
extern void DestroySharedMemory(void* ptr);
extern void* MapSharedMemory(void* handle, size_t offset, void* baseaddr, size_t size, const PageProtectionMode& mode);
extern void UnmapSharedMemory(void* baseaddr, size_t size);

/// JIT write protect for Apple Silicon. Needs to be called prior to writing to any RWX pages.
#if !defined(__APPLE__) || !defined(_M_ARM64)
Expand Down
48 changes: 0 additions & 48 deletions common/Linux/LnxHostSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,6 @@ static __ri uint LinuxProt(const PageProtectionMode& mode)
return lnxmode;
}

void* HostSys::Mmap(void* base, size_t size, const PageProtectionMode& mode)
{
pxAssertMsg((size & (__pagesize - 1)) == 0, "Size is page aligned");

if (mode.IsNone())
return nullptr;

const u32 prot = LinuxProt(mode);

u32 flags = MAP_PRIVATE | MAP_ANONYMOUS;

void* res = mmap(base, size, prot, flags, -1, 0);
if (res == MAP_FAILED)
return nullptr;

return res;
}

void HostSys::Munmap(void* base, size_t size)
{
if (!base)
return;

munmap((void*)base, size);
}

void HostSys::MemProtect(void* baseaddr, size_t size, const PageProtectionMode& mode)
{
pxAssertMsg((size & (__pagesize - 1)) == 0, "Size is page aligned");
Expand Down Expand Up @@ -114,28 +88,6 @@ void HostSys::DestroySharedMemory(void* ptr)
close(static_cast<int>(reinterpret_cast<intptr_t>(ptr)));
}

void* HostSys::MapSharedMemory(void* handle, size_t offset, void* baseaddr, size_t size, const PageProtectionMode& mode)
{
const uint lnxmode = LinuxProt(mode);

int flags = MAP_SHARED;
#ifdef __APPLE__
if (mode.CanExecute())
flags |= MAP_JIT;
#endif
void* ptr = mmap(0, size, lnxmode, flags, static_cast<int>(reinterpret_cast<intptr_t>(handle)), static_cast<off_t>(offset));
if (ptr == MAP_FAILED)
return nullptr;

return ptr;
}

void HostSys::UnmapSharedMemory(void* baseaddr, size_t size)
{
if (munmap(baseaddr, size) != 0)
pxFailRel("Failed to unmap shared memory");
}

#ifndef __APPLE__

size_t HostSys::GetRuntimePageSize()
Expand Down
39 changes: 0 additions & 39 deletions common/Windows/WinHostSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ static DWORD ConvertToWinApi(const PageProtectionMode& mode)
return winmode;
}

void* HostSys::Mmap(void* base, size_t size, const PageProtectionMode& mode)
{
if (mode.IsNone())
return nullptr;

return VirtualAlloc(base, size, MEM_RESERVE | MEM_COMMIT, ConvertToWinApi(mode));
}

void HostSys::Munmap(void* base, size_t size)
{
if (!base)
return;

VirtualFree((void*)base, 0, MEM_RELEASE);
}

void HostSys::MemProtect(void* baseaddr, size_t size, const PageProtectionMode& mode)
{
pxAssert((size & (__pagesize - 1)) == 0);
Expand All @@ -77,29 +61,6 @@ void HostSys::DestroySharedMemory(void* ptr)
CloseHandle(static_cast<HANDLE>(ptr));
}

void* HostSys::MapSharedMemory(void* handle, size_t offset, void* baseaddr, size_t size, const PageProtectionMode& mode)
{
void* ret = MapViewOfFileEx(static_cast<HANDLE>(handle), FILE_MAP_READ | FILE_MAP_WRITE,
static_cast<DWORD>(offset >> 32), static_cast<DWORD>(offset), size, baseaddr);
if (!ret)
return nullptr;

const DWORD prot = ConvertToWinApi(mode);
if (prot != PAGE_READWRITE)
{
DWORD old_prot;
if (!VirtualProtect(ret, size, prot, &old_prot))
pxFail("Failed to protect memory mapping");
}
return ret;
}

void HostSys::UnmapSharedMemory(void* baseaddr, size_t size)
{
if (!UnmapViewOfFile(baseaddr))
pxFail("Failed to unmap shared memory");
}

size_t HostSys::GetRuntimePageSize()
{
SYSTEM_INFO si = {};
Expand Down

0 comments on commit 882fabf

Please sign in to comment.