| 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 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 if (natp->exception_stack == 0) { | 217 if (natp->exception_stack == 0) { |
| 218 new_stack_ptr = regs->stack_ptr - NACL_STACK_RED_ZONE; | 218 new_stack_ptr = regs->stack_ptr - NACL_STACK_RED_ZONE; |
| 219 } else { | 219 } else { |
| 220 new_stack_ptr = natp->exception_stack; | 220 new_stack_ptr = natp->exception_stack; |
| 221 } | 221 } |
| 222 /* Allocate space for the stack frame, and ensure its alignment. */ | 222 /* Allocate space for the stack frame, and ensure its alignment. */ |
| 223 new_stack_ptr -= | 223 new_stack_ptr -= |
| 224 sizeof(struct NaClExceptionFrame) - NACL_STACK_PAD_BELOW_ALIGN; | 224 sizeof(struct NaClExceptionFrame) - NACL_STACK_PAD_BELOW_ALIGN; |
| 225 new_stack_ptr = new_stack_ptr & ~NACL_STACK_ALIGN_MASK; | 225 new_stack_ptr = new_stack_ptr & ~NACL_STACK_ALIGN_MASK; |
| 226 new_stack_ptr -= NACL_STACK_ARG_SIZE; |
| 226 new_stack_ptr -= NACL_STACK_PAD_BELOW_ALIGN; | 227 new_stack_ptr -= NACL_STACK_PAD_BELOW_ALIGN; |
| 227 frame_addr = NaClUserToSysAddrRange(nap, new_stack_ptr, | 228 frame_addr = NaClUserToSysAddrRange(nap, new_stack_ptr, |
| 228 sizeof(struct NaClExceptionFrame)); | 229 sizeof(struct NaClExceptionFrame)); |
| 229 if (frame_addr == kNaClBadAddress) { | 230 if (frame_addr == kNaClBadAddress) { |
| 230 /* We cannot write the stack frame. */ | 231 /* We cannot write the stack frame. */ |
| 231 return 0; | 232 return 0; |
| 232 } | 233 } |
| 233 context_user_addr = new_stack_ptr + offsetof(struct NaClExceptionFrame, | 234 context_user_addr = new_stack_ptr + offsetof(struct NaClExceptionFrame, |
| 234 context); | 235 context); |
| 235 | 236 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 265 regs->lr = kReturnAddr; | 266 regs->lr = kReturnAddr; |
| 266 regs->r0 = context_user_addr; /* Argument 1 */ | 267 regs->r0 = context_user_addr; /* Argument 1 */ |
| 267 regs->prog_ctr = NaClUserToSys(nap, nap->exception_handler); | 268 regs->prog_ctr = NaClUserToSys(nap, nap->exception_handler); |
| 268 regs->stack_ptr = NaClUserToSys(nap, new_stack_ptr); | 269 regs->stack_ptr = NaClUserToSys(nap, new_stack_ptr); |
| 269 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips | 270 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips |
| 270 frame->context.frame_ptr = regs->frame_ptr; | 271 frame->context.frame_ptr = regs->frame_ptr; |
| 271 regs->return_addr = kReturnAddr; | 272 regs->return_addr = kReturnAddr; |
| 272 regs->a0 = context_user_addr; | 273 regs->a0 = context_user_addr; |
| 273 regs->prog_ctr = NaClUserToSys(nap, nap->exception_handler); | 274 regs->prog_ctr = NaClUserToSys(nap, nap->exception_handler); |
| 274 regs->stack_ptr = NaClUserToSys(nap, new_stack_ptr); | 275 regs->stack_ptr = NaClUserToSys(nap, new_stack_ptr); |
| 276 /* |
| 277 * Per Linux/MIPS convention, PIC functions assume that t9 holds |
| 278 * the function's address on entry. |
| 279 */ |
| 280 regs->t9 = regs->prog_ctr; |
| 275 #else | 281 #else |
| 276 # error Unsupported architecture | 282 # error Unsupported architecture |
| 277 #endif | 283 #endif |
| 278 | 284 |
| 279 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 | 285 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 |
| 280 frame->return_addr = kReturnAddr; | 286 frame->return_addr = kReturnAddr; |
| 281 regs->flags &= ~NACL_X86_DIRECTION_FLAG; | 287 regs->flags &= ~NACL_X86_DIRECTION_FLAG; |
| 282 #endif | 288 #endif |
| 283 | 289 |
| 284 return 1; | 290 return 1; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 unsigned int a; | 466 unsigned int a; |
| 461 | 467 |
| 462 /* Remove all handlers */ | 468 /* Remove all handlers */ |
| 463 for (a = 0; a < NACL_ARRAY_SIZE(s_Signals); a++) { | 469 for (a = 0; a < NACL_ARRAY_SIZE(s_Signals); a++) { |
| 464 if (sigaction(s_Signals[a], &s_OldActions[a], NULL) != 0) { | 470 if (sigaction(s_Signals[a], &s_OldActions[a], NULL) != 0) { |
| 465 NaClLog(LOG_FATAL, "Failed to unregister handler for %d.\n\tERR:%s\n", | 471 NaClLog(LOG_FATAL, "Failed to unregister handler for %d.\n\tERR:%s\n", |
| 466 s_Signals[a], strerror(errno)); | 472 s_Signals[a], strerror(errno)); |
| 467 } | 473 } |
| 468 } | 474 } |
| 469 } | 475 } |
| OLD | NEW |