[PATCH compiler-rt 0/5] Improved support for swapcontext()


These patches improve ASan support for swapcontext() and friends mainly
focusing on eliminating false positives caused by throwing and catching
exceptions when on a custom user stack.
This is achieved by adding ability to AsanThread to change current
stack (in an async-safe way).

Some of the things that are still not fully supported:
- swapcontext() and fake stacks
- changing context from signal handlers
- changing context using longjmp()
- final context change via ucontext_t::uc_link

On x64 Linux 'make check-all' passes.

This series is also available at:

  https://github.com/pdziepak/compiler-rt.git asan-swapcontext-v1

Paweł Dziepak (5):
  asan: make getcontext() and swapcontext() write stack description
  asan: introduce AsanThread::StackDescriptor
  lsan: do not expect leaks in coroutines to be not reported
  asan: better support for swapcontext() and setcontext()
  asan: extend swapcontext_test

lib/asan/asan_interceptors.cc | 42 +++++++++++++++++++++
lib/asan/asan_internal.h | 1 +
lib/asan/asan_linux.cc | 10 +++++
lib/asan/asan_mac.cc | 4 ++
lib/asan/asan_thread.cc | 21 +++++++----
lib/asan/asan_thread.h | 54 ++++++++++++++++++++++-----
lib/asan/asan_win.cc | 4 ++
test/asan/TestCases/Linux/swapcontext_test.cc | 15 ++++++++
test/lsan/TestCases/swapcontext.cc | 4 --
9 files changed, 134 insertions(+), 21 deletions(-)

Normally, ucontext_t::uc_stack is only used by makecontext() and not
written to or read from any other *context() functions. However, if
making sure that it contains proper stack description can make improving
support for swapcontext() much easier.

StackDescriptor contains all stack information (bottom, top and size),
which will make code implementing better support for swapcontext()

With improved support for swapcontext() and friends lsan may be able
to report some of the leaks that happened in coroutines.

This patch makes swapcontext() and setcontext() update stack information
in AsanThread each time the stack is changed. It is still far from full
support of these functions but at least makes __asan_handle_no_return()
work correctly on a custom user stack.

This patch extends swapcontext_test to verify that the shadow memory
of the stack is properly cleared after throw.


thanks for the patches, but please use http://llvm.org/docs/Phabricator.html