OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2009 The Native Client Authors. All rights reserved. | 2 * Copyright 2009 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/src/include/nacl_platform.h" | 7 #include "native_client/src/include/nacl_platform.h" |
8 #include "native_client/src/shared/platform/nacl_check.h" | 8 #include "native_client/src/shared/platform/nacl_check.h" |
9 #include "native_client/src/trusted/service_runtime/sel_memory.h" | 9 #include "native_client/src/trusted/service_runtime/sel_memory.h" |
10 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 10 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
11 | 11 |
12 | |
13 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) { | 12 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) { |
14 int result; | 13 int result; |
15 | 14 |
16 CHECK(NULL != mem); | 15 CHECK(NULL != mem); |
17 | 16 |
18 #ifdef NACL_SANDBOX_FIXED_AT_ZERO | 17 #ifdef NACL_SANDBOX_FIXED_AT_ZERO |
19 /* | 18 /* |
20 * When creating a zero-based sandbox, we do not allocate the first 64K of | 19 * When creating a zero-based sandbox, we do not allocate the first 64K of |
21 * pages beneath the trampolines, because -- on Linux at least -- we cannot. | 20 * pages beneath the trampolines, because -- on Linux at least -- we cannot. |
22 * Instead, we allocate starting at the trampolines, and then coerce the | 21 * Instead, we allocate starting at the trampolines, and then coerce the |
23 * out parameter. | 22 * out parameter. |
24 */ | 23 */ |
25 addrsp_size -= NACL_TRAMPOLINE_START; | 24 addrsp_size -= NACL_TRAMPOLINE_START; |
26 *mem = (void *) NACL_TRAMPOLINE_START; | 25 *mem = (void *) NACL_TRAMPOLINE_START; |
27 result = NaCl_page_alloc_at_addr(mem, addrsp_size); | 26 result = NaCl_page_alloc_at_addr(mem, addrsp_size); |
28 *mem = 0; | 27 *mem = 0; |
28 #elif NACL_WINDOWS && NACL_BUILD_SUBARCH == 32 | |
29 /* | |
30 * On 32 bit Windows XP, a 1Gb region of address space is reserved before | |
Mark Seaborn
2011/08/16 20:18:43
Just say "32-bit Windows". It's not just XP.
| |
31 * starting up this process to make sure we can get a contiguous block. Look | |
32 * for it and if found, pass the address to NaCl_page_alloc_at_addr so it can | |
33 * use this pre-reserved block. | |
34 */ | |
35 if (0 == NaCl_find_prereserved_sandbox_memory(mem, addrsp_size)) { | |
36 result = NaCl_page_alloc_at_addr(mem, addrsp_size); | |
37 } else { | |
38 result = NaCl_page_alloc(mem, addrsp_size); | |
39 } | |
29 #else | 40 #else |
30 result = NaCl_page_alloc(mem, addrsp_size); | 41 result = NaCl_page_alloc(mem, addrsp_size); |
31 #endif | 42 #endif |
32 | 43 |
33 if (0 != result) { | 44 if (0 != result) { |
34 NaClLog(2, | 45 NaClLog(2, |
35 "NaClAllocateSpace: NaCl_page_alloc 0x%08"NACL_PRIxPTR | 46 "NaClAllocateSpace: NaCl_page_alloc 0x%08"NACL_PRIxPTR |
36 " failed\n", | 47 " failed\n", |
37 (uintptr_t) *mem); | 48 (uintptr_t) *mem); |
38 return LOAD_NO_MEMORY; | 49 return LOAD_NO_MEMORY; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 NACL_SYSCALL_START_ADDR >> NACL_PAGESHIFT, | 83 NACL_SYSCALL_START_ADDR >> NACL_PAGESHIFT, |
73 PROT_NONE, | 84 PROT_NONE, |
74 (struct NaClMemObj *) NULL)) { | 85 (struct NaClMemObj *) NULL)) { |
75 NaClLog(LOG_ERROR, ("NaClMemoryProtection: NaClVmmapAdd failed" | 86 NaClLog(LOG_ERROR, ("NaClMemoryProtection: NaClVmmapAdd failed" |
76 " (NULL pointer guard page)\n")); | 87 " (NULL pointer guard page)\n")); |
77 return LOAD_MPROTECT_FAIL; | 88 return LOAD_MPROTECT_FAIL; |
78 } | 89 } |
79 | 90 |
80 return LOAD_OK; | 91 return LOAD_OK; |
81 } | 92 } |
OLD | NEW |