You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

#include <stdlib.h>
#if defined(__ORBIS__) || defined(__PROSPERO__)
#define _aligned_malloc(s,a) aligned_alloc(a,s)
#define _aligned_realloc(p,s,a) reallocalign(p,s,a)
#define _aligned_free(p) free(p)
#else
#include <malloc.h>
#endif
#define DLL_EXPORT extern "C" __declspec(dllexport)
static void *AllocateMemory(size_t size, size_t alignment)
{
if (size == 0)
return nullptr;
return _aligned_malloc(size, alignment);
}
static void *ReallocateMemory(void *ptr, size_t size, size_t alignment)
{
if (size == 0)
{
free(ptr);
return nullptr;
}
// Ensure we replicate the realloc behavior that EOS expects
if (ptr == nullptr)
{
return _aligned_malloc(size, alignment);
}
return _aligned_realloc(ptr, size, alignment);
}
static void ReleaseMemory(void *ptr)
{
return _aligned_free(ptr);
}
typedef void* (*AllocateMemoryFunc)(size_t, size_t);
typedef void* (*ReallocateMemoryFunc)(void*, size_t, size_t);
typedef void (*ReleaseMemoryFunc)(void*);
// For more information, see: https://ps4.siedev.net/forums/thread/507337/
DLL_EXPORT void EOS_GetMemoryFunctions(AllocateMemoryFunc *allocFunc, ReallocateMemoryFunc *reallocFunc, ReleaseMemoryFunc *releaseFunc)
{
*allocFunc = AllocateMemory;
*reallocFunc = ReallocateMemory;
*releaseFunc = ReleaseMemory;
}