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 "native_client/src/untrusted/crash_dump/untrusted_crash_dump.h" | 7 #include "native_client/src/untrusted/crash_dump/untrusted_crash_dump.h" |
8 | 8 |
9 #include <assert.h> | 9 #include <assert.h> |
10 #include <inttypes.h> | 10 #include <inttypes.h> |
11 #include <pthread.h> | 11 #include <pthread.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include <sys/mman.h> | 15 #include <sys/mman.h> |
16 | 16 |
17 #ifdef __GLIBC__ | 17 #ifdef __GLIBC__ |
18 #include <elf.h> | 18 #include <elf.h> |
19 #include <link.h> | 19 #include <link.h> |
20 #endif /* __GLIBC__ */ | 20 #endif /* __GLIBC__ */ |
21 | 21 |
22 #include "native_client/src/include/portability.h" | 22 #include "native_client/src/include/portability.h" |
23 #include "native_client/src/include/nacl/nacl_exception.h" | 23 #include "native_client/src/include/nacl/nacl_exception.h" |
24 #include "native_client/src/untrusted/irt/irt.h" | |
25 | 24 |
26 | 25 |
27 #define CRASH_PAGE_CHUNK (64 * 1024) | 26 #define CRASH_PAGE_CHUNK (64 * 1024) |
28 #define CRASH_STACK_SIZE (CRASH_PAGE_CHUNK * 4) | 27 #define CRASH_STACK_SIZE (CRASH_PAGE_CHUNK * 4) |
29 #define CRASH_STACK_GUARD_SIZE CRASH_PAGE_CHUNK | 28 #define CRASH_STACK_GUARD_SIZE CRASH_PAGE_CHUNK |
30 #define CRASH_STACK_COMPLETE_SIZE (CRASH_STACK_GUARD_SIZE + CRASH_STACK_SIZE) | 29 #define CRASH_STACK_COMPLETE_SIZE (CRASH_STACK_GUARD_SIZE + CRASH_STACK_SIZE) |
31 | 30 |
32 | 31 |
33 static pthread_key_t g_CrashStackKey; | 32 static pthread_key_t g_CrashStackKey; |
34 static struct nacl_irt_exception_handling g_ExceptionHandling; | |
35 static int g_ExceptionHandlingEnabled = 0; | 33 static int g_ExceptionHandlingEnabled = 0; |
36 | 34 |
37 | 35 |
38 #ifdef __GLIBC__ | 36 #ifdef __GLIBC__ |
39 | 37 |
40 struct ProgramTableData { | 38 struct ProgramTableData { |
41 FILE *core; | 39 FILE *core; |
42 int first; | 40 int first; |
43 }; | 41 }; |
44 | 42 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 231 } |
234 | 232 |
235 void NaClCrashDumpThreadDestructor(void *arg) { | 233 void NaClCrashDumpThreadDestructor(void *arg) { |
236 munmap(arg, CRASH_STACK_COMPLETE_SIZE); | 234 munmap(arg, CRASH_STACK_COMPLETE_SIZE); |
237 } | 235 } |
238 | 236 |
239 int NaClCrashDumpInit(void) { | 237 int NaClCrashDumpInit(void) { |
240 int result; | 238 int result; |
241 | 239 |
242 assert(g_ExceptionHandlingEnabled == 0); | 240 assert(g_ExceptionHandlingEnabled == 0); |
243 if (nacl_interface_query(NACL_IRT_EXCEPTION_HANDLING_v0_1, | |
244 &g_ExceptionHandling, | |
245 sizeof(g_ExceptionHandling)) == 0) { | |
246 return 0; | |
247 } | |
248 result = pthread_key_create(&g_CrashStackKey, NaClCrashDumpThreadDestructor); | 241 result = pthread_key_create(&g_CrashStackKey, NaClCrashDumpThreadDestructor); |
249 assert(result == 0); | 242 assert(result == 0); |
250 if (g_ExceptionHandling.exception_handler(CrashHandler, NULL) != 0) { | 243 if (nacl_exception_set_handler(CrashHandler) != 0) { |
251 return 0; | 244 return 0; |
252 } | 245 } |
253 g_ExceptionHandlingEnabled = 1; | 246 g_ExceptionHandlingEnabled = 1; |
254 if (!NaClCrashDumpInitThread()) { | 247 if (!NaClCrashDumpInitThread()) { |
255 g_ExceptionHandlingEnabled = 0; | 248 g_ExceptionHandlingEnabled = 0; |
256 return 0; | 249 return 0; |
257 } | 250 } |
258 return 1; | 251 return 1; |
259 } | 252 } |
260 | 253 |
(...skipping 10 matching lines...) Expand all Loading... |
271 * for stack overflow. | 264 * for stack overflow. |
272 */ | 265 */ |
273 stack = mmap(NULL, CRASH_STACK_COMPLETE_SIZE, | 266 stack = mmap(NULL, CRASH_STACK_COMPLETE_SIZE, |
274 PROT_READ | PROT_WRITE, | 267 PROT_READ | PROT_WRITE, |
275 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 268 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
276 assert(stack != MAP_FAILED); | 269 assert(stack != MAP_FAILED); |
277 guard = mmap(stack, CRASH_STACK_GUARD_SIZE, | 270 guard = mmap(stack, CRASH_STACK_GUARD_SIZE, |
278 PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 271 PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
279 assert(guard == stack); | 272 assert(guard == stack); |
280 pthread_setspecific(g_CrashStackKey, stack); | 273 pthread_setspecific(g_CrashStackKey, stack); |
281 result = g_ExceptionHandling.exception_stack( | 274 result = nacl_exception_set_stack(stack, CRASH_STACK_COMPLETE_SIZE); |
282 stack, CRASH_STACK_COMPLETE_SIZE); | |
283 return result == 0; | 275 return result == 0; |
284 } | 276 } |
OLD | NEW |