mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Eliminate cyclic locks in runtime
This change introduces a new deadlock detector for Cosmo's POSIX threads implementation. Error check mutexes will now track a DAG of nested locks and report EDEADLK when a deadlock is theoretically possible. These will occur rarely, but it's important for production hardening your code. You don't even need to change your mutexes to use the POSIX error check mode because `cosmocc -mdbg` will enable error checking on mutexes by default globally. When cycles are found, an error message showing your demangled symbols describing the strongly connected component are printed and then the SIGTRAP is raised, which means you'll also get a backtrace if you're using ShowCrashReports() too. This new error checker is so low-level and so pure that it's able to verify the relationships of every libc runtime lock, including those locks upon which the mutex implementation depends.
This commit is contained in:
parent
26c051c297
commit
af7bd80430
141 changed files with 2094 additions and 1601 deletions
|
@ -15,7 +15,7 @@ struct CosmoFtrace { /* 16 */
|
|||
int64_t ft_lastaddr; /* 8 */
|
||||
};
|
||||
|
||||
/* cosmopolitan thread information block (512 bytes) */
|
||||
/* cosmopolitan thread information block (1024 bytes) */
|
||||
/* NOTE: update aarch64 libc/errno.h if sizeof changes */
|
||||
/* NOTE: update aarch64 libc/proc/vfork.S if sizeof changes */
|
||||
/* NOTE: update aarch64 libc/nexgen32e/gc.S if sizeof changes */
|
||||
|
@ -40,6 +40,7 @@ struct CosmoTib {
|
|||
void *tib_nsync;
|
||||
void *tib_atexit;
|
||||
_Atomic(void *) tib_keys[46];
|
||||
void *tib_locks[64];
|
||||
} __attribute__((__aligned__(64)));
|
||||
|
||||
extern char __tls_morphed;
|
||||
|
@ -78,6 +79,10 @@ forceinline pureconst struct CosmoTib *__get_tls(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
struct CosmoTib *__get_tls_privileged(void) dontthrow pureconst;
|
||||
struct CosmoTib *__get_tls_win32(void) dontthrow;
|
||||
void __set_tls_win32(void *) libcesque;
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define __adj_tls(tib) (tib)
|
||||
#elif defined(__aarch64__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue