Jamie Reece Wilson
8be1afe570
[+] AuMemory::HeapAdapterInterface to describe aforementioned heap allocators of a very limited API [+] AuMemory::HeapAdapter[Unique,Shared,] [+] HeapWin32Adapter to convert HANDLE hHeaps of win32s CreateHeap (RtlCreateHeap?) into AuMemory::Heaps
83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
/***
|
|
Copyright (C) 2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuHeapAdapter.NT.cpp
|
|
File: Heap.hpp
|
|
Date: 2024-7-17
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "AuHeap.hpp"
|
|
#include "AuHeapAdapter.hpp"
|
|
|
|
namespace Aurora::Memory
|
|
{
|
|
static void *Win32HeapAllocate(HeapAdapterHandle *pHandle,
|
|
AuUInt uLength,
|
|
AuUInt uAlignment)
|
|
{
|
|
auto hHandle = (HANDLE)pHandle->pReserved[0];
|
|
return HeapAlloc(hHandle, 0, uLength);
|
|
}
|
|
|
|
static void Win32HeapFree(HeapAdapterHandle *pHandle,
|
|
void *pPointer)
|
|
{
|
|
auto hHandle = (HANDLE)pHandle->pReserved[0];
|
|
HeapFree(hHandle, 0, pPointer);
|
|
}
|
|
|
|
struct Win32HeapAllocator : ImplHeapAdapter
|
|
{
|
|
Win32HeapAllocator()
|
|
{
|
|
|
|
}
|
|
|
|
Win32HeapAllocator(void *hHeap)
|
|
{
|
|
if (!this->Init(hHeap))
|
|
{
|
|
AU_THROW_CONST_STRING("Invalid heap adapter configuration");
|
|
}
|
|
}
|
|
|
|
bool Init(void *hHeap)
|
|
{
|
|
if (!hHeap)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
HeapAdapterInterface heap;
|
|
heap.handle.pReserved[0] = hHeap;
|
|
heap.fFree = Win32HeapFree;
|
|
heap.fAllocate = Win32HeapAllocate;
|
|
return ImplHeapAdapter::Init(heap);
|
|
}
|
|
};
|
|
|
|
AUKN_SYM Heap *HeapWin32AdapterNew(void *hHeap)
|
|
{
|
|
auto pHeap = _new Win32HeapAllocator();
|
|
if (!pHeap)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
if (!pHeap->Init(hHeap))
|
|
{
|
|
delete pHeap;
|
|
return nullptr;
|
|
}
|
|
|
|
return pHeap;
|
|
}
|
|
|
|
AUKN_SYM void HeapWin32AdapterRelease(Heap *pHeap)
|
|
{
|
|
static_cast<Win32HeapAllocator *>(pHeap)->RequestTermination();
|
|
}
|
|
|
|
AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, HeapWin32Adapter, Win32HeapAllocator, (void *, hHeap))
|
|
} |