fixed win32 virtualalloc functions
This commit is contained in:
parent
f17ec84b9c
commit
6f0bbf68ae
@ -33,7 +33,7 @@ moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size)
|
|||||||
heap = (moo_heap_t*)moo->vmprim.alloc_heap(moo, MOO_SIZEOF(*heap) + size);
|
heap = (moo_heap_t*)moo->vmprim.alloc_heap(moo, MOO_SIZEOF(*heap) + size);
|
||||||
if (!heap)
|
if (!heap)
|
||||||
{
|
{
|
||||||
moo_ooch_t* oldmsg = moo_backuperrmsg(moo);
|
const moo_ooch_t* oldmsg = moo_backuperrmsg(moo);
|
||||||
moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to allocate heap - %js", oldmsg);
|
moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to allocate heap - %js", oldmsg);
|
||||||
return MOO_NULL;
|
return MOO_NULL;
|
||||||
}
|
}
|
||||||
|
@ -625,7 +625,6 @@ static void* alloc_heap (moo_t* moo, moo_oow_t size)
|
|||||||
moo_oow_t actual_size, align_size;
|
moo_oow_t actual_size, align_size;
|
||||||
HINSTANCE k32;
|
HINSTANCE k32;
|
||||||
SIZE_T (*k32_GetLargePageMinimum) (void);
|
SIZE_T (*k32_GetLargePageMinimum) (void);
|
||||||
DWORD va_flags;
|
|
||||||
|
|
||||||
align_size = 2 * 1024 * 1024;
|
align_size = 2 * 1024 * 1024;
|
||||||
|
|
||||||
@ -640,24 +639,18 @@ static void* alloc_heap (moo_t* moo, moo_oow_t size)
|
|||||||
actual_size = MOO_SIZEOF(moo_oow_t) + size;
|
actual_size = MOO_SIZEOF(moo_oow_t) + size;
|
||||||
actual_size = MOO_ALIGN_POW2(actual_size, align_size);
|
actual_size = MOO_ALIGN_POW2(actual_size, align_size);
|
||||||
|
|
||||||
va_flags = MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES;
|
if (msw_set_privilege(moo, TEXT("SeLockMemoryPrivilege"), TRUE) <= -1) return MOO_NULL;
|
||||||
if (msw_set_privilege(moo, TEXT("SeLockMemoryPrivilege"), TRUE) <= -1) goto large_page_fail;
|
|
||||||
|
|
||||||
va_do:
|
ptr = VirtualAlloc(MOO_NULL, actual_size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
|
||||||
ptr = VirtualAlloc(MOO_NULL, actual_size, va_flags, PAGE_READWRITE);
|
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
{
|
{
|
||||||
if ((va_flags & MEM_LARGE_PAGES) && GetLastError() == ERROR_INVALID_PARAMETER)
|
DWORD errcode = GetLastError();
|
||||||
{
|
msw_set_privilege(moo, TEXT("SeLockMemoryPrivilege"), FALSE);
|
||||||
large_page_fail:
|
moo_seterrwithsyserr (moo, 1, errcode);
|
||||||
va_flags &= ~MEM_LARGE_PAGES;
|
|
||||||
goto va_do;
|
|
||||||
}
|
|
||||||
|
|
||||||
moo_seterrwithsyserr (moo, 1, GetLastError());
|
|
||||||
return MOO_NULL;
|
return MOO_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msw_set_privilege(moo, TEXT("SeLockMemoryPrivilege"), FALSE);
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
||||||
#elif defined(HAVE_MMAP) && defined(HAVE_MUNMAP) && defined(MAP_ANONYMOUS)
|
#elif defined(HAVE_MMAP) && defined(HAVE_MUNMAP) && defined(MAP_ANONYMOUS)
|
||||||
|
Loading…
Reference in New Issue
Block a user