Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 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 be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #ifndef NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ | 7 #ifndef NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ |
| 8 #define NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ | 8 #define NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ |
| 9 | 9 |
| 10 #include "native_client/src/include/nacl/nacl_exception.h" | 10 #include "native_client/src/include/nacl/nacl_exception.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 233 |
| 234 # define REGS_SAVER_FUNC_NOPROTO(def_func, callee_func) \ | 234 # define REGS_SAVER_FUNC_NOPROTO(def_func, callee_func) \ |
| 235 void callee_func(struct NaClSignalContext *regs); \ | 235 void callee_func(struct NaClSignalContext *regs); \ |
| 236 __asm__( \ | 236 __asm__( \ |
| 237 ".pushsection .text, \"ax\", @progbits\n" \ | 237 ".pushsection .text, \"ax\", @progbits\n" \ |
| 238 ".p2align 5\n" \ | 238 ".p2align 5\n" \ |
| 239 ".global " #def_func "\n"\ | 239 ".global " #def_func "\n"\ |
| 240 #def_func ":\n" \ | 240 #def_func ":\n" \ |
| 241 /* Push most of "struct NaClSignalContext" in reverse order. */ \ | 241 /* Push most of "struct NaClSignalContext" in reverse order. */ \ |
| 242 "push $0\n" /* Leave space for flags */ \ | 242 "push $0\n" /* Leave space for flags */ \ |
| 243 "push $" #def_func "\n" /* Fill out prog_ctr with known value */ \ | 243 "push $0 \n" /* Leave space for prog_ctr */ \ |
| 244 "push %edi\n" \ | 244 "push %edi\n" \ |
| 245 "push %esi\n" \ | 245 "push %esi\n" \ |
| 246 "push %ebp\n" \ | 246 "push %ebp\n" \ |
| 247 "push %esp\n" \ | 247 "push %esp\n" \ |
| 248 "push %ebx\n" \ | 248 "push %ebx\n" \ |
| 249 "push %edx\n" \ | 249 "push %edx\n" \ |
| 250 "push %ecx\n" \ | 250 "push %ecx\n" \ |
| 251 "push %eax\n" \ | 251 "push %eax\n" \ |
| 252 /* Save flags. */ \ | 252 /* Save flags. */ \ |
| 253 SAVE_X86_FLAGS_INTO_REG("%eax") \ | 253 SAVE_X86_FLAGS_INTO_REG("%eax") \ |
| 254 "movl %eax, 0x24(%esp)\n" \ | 254 "movl %eax, 0x24(%esp)\n" \ |
| 255 /* Obtain def_func from GOT to fill progg_ctr with known value. */ \ | |
|
Mark Seaborn
2014/09/15 17:15:21
Typo: "prog_ctr"
Junichi Uekawa
2014/09/16 01:37:53
Done.
| |
| 256 "call 0f\n" \ | |
| 257 "0: popl %eax\n" \ | |
| 258 "1: addl $_GLOBAL_OFFSET_TABLE_ + (1b - 0b), %eax\n" \ | |
| 259 "movl " #def_func "@GOT(%eax), %eax\n" \ | |
| 260 "movl %eax, 0x20(%esp)\n" \ | |
| 255 /* Adjust saved %esp value to account for preceding pushes. */ \ | 261 /* Adjust saved %esp value to account for preceding pushes. */ \ |
| 256 "addl $5 * 4, 0x10(%esp)\n" \ | 262 "addl $5 * 4, 0x10(%esp)\n" \ |
| 257 /* Save argument to callee_func() temporarily. */ \ | 263 /* Save argument to callee_func() temporarily. */ \ |
| 258 "mov %esp, %eax\n" \ | 264 "mov %esp, %eax\n" \ |
| 259 /* Align the stack pointer and leave space for an argument. */ \ | 265 /* Align the stack pointer and leave space for an argument. */ \ |
| 260 "pushl $0\n" \ | 266 "pushl $0\n" \ |
| 261 "and $~15, %esp\n" \ | 267 "and $~15, %esp\n" \ |
| 262 /* Set argument to callee_func(). */ \ | 268 /* Set argument to callee_func(). */ \ |
| 263 "mov %eax, (%esp)\n" \ | 269 "mov %eax, (%esp)\n" \ |
| 264 "call " #callee_func "\n" \ | 270 "call " #callee_func "\n" \ |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 "push {r14}\n" \ | 334 "push {r14}\n" \ |
| 329 /* Save r0-r12 and sp; adjust sp for the pushes above */ \ | 335 /* Save r0-r12 and sp; adjust sp for the pushes above */ \ |
| 330 "add r14, sp, #0xc\n" \ | 336 "add r14, sp, #0xc\n" \ |
| 331 "push {r10-r12, r14}\n" \ | 337 "push {r10-r12, r14}\n" \ |
| 332 /* Push a dummy value for r9, which the tests need not compare */ \ | 338 /* Push a dummy value for r9, which the tests need not compare */ \ |
| 333 "mov r10, #0\n" \ | 339 "mov r10, #0\n" \ |
| 334 "push {r10}\n" \ | 340 "push {r10}\n" \ |
| 335 /* Save the rest of struct NaClSignalContext */ \ | 341 /* Save the rest of struct NaClSignalContext */ \ |
| 336 "push {r0-r8}\n" \ | 342 "push {r0-r8}\n" \ |
| 337 /* Now save a correct prog_ctr value */ \ | 343 /* Now save a correct prog_ctr value */ \ |
| 338 "adr r0, " #def_func "\n" \ | 344 "ldr r2, 11f\n" \ |
|
Mark Seaborn
2014/09/15 17:15:21
Note that "adr" is already position independent.
Junichi Uekawa
2014/09/16 01:37:53
I see, I missed the point that it was already posi
| |
| 339 "str r0, [sp, #0x3c]\n" \ | 345 "1:\n" \ |
| 346 "add r2, pc, r2\n" /* obtain GLOBAL_OFFSET_TABLE */ \ | |
| 347 "ldr r3, 12f\n" \ | |
| 348 "add r2, r2, r3\n" \ | |
| 349 "bic r2, r2, #0xc0000000\n" /* SFI constraint */ \ | |
| 350 "ldr r3, [r2]\n" /* obtain def_func */ \ | |
| 351 "str r3, [sp, #0x3c]\n" \ | |
| 352 "b 2f\n" /* leave some space for PC-relative data. */ \ | |
| 353 "11:\n" \ | |
| 354 ".long _GLOBAL_OFFSET_TABLE_-(1b + 8)\n" \ | |
| 355 "12:\n" \ | |
| 356 ".long " #def_func "(GOT)\n" \ | |
| 357 "2:\n" \ | |
| 340 /* Save CPSR (flags) register, a.k.a. APSR for user mode */ \ | 358 /* Save CPSR (flags) register, a.k.a. APSR for user mode */ \ |
| 341 "mrs r0, apsr\n" \ | 359 "mrs r0, apsr\n" \ |
| 342 "str r0, [sp, #0x40]\n" \ | 360 "str r0, [sp, #0x40]\n" \ |
| 343 /* Set argument to callee_func() */ \ | 361 /* Set argument to callee_func() */ \ |
| 344 "mov r0, sp\n" \ | 362 "mov r0, sp\n" \ |
| 345 /* Align the stack pointer */ \ | 363 /* Align the stack pointer */ \ |
| 346 "bic sp, sp, #0xc000000f\n" \ | 364 "bic sp, sp, #0xc000000f\n" \ |
| 347 "b " #callee_func "\n" \ | 365 "b " #callee_func "\n" \ |
| 348 ".popsection\n") | 366 ".popsection\n") |
| 349 | 367 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 void RegsUnsetNonCalleeSavedRegisters(struct NaClSignalContext *regs); | 459 void RegsUnsetNonCalleeSavedRegisters(struct NaClSignalContext *regs); |
| 442 | 460 |
| 443 /* | 461 /* |
| 444 * For a function called with register state |regs|, extract the first | 462 * For a function called with register state |regs|, extract the first |
| 445 * argument. This is useful for a function entry point defined by | 463 * argument. This is useful for a function entry point defined by |
| 446 * REGS_SAVER_FUNC. | 464 * REGS_SAVER_FUNC. |
| 447 */ | 465 */ |
| 448 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs); | 466 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs); |
| 449 | 467 |
| 450 #endif | 468 #endif |
| OLD | NEW |