Skip to content

Commit

Permalink
Create copy of context record before passing it to StackWalk64
Browse files Browse the repository at this point in the history
StackWalk64 may modify EXCEPTION_POINTERS struct that is passed
to it from constructor of StackTrace.
In the case of StackDumpExceptionFilter the struct that is passed
to constructor of StackTrace may be later passed to other (chained)
exception filter(s), so it shouldn't be modified.

BUG=

Review URL: https://codereview.chromium.org/267463003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269296 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
marcing@opera.com committed May 9, 2014
1 parent da48055 commit fe7a12a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion base/debug/stack_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BASE_EXPORT StackTrace {
// Creates a stacktrace for an exception.
// Note: this function will throw an import not found (StackWalk64) exception
// on system without dbghelp 5.1.
StackTrace(_EXCEPTION_POINTERS* exception_pointers);
StackTrace(const _EXCEPTION_POINTERS* exception_pointers);
#endif

// Copying and assignment are allowed with the default functions.
Expand Down
19 changes: 11 additions & 8 deletions base/debug/stack_trace_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,25 @@ StackTrace::StackTrace() {
#pragma optimize("", on)
#endif

StackTrace::StackTrace(EXCEPTION_POINTERS* exception_pointers) {
StackTrace::StackTrace(const EXCEPTION_POINTERS* exception_pointers) {
// When walking an exception stack, we need to use StackWalk64().
count_ = 0;
// StackWalk64() may modify context record passed to it, so we will
// use a copy.
CONTEXT context_record = *exception_pointers->ContextRecord;
// Initialize stack walking.
STACKFRAME64 stack_frame;
memset(&stack_frame, 0, sizeof(stack_frame));
#if defined(_WIN64)
int machine_type = IMAGE_FILE_MACHINE_AMD64;
stack_frame.AddrPC.Offset = exception_pointers->ContextRecord->Rip;
stack_frame.AddrFrame.Offset = exception_pointers->ContextRecord->Rbp;
stack_frame.AddrStack.Offset = exception_pointers->ContextRecord->Rsp;
stack_frame.AddrPC.Offset = context_record.Rip;
stack_frame.AddrFrame.Offset = context_record.Rbp;
stack_frame.AddrStack.Offset = context_record.Rsp;
#else
int machine_type = IMAGE_FILE_MACHINE_I386;
stack_frame.AddrPC.Offset = exception_pointers->ContextRecord->Eip;
stack_frame.AddrFrame.Offset = exception_pointers->ContextRecord->Ebp;
stack_frame.AddrStack.Offset = exception_pointers->ContextRecord->Esp;
stack_frame.AddrPC.Offset = context_record.Eip;
stack_frame.AddrFrame.Offset = context_record.Ebp;
stack_frame.AddrStack.Offset = context_record.Esp;
#endif
stack_frame.AddrPC.Mode = AddrModeFlat;
stack_frame.AddrFrame.Mode = AddrModeFlat;
Expand All @@ -235,7 +238,7 @@ StackTrace::StackTrace(EXCEPTION_POINTERS* exception_pointers) {
GetCurrentProcess(),
GetCurrentThread(),
&stack_frame,
exception_pointers->ContextRecord,
&context_record,
NULL,
&SymFunctionTableAccess64,
&SymGetModuleBase64,
Expand Down

0 comments on commit fe7a12a

Please sign in to comment.