Stack* stack = find_stack_by_addr(SP);
NSegment const *stackseg = VG_(am_find_nsegment) (SP);
- if (stack) {
+ if (LIKELY(stack)) {
*start = stack->start;
*end = stack->end;
}
stack for SP, and set *start and *end to 0.
Otherwise, possibly reduce the stack limits using the boundaries of
the RW segment/SkResvn segments containing SP. */
- if (stackseg == NULL) {
+ if (UNLIKELY(stackseg == NULL)) {
VG_(debugLog)(2, "stacks",
"no addressable segment for SP %p\n",
(void*)SP);
return;
}
- if ((!stackseg->hasR || !stackseg->hasW)
- && (stackseg->kind != SkResvn || stackseg->smode != SmUpper)) {
+ if (UNLIKELY((!stackseg->hasR || !stackseg->hasW)
+ && (stackseg->kind != SkResvn || stackseg->smode != SmUpper))) {
VG_(debugLog)(2, "stacks",
"segment for SP %p is not RW or not a SmUpper Resvn\n",
(void*)SP);
return;
}
- // SP is in a RW segment, or in the SkResvn of an extensible stack.
- if (*start < stackseg->start) {
+ /* SP is in a RW segment, or in the SkResvn of an extensible stack.
+ We can use the seg start as the stack start limit. */
+ if (UNLIKELY(*start < stackseg->start)) {
VG_(debugLog)(2, "stacks",
"segment for SP %p changed stack start limit"
" from %p to %p\n",
*start = stackseg->start;
}
- if (stackseg->kind == SkResvn) {
+ /* Now, determine the stack end limit. If the stackseg is SkResvn,
+ we need to get the neighbour segment (towards higher addresses).
+ This segment must be anonymous and RW. */
+ if (UNLIKELY(stackseg->kind == SkResvn)) {
stackseg = VG_(am_next_nsegment)(stackseg, /*forward*/ True);
if (!stackseg || !stackseg->hasR || !stackseg->hasW
|| stackseg->kind != SkAnonC) {
}
}
- if (*end > stackseg->end) {
+ /* Limit the stack end limit, using the found segment. */
+ if (UNLIKELY(*end > stackseg->end)) {
VG_(debugLog)(2, "stacks",
"segment for SP %p changed stack end limit"
" from %p to %p\n",
/* If reducing start and/or end to the SP segment gives an
empty range, return 'empty' limits */
- if (*start > *end) {
+ if (UNLIKELY(*start > *end)) {
VG_(debugLog)(2, "stacks",
"stack for SP %p start %p after end %p\n",
(void*)SP, (void*)*start, (void*)end);