OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2014 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 be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * This alters instructions for the IRT so that access to the TLS | 8 * This alters instructions for the IRT so that access to the TLS |
9 * point to the IRT's TLS. | 9 * point to the IRT's TLS. |
10 */ | 10 */ |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 /* | 59 /* |
60 * This is 'ldr REG, [r9, #0]'. | 60 * This is 'ldr REG, [r9, #0]'. |
61 * Turn it into 'ldr REG, [r9, #4]'. | 61 * Turn it into 'ldr REG, [r9, #4]'. |
62 */ | 62 */ |
63 *insn |= 4; | 63 *insn |= 4; |
64 ++g_changes; | 64 ++g_changes; |
65 } | 65 } |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
| 69 static void EditMipsCode(void *code, size_t code_length) { |
| 70 Elf32_Word *const words = code; |
| 71 Elf32_Word *const end = (void *) ((uint8_t *) code + code_length); |
| 72 Elf32_Word *insn; |
| 73 |
| 74 for (insn = words; insn < end; ++insn) { |
| 75 if ((*insn & 0xFFE0FFFF) == 0x8f000000) { |
| 76 /* |
| 77 * This is 'lw $REG, 0($t8)'. |
| 78 * Turn it into 'lw $REG, 4($t8)'. |
| 79 */ |
| 80 *insn |= 4; |
| 81 ++g_changes; |
| 82 } |
| 83 } |
| 84 } |
| 85 |
69 static Bool ConsiderOneInsn(const uint8_t *insn_begin, const uint8_t *insn_end, | 86 static Bool ConsiderOneInsn(const uint8_t *insn_begin, const uint8_t *insn_end, |
70 uint32_t validation_info, void *data) { | 87 uint32_t validation_info, void *data) { |
71 UNREFERENCED_PARAMETER(data); | 88 UNREFERENCED_PARAMETER(data); |
72 if (insn_begin[0] == 0x65) { /* GS prefix */ | 89 if (insn_begin[0] == 0x65) { /* GS prefix */ |
73 if (insn_end - insn_begin < 6) { | 90 if (insn_end - insn_begin < 6) { |
74 ReportError(insn_begin, "Unexpected GS prefix"); | 91 ReportError(insn_begin, "Unexpected GS prefix"); |
75 } else if (insn_end[-1] == 0 && insn_end[-2] == 0 && | 92 } else if (insn_end[-1] == 0 && insn_end[-2] == 0 && |
76 insn_end[-3] == 0 && insn_end[-4] == 0) { | 93 insn_end[-3] == 0 && insn_end[-4] == 0) { |
77 /* | 94 /* |
78 * This is 'something %gs:0'. | 95 * This is 'something %gs:0'. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 case EM_386: | 199 case EM_386: |
183 EditX86_32Code(g_code_start, code_length); | 200 EditX86_32Code(g_code_start, code_length); |
184 break; | 201 break; |
185 case EM_X86_64: | 202 case EM_X86_64: |
186 if (g_verbose) { | 203 if (g_verbose) { |
187 printf("%s: x86-64 ELF detected, no instructions changed\n", | 204 printf("%s: x86-64 ELF detected, no instructions changed\n", |
188 infile); | 205 infile); |
189 } | 206 } |
190 return TRUE; | 207 return TRUE; |
191 case EM_MIPS: | 208 case EM_MIPS: |
192 if (g_verbose) { | 209 EditMipsCode(g_code_start, code_length); |
193 printf("%s: MIPS ELF detected, no instructions changed\n", | |
194 infile); | |
195 } | |
196 return TRUE; | 210 return TRUE; |
197 default: | 211 default: |
198 fprintf(stderr, "%s: Unsupported e_machine %d\n", | 212 fprintf(stderr, "%s: Unsupported e_machine %d\n", |
199 infile, e_machine); | 213 infile, e_machine); |
200 return FALSE; | 214 return FALSE; |
201 } | 215 } |
202 | 216 |
203 if (g_verbose) { | 217 if (g_verbose) { |
204 if (g_changes == 0) { | 218 if (g_changes == 0) { |
205 printf("%s: Found no changes to make\n", | 219 printf("%s: Found no changes to make\n", |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 infile); | 402 infile); |
389 return 1; | 403 return 1; |
390 } | 404 } |
391 | 405 |
392 if (g_errors != 0) | 406 if (g_errors != 0) |
393 return 1; | 407 return 1; |
394 | 408 |
395 WriteOutput(outfile); | 409 WriteOutput(outfile); |
396 return 0; | 410 return 0; |
397 } | 411 } |
OLD | NEW |