Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: src/trusted/service_runtime/win/sel_memory.c

Issue 7648002: Modify the NaCl_page_alloc_hint function to use VirtualQuery to check (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698