Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: third_party/tcmalloc/chromium/src/stacktrace_x86-inl.h

Issue 3120017: Keep shadow stacks to help heap checker unwind without frame pointers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/tcmalloc/chromium/src/linux_shadow_stacks.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #endif 58 #endif
59 #ifdef HAVE_UNISTD_H 59 #ifdef HAVE_UNISTD_H
60 #include <unistd.h> 60 #include <unistd.h>
61 #endif 61 #endif
62 #ifdef HAVE_MMAP 62 #ifdef HAVE_MMAP
63 #include <sys/mman.h> // for msync 63 #include <sys/mman.h> // for msync
64 #include "base/vdso_support.h" 64 #include "base/vdso_support.h"
65 #endif 65 #endif
66 66
67 #include "google/stacktrace.h" 67 #include "google/stacktrace.h"
68 #if defined(KEEP_SHADOW_STACKS)
69 #include "linux_shadow_stacks.h"
70 #endif // KEEP_SHADOW_STACKS
68 71
69 #if defined(__linux__) && defined(__i386__) && defined(__ELF__) && defined(HAVE_ MMAP) 72 #if defined(__linux__) && defined(__i386__) && defined(__ELF__) && defined(HAVE_ MMAP)
70 // Count "push %reg" instructions in VDSO __kernel_vsyscall(), 73 // Count "push %reg" instructions in VDSO __kernel_vsyscall(),
71 // preceeding "syscall" or "sysenter". 74 // preceeding "syscall" or "sysenter".
72 // If __kernel_vsyscall uses frame pointer, answer 0. 75 // If __kernel_vsyscall uses frame pointer, answer 0.
73 // 76 //
74 // kMaxBytes tells how many instruction bytes of __kernel_vsyscall 77 // kMaxBytes tells how many instruction bytes of __kernel_vsyscall
75 // to analyze before giving up. Up to kMaxBytes+1 bytes of 78 // to analyze before giving up. Up to kMaxBytes+1 bytes of
76 // instructions could be accessed. 79 // instructions could be accessed.
77 // 80 //
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // static void Noop() { asm(""); } // prevent optimizing-away 312 // static void Noop() { asm(""); } // prevent optimizing-away
310 __asm__ volatile ("mov %%rbp, %0" : "=r" (rbp)); 313 __asm__ volatile ("mov %%rbp, %0" : "=r" (rbp));
311 // Arguments are passed in registers on x86-64, so we can't just 314 // Arguments are passed in registers on x86-64, so we can't just
312 // offset from &result 315 // offset from &result
313 sp = (void **) rbp; 316 sp = (void **) rbp;
314 #else 317 #else
315 # error Using stacktrace_x86-inl.h on a non x86 architecture! 318 # error Using stacktrace_x86-inl.h on a non x86 architecture!
316 #endif 319 #endif
317 320
318 int n = 0; 321 int n = 0;
322 #if defined(KEEP_SHADOW_STACKS)
323 void **shadow_ip_stack;
324 void **shadow_sp_stack;
325 int stack_size;
326 shadow_ip_stack = (void**) get_shadow_ip_stack(&stack_size);
327 shadow_sp_stack = (void**) get_shadow_sp_stack(&stack_size);
328 int shadow_index = stack_size - 1;
329 for (int i = stack_size - 1; i >= 0; i--) {
330 if (sp == shadow_sp_stack[i]) {
331 shadow_index = i;
332 break;
333 }
334 }
335 void **prev_sp = NULL;
336 #endif // KEEP_SHADOW_STACKS
319 while (sp && n < max_depth) { 337 while (sp && n < max_depth) {
320 if (*(sp+1) == reinterpret_cast<void *>(0)) { 338 if (*(sp+1) == reinterpret_cast<void *>(0)) {
321 // In 64-bit code, we often see a frame that 339 // In 64-bit code, we often see a frame that
322 // points to itself and has a return address of 0. 340 // points to itself and has a return address of 0.
323 break; 341 break;
324 } 342 }
325 #if !IS_WITH_CONTEXT 343 #if !IS_WITH_CONTEXT
326 const void *const ucp = NULL; 344 const void *const ucp = NULL;
327 #endif 345 #endif
328 void **next_sp = NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(sp, ucp); 346 void **next_sp = NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(sp, ucp);
329 if (skip_count > 0) { 347 if (skip_count > 0) {
330 skip_count--; 348 skip_count--;
349 #if defined(KEEP_SHADOW_STACKS)
350 shadow_index--;
351 #endif // KEEP_SHADOW_STACKS
331 } else { 352 } else {
332 result[n] = *(sp+1); 353 result[n] = *(sp+1);
354 #if defined(KEEP_SHADOW_STACKS)
355 if ((shadow_index > 0) && (sp == shadow_sp_stack[shadow_index])) {
356 shadow_index--;
357 }
358 #endif // KEEP_SHADOW_STACKS
359
333 #if IS_STACK_FRAMES 360 #if IS_STACK_FRAMES
334 if (next_sp > sp) { 361 if (next_sp > sp) {
335 sizes[n] = (uintptr_t)next_sp - (uintptr_t)sp; 362 sizes[n] = (uintptr_t)next_sp - (uintptr_t)sp;
336 } else { 363 } else {
337 // A frame-size of 0 is used to indicate unknown frame size. 364 // A frame-size of 0 is used to indicate unknown frame size.
338 sizes[n] = 0; 365 sizes[n] = 0;
339 } 366 }
340 #endif 367 #endif
341 n++; 368 n++;
342 } 369 }
370 #if defined(KEEP_SHADOW_STACKS)
371 prev_sp = sp;
372 #endif // KEEP_SHADOW_STACKS
343 sp = next_sp; 373 sp = next_sp;
344 } 374 }
375
376 #if defined(KEEP_SHADOW_STACKS)
377 if (shadow_index >= 0) {
378 for (int i = shadow_index; i >= 0; i--) {
379 if (shadow_sp_stack[i] > prev_sp) {
380 result[n] = shadow_ip_stack[i];
381 if (n + 1 < max_depth) {
382 n++;
383 continue;
384 }
385 }
386 break;
387 }
388 }
389 #endif // KEEP_SHADOW_STACKS
345 return n; 390 return n;
346 } 391 }
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/linux_shadow_stacks.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698