Chromium Code Reviews| Index: src/trusted/service_runtime/win/sel_memory.c |
| =================================================================== |
| --- src/trusted/service_runtime/win/sel_memory.c (revision 6397) |
| +++ src/trusted/service_runtime/win/sel_memory.c (working copy) |
| @@ -61,6 +61,10 @@ |
| void *chunk; |
| void *unroll; |
| + MEMORY_BASIC_INFORMATION mem; |
| + const SIZE_T kOneGb = 0x40000000; |
| + char* start; |
| + |
| /* |
| * We have to allocate every 64KB -- the windows allocation |
| * granularity -- because VirtualFree will only accept an address |
| @@ -101,11 +105,32 @@ |
| */ |
| num_bytes = NaClRoundAllocPage(num_bytes); |
| + /* |
| + * If the request is for 1Gb (the sandbox), look for a memory region that |
| + * was reserved by our parent process. |
| + */ |
| + addr = 0; |
| + if (num_bytes == kOneGb) { |
|
Mark Seaborn
2011/08/12 21:57:54
Having a special case for 1GB in NaCl_page_alloc()
|
| + start = sys_info.lpMinimumApplicationAddress; |
| + while (VirtualQuery((LPCVOID)start, &mem, sizeof(mem))) |
| + { |
|
Mark Seaborn
2011/08/12 21:57:54
Style: '{' should be on previous line
|
| + if (mem.State == MEM_RESERVE && mem.RegionSize == kOneGb) |
| + { |
|
Mark Seaborn
2011/08/12 21:57:54
Ditto
|
| + addr = start; |
| + break; |
| + } |
| + start += mem.RegionSize; |
| + if ((LPVOID)start > sys_info.lpMaximumApplicationAddress) |
| + break; |
| + } |
| + } |
| + |
| for (attempt_count = 0; |
| attempt_count < NACL_MEMORY_ALLOC_RETRY_MAX; |
| ++attempt_count) { |
| - addr = VirtualAlloc(hint, num_bytes, MEM_RESERVE, PAGE_NOACCESS); |
| + if (addr == NULL) |
| + addr = VirtualAlloc(hint, num_bytes, MEM_RESERVE, PAGE_NOACCESS); |
| if (addr == NULL) { |
| NaClLog(0, |
| "NaCl_page_alloc: VirtualAlloc(*,0x%"NACL_PRIxS") failed\n", |
| @@ -153,6 +178,10 @@ |
| retry: |
| NaClLog(2, "NaCl_page_alloc_hint: retrying w/o hint\n"); |
| hint = NULL; |
| + /* |
| + * If the parent process had reserved memory, it's gone now. |
| + */ |
| + addr = NULL; |
| } |
| return -ENOMEM; |