X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fmemory.c;h=c8166af4fb9bc2bf7f5da71f3e8d88000960f759;hb=7b64f5e7f00e445a5637e9e3289a1332a14d28e5;hp=3f0091d3724676640cb07d6f709d11342a65c64c;hpb=33de4e7776814ede6263b6563f5b8ff3ff20e33e;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/memory.c b/AcessNative/ld-acess_src/memory.c index 3f0091d3..c8166af4 100644 --- a/AcessNative/ld-acess_src/memory.c +++ b/AcessNative/ld-acess_src/memory.c @@ -21,9 +21,26 @@ int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount) size_t size = (VirtAddr & 0xFFF) + ByteCount; void *tmp; #if __WIN32__ - tmp = VirtualAlloc((void*)base, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + do + { + MEMORY_BASIC_INFORMATION info; + VirtualQuery( (void*)base, &info, sizeof(info) ); + if( info.State != MEM_FREE ) { + printf("ERROR: Unable to allocate memory %p+0x%x, already allocated\n", + (void*)base, size); + base += 0x1000; + if( size < 0x1000 ) + return 0; + size -= 0x1000; + } + else + break; + } while( size >= 0x1000 ); + tmp = VirtualAlloc((void*)base, size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE); if( tmp == NULL ) { - printf("ERROR: Unable to allocate memory (0x%x)\n", (int)GetLastError()); + printf("ERROR: Unable to allocate memory %p+%x (0x%x)\n", + (void*)base, size, + (int)GetLastError()); return -1; } #else