mirror of
https://github.com/pound-emu/pound.git
synced 2025-12-15 10:36:59 +00:00
Merge branch 'Xphalnos-VirtualAlloc' into arm64
Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
commit
0d4e5fd765
2 changed files with 18 additions and 7 deletions
|
|
@ -1,7 +1,10 @@
|
||||||
#include "arena.h"
|
#include "arena.h"
|
||||||
#include "common/passert.h"
|
#include "common/passert.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#ifndef WIN32
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <Windows.h>
|
||||||
|
#else
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -10,12 +13,15 @@ namespace pound::host::memory
|
||||||
arena_t arena_init(size_t capacity)
|
arena_t arena_init(size_t capacity)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO(GloriousTaco:memory): Replace malloc with a windows memory mapping API.
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
auto data = static_cast<uint8_t*>(malloc(sizeof(size_t) * capacity));
|
void* const data = ::VirtualAlloc(nullptr, capacity, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||||
|
if (NULL == data)
|
||||||
|
{
|
||||||
|
return {0, 0, nullptr}; // Return invalid arena on failure
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
void* data = ::mmap(nullptr, capacity, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
void* const data = ::mmap(nullptr, capacity, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
if (data == MAP_FAILED)
|
if (MAP_FAILED == data)
|
||||||
{
|
{
|
||||||
return {0, 0, nullptr}; // Return invalid arena on failure
|
return {0, 0, nullptr}; // Return invalid arena on failure
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +57,12 @@ void arena_free(memory::arena_t* arena)
|
||||||
PVM_ASSERT(arena != nullptr);
|
PVM_ASSERT(arena != nullptr);
|
||||||
arena->capacity = 0;
|
arena->capacity = 0;
|
||||||
arena->size = 0;
|
arena->size = 0;
|
||||||
|
|
||||||
// TODO(GloriousTaco:memory): Replace free with a memory safe alternative.
|
// TODO(GloriousTaco:memory): Replace free with a memory safe alternative.
|
||||||
|
#ifdef WIN32
|
||||||
|
VirtualFree(arena->data, 0, MEM_RELEASE);
|
||||||
|
#else
|
||||||
free(arena->data);
|
free(arena->data);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} // namespace pound::host::memory
|
} // namespace pound::host::memory
|
||||||
|
|
|
||||||
|
|
@ -59,13 +59,13 @@ struct arena_allocator
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
inline bool operator==(const arena_allocator<T>& a, const arena_allocator<U>& b)
|
inline constexpr bool operator==(const arena_allocator<T>& a, const arena_allocator<U>& b)
|
||||||
{
|
{
|
||||||
return a.arena == b.arena;
|
return a.arena == b.arena;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
inline bool operator!=(const arena_allocator<T>& a, const arena_allocator<U>& b)
|
inline constexpr bool operator!=(const arena_allocator<T>& a, const arena_allocator<U>& b)
|
||||||
{
|
{
|
||||||
return a.arena != b.arena;
|
return a.arena != b.arena;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue