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

Side by Side Diff: src/trusted/service_runtime/arch/arm/sel_addrspace_arm.c

Issue 7677036: Enable the service runtime to use a zero-based sandbox on Linux. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/nacl_error_code.h" 9 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
10 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 10 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
11 #include "native_client/src/trusted/service_runtime/sel_memory.h" 11 #include "native_client/src/trusted/service_runtime/sel_memory.h"
12 12
13 13
14 #define POST_ADDR_SPACE_GUARD_SIZE (2 * NACL_PAGESIZE)
15
16 /* 14 /*
17 * On ARM, we cheat slightly: we add two pages to the requested allocation! 15 * On ARM, we cheat slightly: we add two pages to the requested allocation!
18 * This accomodates the guard region we require at the top end of untrusted 16 * This accomodates the guard region we require at the top end of untrusted
19 * memory. 17 * memory.
20 */ 18 */
19 #define POST_ADDR_SPACE_GUARD_SIZE (2 * NACL_PAGESIZE)
20
21 /* NOTE: This routine is almost identical to the x86_32 version.
22 */
21 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) { 23 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) {
22 CHECK(mem); 24 const void* ONE_MEGABYTE = (void *)1024*1024;
Mark Seaborn 2011/08/18 23:09:45 Nit: " *" style not "* " in this code.
Brad Chen 2011/08/19 00:24:35 Done.
25 int result;
26
27 CHECK(NULL != mem);
23 28
24 addrsp_size += POST_ADDR_SPACE_GUARD_SIZE; 29 addrsp_size += POST_ADDR_SPACE_GUARD_SIZE;
25 addrsp_size -= NACL_TRAMPOLINE_START; 30 #if NACL_LINUX
31 /*
32 * On 32 bit Linux, a 1 gigabyte block of address space may be reserved at
33 * the zero-end of the address space during process creation, to address
34 * sandbox layout requirements on ARM and performance issues on Intel ATOM.
35 * Look for this pre-reserved block and if found, pass its address to the
36 * page allocation function.
37 */
38 if (!NaCl_find_prereserved_sandbox_memory(mem, addrsp_size)) {
39 /* zero-based sandbox not pre-reserved */
Mark Seaborn 2011/08/18 23:09:45 Capitalise the start of the sentence, please.
Brad Chen 2011/08/19 00:24:35 Done.
40 return LOAD_NO_MEMORY;
41 } else {
42 /* sanity check zero sandbox base address */
Mark Seaborn 2011/08/18 23:09:45 Capitalise.
Brad Chen 2011/08/19 00:24:35 Done.
43 if (0 == *mem || ONE_MEGABYTE > *mem)
44 return LOAD_NO_MEMORY;
26 45
27 *mem = (void *) NACL_TRAMPOLINE_START; 46 /*
28 if (NaCl_page_alloc_at_addr(mem, addrsp_size) != 0) { 47 * When creating a zero-based sandbox, we do not allocate the first 64K of
48 * pages beneath the trampolines, because -- on Linux at least -- we cannot.
49 * Instead, we allocate starting at the trampolines, and then coerce the
50 * "mem" out parameter.
51 */
52 addrsp_size -= NACL_TRAMPOLINE_START;
53 *mem = (void *) NACL_TRAMPOLINE_START;
54 result = NaCl_page_alloc_at_addr(mem, addrsp_size);
55 *mem = 0;
56 }
57 #else
58 # error "I only know how to allocate memory for ARM on Linux."
59 #endif
60 if (0 != result) {
29 NaClLog(2, 61 NaClLog(2,
30 "NaClAllocateSpace: NaCl_page_alloc_at_addr 0x%08"NACL_PRIxPTR 62 "NaClAllocateSpace: NaCl_page_alloc_at_addr 0x%08"NACL_PRIxPTR
31 " failed\n", 63 " failed\n",
32 (uintptr_t) *mem); 64 (uintptr_t) *mem);
33 return LOAD_NO_MEMORY; 65 return LOAD_NO_MEMORY;
34 } 66 }
35 NaClLog(4, "NaClAllocateSpace: %"NACL_PRIxPTR", %"NACL_PRIxS"\n", 67 NaClLog(4, "NaClAllocateSpace: %"NACL_PRIxPTR", %"NACL_PRIxS"\n",
36 (uintptr_t) *mem, 68 (uintptr_t) *mem,
37 addrsp_size); 69 addrsp_size);
38 70
39 /*
40 * makes sel_ldr think that the module's address space is at 0x0, this where
41 * it should be
42 */
43 *mem = 0x0;
44
45 return LOAD_OK; 71 return LOAD_OK;
46 } 72 }
47 73
48 /* 74 /*
49 * In the ARM sandboxing scheme we put the NaCl module at low virtual 75 * In the ARM sandboxing scheme we put the NaCl module at low virtual
50 * address -- and thus there can only ever be one running NaCl app per 76 * address -- and thus there can only ever be one running NaCl app per
51 * sel_ldr process -- to simplify the address masking etc needed for 77 * sel_ldr process -- to simplify the address masking etc needed for
52 * the sandboxing. All memory below ((uintptr_t) 1) << nap->addr_bits 78 * the sandboxing. All memory below ((uintptr_t) 1) << nap->addr_bits
53 * is accessible to the NaCl app, and modulo page protection, 79 * is accessible to the NaCl app, and modulo page protection,
54 * potentially writable. Page protection is, of course, used to 80 * potentially writable. Page protection is, of course, used to
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 * NB: the pages just mapped are OUTSIDE of the address space of the 129 * NB: the pages just mapped are OUTSIDE of the address space of the
104 * NaCl module. We should not track them in the Vmmap structure, 130 * NaCl module. We should not track them in the Vmmap structure,
105 * since that's to track addressable memory for mapping and unmapping. 131 * since that's to track addressable memory for mapping and unmapping.
106 * 132 *
107 * This means that because these pages are implicit and not tracked, 133 * This means that because these pages are implicit and not tracked,
108 * we should have a hook to tear down these pages as part of the 134 * we should have a hook to tear down these pages as part of the
109 * NaClApp dtor. 135 * NaClApp dtor.
110 */ 136 */
111 return LOAD_OK; 137 return LOAD_OK;
112 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698