Chromium Code Reviews| Index: src/trusted/service_runtime/win/sel_memory.c |
| =================================================================== |
| --- src/trusted/service_runtime/win/sel_memory.c (revision 6420) |
| +++ src/trusted/service_runtime/win/sel_memory.c (working copy) |
| @@ -24,6 +24,31 @@ |
| #define MSGWIDTH "25" |
| +#if NACL_ARCH_CPU_32_BITS |
|
Mark Seaborn
2011/08/16 17:34:10
As before.
bbudge
2011/08/16 19:46:22
Done.
|
| + |
| +int NaCl_find_sandbox_memory(void **p, |
|
Mark Seaborn
2011/08/16 17:34:10
Can you put a comment in to say that the purpose o
bbudge
2011/08/16 19:46:22
Done.
|
| + size_t num_bytes) { |
| + SYSTEM_INFO sys_info; |
| + MEMORY_BASIC_INFORMATION mem; |
| + char* start; |
|
Mark Seaborn
2011/08/16 17:34:10
Nit: " *" rather than "* "
bbudge
2011/08/16 19:46:22
Done.
|
| + |
| + GetSystemInfo(&sys_info); |
| + start = sys_info.lpMinimumApplicationAddress; |
| + while (VirtualQuery((LPCVOID)start, &mem, sizeof(mem))) { |
|
Mark Seaborn
2011/08/16 17:34:10
I'd suggest checking that the return value is eith
bbudge
2011/08/16 19:46:22
Done.
|
| + if (mem.State == MEM_RESERVE && mem.RegionSize == num_bytes) { |
| + VirtualFree(start, 0, MEM_RELEASE); |
|
Mark Seaborn
2011/08/16 17:34:10
Please check return value. You can use LOG_FATAL
bbudge
2011/08/16 19:46:22
Done.
|
| + *p = start; |
| + return 0; |
| + } |
| + start += mem.RegionSize; |
| + if ((LPVOID)start > sys_info.lpMaximumApplicationAddress) |
|
Mark Seaborn
2011/08/16 17:34:10
Minor nit: maybe '>='?
bbudge
2011/08/16 19:46:22
Done.
|
| + break; |
| + } |
| + return -ENOMEM; |
| +} |
| + |
| +#endif /* NACL_ARCH_CPU_32_BITS */ |
| + |
| /* |
| * NaCl_page_free: free pages allocated with NaCl_page_alloc. |
| * Must start at allocation granularity (NACL_MAP_PAGESIZE) and |
| @@ -48,8 +73,7 @@ |
| } |
| -static |
| -int NaCl_page_alloc_hint(void **p, |
| +int NaCl_page_alloc_at_addr(void **p, |
| size_t num_bytes) { |
| SYSTEM_INFO sys_info; |
| @@ -151,7 +175,7 @@ |
| *p = addr; |
| return 0; |
| retry: |
| - NaClLog(2, "NaCl_page_alloc_hint: retrying w/o hint\n"); |
| + NaClLog(2, "NaCl_page_alloc_at_addr: retrying w/o hint\n"); |
| hint = NULL; |
| } |
| @@ -161,7 +185,7 @@ |
| int NaCl_page_alloc(void **p, |
| size_t num_bytes) { |
| *p = NULL; |
| - return NaCl_page_alloc_hint(p, num_bytes); |
| + return NaCl_page_alloc_at_addr(p, num_bytes); |
| } |
| /* |
| @@ -203,7 +227,7 @@ |
| NaClLog(LOG_INFO, "NaCl_page_alloc_randomized: hint 0x%"NACL_PRIxPTR"\n", |
| (uintptr_t) *p); |
| - neg_errno = NaCl_page_alloc_hint(p, size); |
| + neg_errno = NaCl_page_alloc_at_addr(p, size); |
| if (0 == neg_errno) { |
| break; |
| } |
| @@ -213,7 +237,7 @@ |
| "NaCl_page_alloc_randomized: failed (%d), dropping hints\n", |
| -neg_errno); |
| *p = 0; |
| - neg_errno = NaCl_page_alloc_hint(p, size); |
| + neg_errno = NaCl_page_alloc_at_addr(p, size); |
| } |
| return neg_errno; |
| } |