AK: Port BumpAllocator.h to Windows

This commit is contained in:
R-Goc 2024-11-21 14:15:44 +01:00
parent 001df24935
commit 06f28a055b
No known key found for this signature in database

View file

@ -10,7 +10,12 @@
#include <AK/StdLibExtras.h>
#include <AK/Types.h>
#include <AK/kmalloc.h>
#include <sys/mman.h>
#if defined(AK_OS_WINDOWS)
# include <Windows.h>
# include <Memoryapi.h>
#else
# include <sys/mman.h>
#endif
namespace AK {
@ -73,7 +78,11 @@ public:
}
if constexpr (use_mmap) {
#if defined(AK_OS_WINDOWS)
VirtualFree((LPVOID)chunk, m_chunk_size, MEM_RELEASE);
#else
munmap((void*)chunk, m_chunk_size);
#endif
} else {
kfree_sized((void*)chunk, m_chunk_size);
}
@ -106,10 +115,19 @@ protected:
#ifdef AK_OS_SERENITY
new_chunk = serenity_mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_RANDOMIZED | MAP_PRIVATE, 0, 0, m_chunk_size, "BumpAllocator Chunk");
#else
# if defined(AK_OS_WINDOWS)
new_chunk = VirtualAlloc(NULL, m_chunk_size, MEM_COMMIT, PAGE_READWRITE);
# else
new_chunk = mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
# endif
#endif
#if defined(AK_OS_WINDOWS)
if (new_chunk == NULL)
return false;
#else
if (new_chunk == MAP_FAILED)
return false;
#endif
} else {
new_chunk = kmalloc(m_chunk_size);
if (!new_chunk)