forked from textmate/interactive-input
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protect against recursive invocations of our system function overrides.
Mac OS 10.6 introduced a change that caused our read variant to be invoked recursively resulting in a crash. This appears to be because malloc() now invokes read() for some reason. To solve this problem we mark a (thread local) flag whenever we invoke our custom override logic. If this flag is set when one of the system functions we override is called we defer straight to the system implementation, thereby avoid recursion. The same flag is used for all overridden system functions, so invocation of one of our overrides prevents any other overrides being used in that thread for the duration of the invocation. We use a library constructor to initialise our thread local storage. Interestingly, our system override functions can be called before our library constructor which causes problems. To work around this, we use a global flag to indicate whether our library constructor has been called. If it has not, we do not invoke any of our overridden system functions and instead defer straight to the system implementation.
- Loading branch information
Showing
1 changed file
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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