This is an archive of the discontinued LLVM Phabricator instance.

[safestack] Fix/port SafeStack on OS X
Needs ReviewPublic

Authored by kubamracek on Dec 3 2015, 8:27 AM.

Details

Summary

There are currently several issues/crashers with SafeStack on OS X:

  1. It doesn't properly create unsafe stacks for newly created threads via pthread_create. This should be solved by changing the runtime into a dynamic library -- see http://reviews.llvm.org/D15192.
  2. It doesn't create unsafe stacks for GCD worker threads, which are not created via pthread_create.
  3. Cleanup of unsafe stacks doesn't work, because the TLV holding the stack's address is already destroyed when the cleanup routine is called.

This patch implements fixes for these and adds a test for GCD. Removing the "XFAIL: darwin" in the pthread test (which fails due to #1). Chaning pthread-cleanup.c test to make sure we crash where we want and not somewhere else (to verify #3).

The implementation needs a workarounds for the cleanup of unsafe stack. In unsafe_stack_free, TLVs are already destroyed. We need to store the information about the unsafe stack elsewhere. This patch simply malloc's a small data structure that holds there values, and stores a pointer to it in a pthread_setspecific storage.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 41760.Dec 3 2015, 8:27 AM
kubamracek retitled this revision from to [safestack] Fix/port SafeStack on OS X.
kubamracek updated this object.
kubamracek added reviewers: eugenis, kcc, pcc, samsonov, glider.
kubamracek added subscribers: llvm-commits, zaks.anna.
pcc edited edge metadata.Dec 3 2015, 11:14 AM

A high level comment: please move Darwin-specific code to a separate file.