-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[sanitizer_common] Implement address sanitizer on AIX: stack unwinding #138188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jakeegan
wants to merge
3
commits into
llvm:main
Choose a base branch
from
jakeegan:asan_common6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//===-- sanitizer_unwind_aix.cpp ------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains the unwind.h-based (aka "slow") stack unwinding routines | ||
// available to the tools on AIX. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "sanitizer_platform.h" | ||
|
||
#if SANITIZER_AIX | ||
# include <unwind.h> | ||
|
||
# include "sanitizer_common.h" | ||
# include "sanitizer_stacktrace.h" | ||
|
||
namespace __sanitizer { | ||
|
||
struct UnwindTraceArg { | ||
BufferedStackTrace *stack; | ||
u32 max_depth; | ||
}; | ||
|
||
static _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, | ||
void *param) { | ||
UnwindTraceArg *arg = (UnwindTraceArg *)param; | ||
CHECK_LT(arg->stack->size, arg->max_depth); | ||
uptr pc = _Unwind_GetIP(ctx); | ||
// On AIX 32-bit and 64-bit, addresses up through 0x0fffffff are for kernel. | ||
if (pc <= 0x0fffffff) | ||
return _URC_NORMAL_STOP; | ||
arg->stack->trace_buffer[arg->stack->size++] = pc; | ||
if (arg->stack->size == arg->max_depth) | ||
return _URC_NORMAL_STOP; | ||
return _URC_NO_REASON; | ||
} | ||
|
||
void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) { | ||
CHECK_GE(max_depth, 2); | ||
size = 0; | ||
UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)}; | ||
_Unwind_Backtrace(Unwind_Trace, &arg); | ||
// We need to pop a few frames so that pc is on top. | ||
uptr to_pop = LocatePcInTrace(pc); | ||
// trace_buffer[0] belongs to the current function so we always pop it, | ||
// unless there is only 1 frame in the stack trace (1 frame is always better | ||
// than 0!). | ||
// 1-frame stacks don't normally happen, but this depends on the actual | ||
// unwinder implementation (libgcc, libunwind, etc) which is outside of our | ||
// control. | ||
if (to_pop == 0 && size > 1) | ||
to_pop = 1; | ||
|
||
PopStackFrames(to_pop); | ||
trace_buffer[0] = pc; | ||
} | ||
|
||
void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) { | ||
CHECK(context); | ||
UnwindSlow(pc, max_depth); | ||
} | ||
} // namespace __sanitizer | ||
|
||
#endif // SANITIZER_AIX |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.