OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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 | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
7 #include <string.h> | |
8 | |
9 #include "native_client/src/include/nacl_assert.h" | |
10 #include "native_client/src/shared/platform/nacl_check.h" | |
11 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | |
12 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | |
13 #include "native_client/src/trusted/service_runtime/arch/mips/sel_ldr_mips.h" | |
14 #include "native_client/src/trusted/service_runtime/arch/mips/tramp_mips.h" | |
15 | |
16 | |
17 /* NOTE: the trampoline organization for MIPS is currenly assuming | |
Mark Seaborn
2012/09/08 02:43:14
Nit: please follow service_runtime's comment style
petarj
2012/09/11 16:58:13
Done.
| |
18 * NACL_TRAMPOLINE_SIZE == 32. This is contrary to the bundle size | |
19 * which is 16. | |
20 */ | |
21 | |
22 /* | |
23 * Install a syscall trampoline at target_addr. NB: Thread-safe. | |
24 * The code being patched is from tramp.S | |
25 */ | |
26 void NaClPatchOneTrampoline(struct NaClApp *nap, | |
27 uintptr_t target_addr) { | |
28 struct NaClPatchInfo patch_info; | |
29 uint16_t upper, lower; | |
30 char *tramp_ptr = (char *)&NaCl_trampoline_seg_code; | |
31 void (*funcptr)(void) = NaClSyscallSeg; | |
32 uint32_t func_addr = (uint32_t)funcptr; | |
33 unsigned long tramp_buffer[8]; | |
34 size_t tramp_size = ((uintptr_t) &NaCl_trampoline_seg_end | |
35 - (uintptr_t) &NaCl_trampoline_seg_code); | |
36 | |
37 UNREFERENCED_PARAMETER(nap); | |
38 | |
39 /* We copy trampoline code to buffer so that we can patch it with address | |
40 * of NaClSyscallSeg. */ | |
41 | |
42 ASSERT_MSG(tramp_size <= 8 * sizeof(unsigned long), | |
43 "Trampoline size is bigger than tramp_buffer size"); | |
44 | |
45 memcpy(tramp_buffer, tramp_ptr, tramp_size); | |
46 | |
47 /* For MIPS we do not need to patch ds, cs segments. */ | |
48 | |
49 NaClPatchInfoCtor(&patch_info); | |
50 | |
51 /* We break address of NaClSyscallSeg into upper and lower 16 bits, so that | |
52 * we can patch first and second instruction of trampoline respectively. */ | |
53 | |
54 upper = (uint16_t)(func_addr >>16); | |
55 lower = (uint16_t)(func_addr & 0xffff); | |
56 | |
57 tramp_buffer[0] = (tramp_buffer[0] & (0xFFFF0000)) | upper; | |
58 tramp_buffer[1] = (tramp_buffer[1] & (0xFFFF0000)) | lower; | |
59 | |
60 patch_info.dst = target_addr; | |
61 patch_info.src = (uintptr_t) tramp_buffer; | |
62 patch_info.nbytes = ((uintptr_t) &NaCl_trampoline_seg_end | |
63 - (uintptr_t) &NaCl_trampoline_seg_code); | |
64 | |
65 NaClApplyPatchToMemory(&patch_info); | |
66 } | |
67 | |
68 void NaClFillMemoryRegionWithHalt(void *start, size_t size) { | |
69 uint32_t *inst = (uint32_t *) start; | |
70 uint32_t i; | |
71 | |
72 CHECK(sizeof *inst == NACL_HALT_LEN); | |
73 CHECK(0 == size % NACL_HALT_LEN); | |
74 /* check that the region start is 4 bytes aligned */ | |
75 CHECK(0 == (uint32_t)start % NACL_HALT_LEN); | |
76 | |
77 for (i = 0; i < (size / NACL_HALT_LEN); i++) | |
78 inst[i] = NACL_HALT_OPCODE; | |
79 } | |
80 | |
81 | |
82 void NaClFillTrampolineRegion(struct NaClApp *nap) { | |
83 NaClFillMemoryRegionWithHalt((void *)(nap->mem_start + NACL_TRAMPOLINE_START), | |
84 NACL_TRAMPOLINE_SIZE); | |
85 } | |
86 | |
87 void NaClLoadSpringboard(struct NaClApp *nap) { | |
88 UNREFERENCED_PARAMETER(nap); | |
89 } | |
90 | |
OLD | NEW |