mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Port BumpAllocator.h to Windows
This commit is contained in:
parent
001df24935
commit
06f28a055b
1 changed files with 19 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue