Common: Add proper macros to test for architecture pointer size
The old system of just defining macros available in some other platform
was susceptible to silently using the wrong code if you forgot to
include a particular header. This fixes a crash on non-Windows platforms
introduced by e1fbac3ca1
.
This commit is contained in:
parent
4f4d230dac
commit
fae5933ad6
@ -34,13 +34,6 @@
|
|||||||
#define MEMORY_ALIGNED64(x) __declspec(align(64)) x
|
#define MEMORY_ALIGNED64(x) __declspec(align(64)) x
|
||||||
#define MEMORY_ALIGNED128(x) __declspec(align(128)) x
|
#define MEMORY_ALIGNED128(x) __declspec(align(128)) x
|
||||||
#else
|
#else
|
||||||
// Windows compatibility
|
|
||||||
#ifdef _LP64
|
|
||||||
#define _M_X64 1
|
|
||||||
#else
|
|
||||||
#define _M_IX86 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define __forceinline inline __attribute__((always_inline))
|
#define __forceinline inline __attribute__((always_inline))
|
||||||
#define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
|
#define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
|
||||||
#define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
|
#define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
|
||||||
|
@ -103,7 +103,7 @@ u32 HashEctor(const u8* ptr, int length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _M_X64
|
#if EMU_ARCH_BITS == 64
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Block read - if your platform needs to do endian-swapping or can only
|
// Block read - if your platform needs to do endian-swapping or can only
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/mem_arena.h"
|
#include "common/mem_arena.h"
|
||||||
#include "common/memory_util.h"
|
#include "common/memory_util.h"
|
||||||
|
#include "common/platform.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -198,7 +199,7 @@ void MemArena::ReleaseView(void* view, size_t size)
|
|||||||
|
|
||||||
u8* MemArena::Find4GBBase()
|
u8* MemArena::Find4GBBase()
|
||||||
{
|
{
|
||||||
#ifdef _M_X64
|
#if EMU_ARCH_BITS == 64
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// 64 bit
|
// 64 bit
|
||||||
u8* base = (u8*)VirtualAlloc(0, 0xE1000000, MEM_RESERVE, PAGE_READWRITE);
|
u8* base = (u8*)VirtualAlloc(0, 0xE1000000, MEM_RESERVE, PAGE_READWRITE);
|
||||||
@ -269,7 +270,7 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32
|
|||||||
if (!*view.out_ptr_low)
|
if (!*view.out_ptr_low)
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
#ifdef _M_X64
|
#if EMU_ARCH_BITS == 64
|
||||||
*view.out_ptr = (u8*)arena->CreateView(
|
*view.out_ptr = (u8*)arena->CreateView(
|
||||||
position, view.size, base + view.virtual_address);
|
position, view.size, base + view.virtual_address);
|
||||||
#else
|
#else
|
||||||
@ -305,7 +306,7 @@ bail:
|
|||||||
}
|
}
|
||||||
if (*views[j].out_ptr)
|
if (*views[j].out_ptr)
|
||||||
{
|
{
|
||||||
#ifdef _M_X64
|
#if EMU_ARCH_BITS == 64
|
||||||
arena->ReleaseView(*views[j].out_ptr, views[j].size);
|
arena->ReleaseView(*views[j].out_ptr, views[j].size);
|
||||||
#else
|
#else
|
||||||
if (!(views[j].flags & MV_MIRROR_PREVIOUS))
|
if (!(views[j].flags & MV_MIRROR_PREVIOUS))
|
||||||
@ -336,7 +337,7 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
|
|||||||
arena->GrabLowMemSpace(total_mem);
|
arena->GrabLowMemSpace(total_mem);
|
||||||
|
|
||||||
// Now, create views in high memory where there's plenty of space.
|
// Now, create views in high memory where there's plenty of space.
|
||||||
#ifdef _M_X64
|
#if EMU_ARCH_BITS == 64
|
||||||
u8 *base = MemArena::Find4GBBase();
|
u8 *base = MemArena::Find4GBBase();
|
||||||
// This really shouldn't fail - in 64-bit, there will always be enough
|
// This really shouldn't fail - in 64-bit, there will always be enough
|
||||||
// address space.
|
// address space.
|
||||||
|
@ -71,7 +71,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_M_X64)
|
#if EMU_ARCH_BITS == 64
|
||||||
if ((u64)ptr >= 0x80000000 && low == true)
|
if ((u64)ptr >= 0x80000000 && low == true)
|
||||||
LOG_ERROR(Common_Memory, "Executable memory ended up above 2GB!");
|
LOG_ERROR(Common_Memory, "Executable memory ended up above 2GB!");
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,10 +57,10 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__x86_64__) || defined(_M_X64) || defined(__alpha__) || defined(__ia64__)
|
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__)
|
||||||
#define EMU_ARCHITECTURE_X64
|
#define EMU_ARCH_BITS 64
|
||||||
#else
|
#elif defined(__i386) || defined(_M_IX86) || defined(__arm__) || defined(_M_ARM)
|
||||||
#define EMU_ARCHITECTURE_X86
|
#define EMU_ARCH_BITS 32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user