1
0
Fork 0
forked from suyu/suyu

Common: Correctly set ptr to null if mmap fails in memory_util

On POSIX systems mmap will return MAP_FAILED ((void*)-1) instead of a null pointer.
This commit is contained in:
Lioncash 2014-08-17 14:08:39 -04:00
parent d1c2b76ad1
commit cc9f352b66

View file

@ -51,13 +51,13 @@ void* AllocateExecutableMemory(size_t size, bool low)
// printf("Mapped executable memory at %p (size %ld)\n", ptr, // printf("Mapped executable memory at %p (size %ld)\n", ptr,
// (unsigned long)size); // (unsigned long)size);
#if defined(__FreeBSD__) #ifdef _WIN32
if (ptr == nullptr)
{
#else
if (ptr == MAP_FAILED) if (ptr == MAP_FAILED)
{ {
ptr = NULL; ptr = nullptr;
#else
if (ptr == NULL)
{
#endif #endif
PanicAlert("Failed to allocate executable memory"); PanicAlert("Failed to allocate executable memory");
} }
@ -88,6 +88,9 @@ void* AllocateMemoryPages(size_t size)
#else #else
void* ptr = mmap(0, size, PROT_READ | PROT_WRITE, void* ptr = mmap(0, size, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0); MAP_ANON | MAP_PRIVATE, -1, 0);
if (ptr == MAP_FAILED)
ptr = nullptr;
#endif #endif
// printf("Mapped memory at %p (size %ld)\n", ptr, // printf("Mapped memory at %p (size %ld)\n", ptr,