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

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
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)
@@ -14,6 +14,7 @@
#include <windows.h>
#include <string.h>
+#include "native_client/src/shared/platform/nacl_check.h"
#include "native_client/src/shared/platform/nacl_global_secure_random.h"
#include "native_client/src/shared/platform/nacl_log.h"
#include "native_client/src/shared/platform/win/xlate_system_error.h"
@@ -24,7 +25,50 @@
#define MSGWIDTH "25"
+#if NACL_BUILD_SUBARCH == 32
+
/*
+ * This function searches for sandbox memory that has been reserved by
+ * the parent process on our behalf. We pre-reserve the sandbox on 32-bit
+ * systems because otherwise the address space may become fragmented, making
+ * the large sandbox request fail.
+ */
+int NaCl_find_prereserved_sandbox_memory(void **p,
+ size_t num_bytes) {
+ SYSTEM_INFO sys_info;
+ MEMORY_BASIC_INFORMATION mem;
+ char *start;
+ SIZE_T mem_size;
+
+ GetSystemInfo(&sys_info);
+ start = sys_info.lpMinimumApplicationAddress;
+ while (mem_size = VirtualQuery((LPCVOID)start, &mem, sizeof(mem))) {
Mark Seaborn 2011/08/16 20:18:43 I wouldn't put assignments inside while() or if().
bbudge 2011/08/16 20:35:58 Done.
+ CHECK(mem_size == sizeof(mem));
+
+ if (mem.State == MEM_RESERVE &&
+ mem.AllocationProtect == PAGE_NOACCESS &&
+ mem.RegionSize == num_bytes) {
+ if (!VirtualFree(start, 0, MEM_RELEASE)) {
+ DWORD err = GetLastError();
+ NaClLog(LOG_FATAL,
+ "NaCl_find_prereserved_sandbox_memory: VirtualFree(0x%016"
Mark Seaborn 2011/08/16 20:18:43 Indent args to align with '('
bbudge 2011/08/16 20:35:58 Done.
+ NACL_PRIxPTR", 0, MEM_RELEASE) failed "
+ "with error 0x%X\n",
+ (uintptr_t) start, err);
+ }
+ *p = start;
+ return 0;
+ }
+ start += mem.RegionSize;
+ if ((LPVOID)start >= sys_info.lpMaximumApplicationAddress)
+ 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
* number of bytes must be a multiple of allocation granularity.
@@ -48,8 +92,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 +194,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 +204,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 +246,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 +256,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;
}

Powered by Google App Engine
This is Rietveld 408576698