- base_non_committed = VirtualAlloc ( NULL
- , size_reserved_pool
- , MEM_RESERVE
- , PAGE_READWRITE
- );
- membase = base_non_committed;
- if ( base_non_committed == 0 ) {
- errorBelch("getMBlocks: VirtualAlloc MEM_RESERVE %lu failed with: %ld\n", size_reserved_pool, GetLastError());
- ret=(void*)-1;
- } else {
- end_non_committed = (char*)base_non_committed + (unsigned long)size_reserved_pool;
- /* The returned pointer is not aligned on a mega-block boundary. Make it. */
- base_mblocks = (char*)((unsigned long)base_non_committed & (unsigned long)~MBLOCK_MASK) + MBLOCK_SIZE;
-# if 0
- debugBelch("getMBlocks: Dropping %d bytes off of 256M chunk\n",
- (unsigned)base_mblocks - (unsigned)base_non_committed);
-# endif
-
- if ( ((char*)base_mblocks + size) > end_non_committed ) {
- debugBelch("getMBlocks: oops, committed too small a region to start with.");
- ret=(void*)-1;
- } else {
- next_request = base_mblocks;
- }
- }
- }
- /* Commit the mega block(s) to phys mem */
- if ( ret != (void*)-1 ) {
- ret = VirtualAlloc(next_request, size, MEM_COMMIT, PAGE_READWRITE);
- if (ret == NULL) {
- debugBelch("getMBlocks: VirtualAlloc MEM_COMMIT %lu failed with: %ld\n", size, GetLastError());
- ret=(void*)-1;
- }
- }