#include "mozilla/Types.h"
#include <windows.h>
#if defined(MOZ_MEMORY)
# define MOZ_MEMORY_IMPL
# include "mozmemory_wrap.h"
# define MALLOC_DECL(name, return_type, ...) \
MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
# define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
# include "malloc_decls.h"
#else
# include <malloc.h>
# define malloc_impl malloc
# define calloc_impl calloc
# define realloc_impl realloc
# define free_impl free
#endif
#pragma warning(disable : 4273)
MFBT_API
LPVOID WINAPI HeapAlloc(_In_ HANDLE hHeap, _In_ DWORD dwFlags,
_In_ SIZE_T dwBytes) {
if (dwFlags & HEAP_ZERO_MEMORY) {
return calloc_impl(1, dwBytes);
}
return malloc_impl(dwBytes);
}
MFBT_API
LPVOID WINAPI HeapReAlloc(_In_ HANDLE hHeap, _In_ DWORD dwFlags,
_In_ LPVOID lpMem, _In_ SIZE_T dwBytes) {
if (dwFlags & (HEAP_REALLOC_IN_PLACE_ONLY | HEAP_ZERO_MEMORY)) {
return NULL;
}
return realloc_impl(lpMem, dwBytes);
}
MFBT_API
BOOL WINAPI HeapFree(_In_ HANDLE hHeap, _In_ DWORD dwFlags, _In_ LPVOID lpMem) {
free_impl(lpMem);
return true;
}