| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * 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/arch/sel_ldr_arch.h" | 9 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" |
| 10 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 10 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
| 11 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" | 11 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" |
| 12 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 12 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 13 #include "native_client/src/trusted/service_runtime/sel_memory.h" | 13 #include "native_client/src/trusted/service_runtime/sel_memory.h" |
| 14 | 14 |
| 15 | 15 |
| 16 /* NOTE: This routine is almost identical to the x86_32 version. | 16 /* NOTE: This routine is almost identical to the x86_32 version. |
| 17 */ | 17 */ |
| 18 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) { | 18 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) { |
| 19 int result; | 19 int result; |
| 20 void *tmp_mem = (void *) NACL_TRAMPOLINE_START; | 20 void *tmp_mem = (void *) NACL_TRAMPOLINE_START; |
| 21 | 21 |
| 22 CHECK(NULL != mem); | 22 CHECK(NULL != mem); |
| 23 | 23 |
| 24 /* | 24 /* |
| 25 * On ARM, we cheat slightly: we add two pages to the requested | 25 * On Mips, we also cheat slightly: we add two pages to the requested |
| 26 * allocation! This accomodates the guard region we require at the | 26 * allocation! This accomodates the guard region we require at the |
| 27 * top end of untrusted memory. | 27 * top end of untrusted memory. |
| 28 */ | 28 */ |
| 29 addrsp_size += NACL_ADDRSPACE_UPPER_GUARD_SIZE; | 29 addrsp_size += NACL_ADDRSPACE_UPPER_GUARD_SIZE; |
| 30 | 30 |
| 31 NaClAddrSpaceBeforeAlloc(addrsp_size); | 31 NaClAddrSpaceBeforeAlloc(addrsp_size); |
| 32 | 32 |
| 33 /* | 33 /* |
| 34 * On 32 bit Linux, a 1 gigabyte block of address space may be reserved at | 34 * On 32 bit Linux, a 1 gigabyte block of address space may be reserved at |
| 35 * the zero-end of the address space during process creation, to address | 35 * the zero-end of the address space during process creation, to address |
| 36 * sandbox layout requirements on ARM and performance issues on Intel ATOM. | 36 * sandbox layout requirements on Mips and performance issues on Intel ATOM. |
| 37 * Look for this prereserved block and if found, pass its address to the | 37 * Look for this pre-reserved block and if found, pass its address to the |
| 38 * page allocation function. | 38 * page allocation function. |
| 39 */ | 39 */ |
| 40 if (!NaClFindPrereservedSandboxMemory(mem, addrsp_size)) { | 40 if (!NaClFindPrereservedSandboxMemory(mem, addrsp_size)) { |
| 41 /* On ARM, we should always have prereserved sandbox memory. */ | 41 /* On Mips, we should always have prereserved sandbox memory. */ |
| 42 NaClLog(LOG_ERROR, "NaClAllocateSpace:" | 42 NaClLog(LOG_ERROR, "NaClAllocateSpace:" |
| 43 " Could not find correct amount of prereserved memory" | 43 " Could not find correct amount of prereserved memory" |
| 44 " (looked for 0x%016"NACL_PRIxS" bytes).\n", | 44 " (looked for 0x%016"NACL_PRIxS" bytes).\n", |
| 45 addrsp_size); | 45 addrsp_size); |
| 46 return LOAD_NO_MEMORY; | 46 return LOAD_NO_MEMORY; |
| 47 } | 47 } |
| 48 |
| 48 /* | 49 /* |
| 49 * When creating a zero-based sandbox, we do not allocate the first 64K of | 50 * When creating a zero-based sandbox, we do not allocate the first 64K of |
| 50 * pages beneath the trampolines, because -- on Linux at least -- we cannot. | 51 * pages beneath the trampolines, because -- on Linux at least -- we cannot. |
| 51 * Instead, we allocate starting at the trampolines, and then coerce the | 52 * Instead, we allocate starting at the trampolines, and then coerce the |
| 52 * "mem" out parameter. | 53 * "mem" out parameter. |
| 53 */ | 54 */ |
| 54 CHECK(*mem == NULL); | 55 CHECK(*mem == NULL); |
| 55 addrsp_size -= NACL_TRAMPOLINE_START; | 56 addrsp_size -= NACL_TRAMPOLINE_START; |
| 56 result = NaCl_page_alloc_at_addr(&tmp_mem, addrsp_size); | 57 result = NaCl_page_alloc_at_addr(&tmp_mem, addrsp_size); |
| 57 | 58 |
| 58 if (0 != result) { | 59 if (0 != result) { |
| 59 NaClLog(2, | 60 NaClLog(2, |
| 60 "NaClAllocateSpace: NaCl_page_alloc_at_addr 0x%08"NACL_PRIxPTR | 61 "NaClAllocateSpace: NaCl_page_alloc_at_addr 0x%08"NACL_PRIxPTR |
| 61 " failed\n", | 62 " failed\n", |
| 62 (uintptr_t) tmp_mem); | 63 (uintptr_t) tmp_mem); |
| 63 return LOAD_NO_MEMORY; | 64 return LOAD_NO_MEMORY; |
| 64 } | 65 } |
| 65 NaClLog(4, "NaClAllocateSpace: %"NACL_PRIxPTR", %"NACL_PRIxS"\n", | 66 NaClLog(4, "NaClAllocateSpace: %"NACL_PRIxPTR", %"NACL_PRIxS"\n", |
| 66 (uintptr_t) *mem, | 67 (uintptr_t) *mem, |
| 67 addrsp_size); | 68 addrsp_size); |
| 68 | 69 |
| 69 return LOAD_OK; | 70 return LOAD_OK; |
| 70 } | 71 } |
| 71 | 72 |
| OLD | NEW |