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 /* | |
18 * NOTE: the trampoline organization for MIPS is currenly assuming | |
19 * NACL_TRAMPOLINE_SIZE == 32. This is contrary to the bundle size | |
20 * which is 16. | |
21 */ | |
22 | |
23 /* | |
24 * Install a syscall trampoline at target_addr. NB: Thread-safe. | |
25 * The code being patched is from tramp.S | |
26 */ | |
27 void NaClPatchOneTrampoline(struct NaClApp *nap, | |
28 uintptr_t target_addr) { | |
29 struct NaClPatchInfo patch_info; | |
30 uint16_t upper, lower; | |
31 char *tramp_ptr = (char *)&NaCl_trampoline_seg_code; | |
32 void (*funcptr)(void) = NaClSyscallSeg; | |
33 uint32_t func_addr = (uint32_t)funcptr; | |
34 unsigned long tramp_buffer[8]; | |
35 size_t tramp_size = ((uintptr_t) &NaCl_trampoline_seg_end | |
36 - (uintptr_t) &NaCl_trampoline_seg_code); | |
37 | |
38 UNREFERENCED_PARAMETER(nap); | |
39 | |
40 /* | |
41 * We copy trampoline code to buffer so that we can patch it with address | |
42 * of NaClSyscallSeg. | |
43 */ | |
44 | |
45 ASSERT_MSG(tramp_size <= 8 * sizeof(unsigned long), | |
46 "Trampoline size is bigger than tramp_buffer size"); | |
47 | |
48 memcpy(tramp_buffer, tramp_ptr, tramp_size); | |
49 | |
50 /* | |
51 * For MIPS we do not need to patch ds, cs segments. | |
52 */ | |
53 | |
54 NaClPatchInfoCtor(&patch_info); | |
55 | |
56 /* | |
57 * We break address of NaClSyscallSeg into upper and lower 16 bits, so that | |
58 * we can patch first and second instruction of trampoline respectively. | |
59 */ | |
60 | |
61 upper = (uint16_t)(func_addr >>16); | |
Mark Seaborn
2012/09/18 03:24:34
Nit: put spaces around '>>'. Also a space after '
petarj
2012/09/19 17:27:51
Done.
| |
62 lower = (uint16_t)(func_addr & 0xffff); | |
63 | |
64 tramp_buffer[0] = (tramp_buffer[0] & (0xFFFF0000)) | upper; | |
65 tramp_buffer[1] = (tramp_buffer[1] & (0xFFFF0000)) | lower; | |
66 | |
67 patch_info.dst = target_addr; | |
68 patch_info.src = (uintptr_t) tramp_buffer; | |
69 patch_info.nbytes = ((uintptr_t) &NaCl_trampoline_seg_end | |
70 - (uintptr_t) &NaCl_trampoline_seg_code); | |
71 | |
72 NaClApplyPatchToMemory(&patch_info); | |
73 } | |
74 | |
75 void NaClFillMemoryRegionWithHalt(void *start, size_t size) { | |
76 uint32_t *inst = (uint32_t *) start; | |
77 uint32_t i; | |
78 | |
79 CHECK(sizeof *inst == NACL_HALT_LEN); | |
80 CHECK(0 == size % NACL_HALT_LEN); | |
81 /* | |
82 * Check that the region start is 4 bytes aligned. | |
83 */ | |
84 CHECK(0 == (uint32_t)start % NACL_HALT_LEN); | |
85 | |
86 for (i = 0; i < (size / NACL_HALT_LEN); i++) | |
87 inst[i] = NACL_HALT_OPCODE; | |
88 } | |
89 | |
90 | |
91 void NaClFillTrampolineRegion(struct NaClApp *nap) { | |
92 NaClFillMemoryRegionWithHalt((void *)(nap->mem_start + NACL_TRAMPOLINE_START), | |
93 NACL_TRAMPOLINE_SIZE); | |
94 } | |
95 | |
96 void NaClLoadSpringboard(struct NaClApp *nap) { | |
97 UNREFERENCED_PARAMETER(nap); | |
98 } | |
99 | |
OLD | NEW |