chenBright opened a new pull request, #3298:
URL: https://github.com/apache/brpc/pull/3298

   ### What problem does this PR solve?
   
   Issue Number: resolve 
   
   Problem Summary:
   
   Under ASan, every `bthread_exit` from a non-main task (i.e. the
   `throw bthread::ExitException(retval)` branch) reliably emits the
   following warning to stderr, polluting test output and confusing future
   ASan reports:
   
   ```
   ==42417==WARNING: ASan is ignoring requested __asan_handle_no_return: stack 
type: default top: 0x7feebb8cc000; bottom 0x7feebc8c9000; size: 
0xffffffffff003000 (-16764928)
   False positive error reports may follow
   For details see https://github.com/google/sanitizers/issues/189
   ```
   
   (`top - bottom ≈ 1.5 GiB` is impossible for any real stack: brpc's
   biggest bthread stack is `STACK_TYPE_LARGE`, an order-of-magnitude
   smaller, and a default pthread stack is only a few MB.)
   
   Root cause: brpc's `StackStorage::bottom` is, by convention, the
   **highest** address of the stack (see `bthread/stack.h` comment "Assume
   stack grows upwards"; stack.cpp confirms with
   `s->bottom = (char*)mem + stacksize`). However, in the ASan-only branch
   of `TaskGroup::init`, the value passed to `stk->storage.bottom` for the
   main task came straight from `PthreadAttrGetStack`, which on Linux uses
   `pthread_attr_getstack(3)` — and that returns the **lowest** address of
   the region. The convention was therefore violated for the main task.
   
   `internal::StartSwitchFiber` computes
   `asan_stack_bottom = (char*)storage.bottom - storage.stacksize` and
   passes it to `__sanitizer_start_switch_fiber`. With the convention
   violated, this address was `stacksize` bytes **below** the real pthread
   stack, so the per-jump `BTHREAD_SCOPED_ASAN_FIBER_SWITCHER` told ASan
   that the main task lives in nonsensical memory. From that point on,
   ASan's per-thread fake-stack tracking was inconsistent with reality.
   The first time the C++ unwinder fired (e.g. from
   `throw bthread::ExitException`), `__asan_handle_no_return` saw a stack
   range that straddles the bthread stack and the bogus "main" stack and
   bailed out with the warning above.
   
   ### What is changed and the side effects?
   
   Changed:
   
   `PthreadAttrGetStack` now translates
     the lowest address returned by `pthread_attr_getstack(3)` into a
     highest address before returning, so callers can keep treating the
     output as a `StackStorage::bottom`. macOS already returns the stack
     base (highest address) via `pthread_get_stackaddr_np(3)` and is
     unchanged. A comment is added describing the convention.
   
   Side effects:
   - Performance effects:
   
   - Breaking backward compatibility: 
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to