DynamoRIO / DynamoRIO/dynamorio
many SIGSEGV for safe_read_tls_magic on every thread on attach
- Dominant language
- C
- Stars
- 3.2k
- Forks
- 629
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 31
Description
The safe-read-tls solution from #2089 and #1986 solved a lot of thorny problems, but left us with 2 remaining: problems handling signals on detach (#2270) and the pain of debugging (and perhaps performance issues?) with multiple faults in every new thread when we attach. This issue covers trying to reduce the # of faults per new thread on attach.
You can see these running:
```
# gdb suite/tests/bin/api.static_signal
```
```
Program received signal SIGSEGV, Segmentation fault.
safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
warning: Source file is more recent than executable.
2382 DECLARE_FUNC(_dynamorio_runtime_resolve)
(gdb) bt
#0 safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
#1 0x00000000006b70ac in is_thread_tls_initialized () at dr/git/src/core/unix/os.c:1446
#2 0x00000000006b9656 in get_thread_private_dcontext () at dr/git/src/core/unix/os.c:2609
#3 0x00000000006d8cd1 in master_signal_handler_C (sig=12, siginfo=0x7f2c840044b0, ucxt=0x7f2c84004380, xsp=0x7f2c84004378 "\017\331i")
at dr/git/src/core/unix/signal.c:4372
Program received signal SIGSEGV, Segmentation fault.
safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
2382 DECLARE_FUNC(_dynamorio_runtime_resolve)
(gdb) bt
#0 safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
#1 0x00000000006b70ac in is_thread_tls_initialized () at dr/git/src/core/unix/os.c:1446
#2 0x00000000006b9627 in get_tls_thread_id () at dr/git/src/core/unix/os.c:2588
#3 0x00000000004732bb in is_thread_initialized () at dr/git/src/core/dynamo.c:1802
#4 0x00000000006cbf40 in os_thread_re_take_over () at dr/git/src/core/unix/os.c:9736
#5 0x00000000006cc167 in os_thread_take_over (mc=0x7f2c84004020, sigset=0x7f2c840044a8) at dr/git/src/core/unix/os.c:9773
#6 0x00000000006d8b7a in sig_take_over (uc=0x7f2c84004380) at dr/git/src/core/unix/signal.c:4293
#7 0x00000000006d8daf in master_signal_handler_C (sig=12, siginfo=0x7f2c840044b0, ucxt=0x7f2c84004380, xsp=0x7f2c84004378 "\017\331i")
at dr/git/src/core/unix/signal.c:4425
```
And get things like this during takeover:
```
Program received signal SIGSEGV, Segmentation fault.
safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
2382 DECLARE_FUNC(_dynamorio_runtime_resolve)
(gdb) bt
#0 safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
#1 0x00000000006b70ac in is_thread_tls_initialized () at dr/git/src/core/unix/os.c:1446
#2 0x00000000006b9627 in get_tls_thread_id () at dr/git/src/core/unix/os.c:2588
#3 0x00000000006b9605 in get_thread_id () at dr/git/src/core/unix/os.c:2577
c#4 0x00000000004fcd30 in deadlock_avoidance_lock (lock=0x7e72c0 , acquired=true, ownable=true) at dr/git/src/core/utils.c:574
#5 0x00000000004fd840 in mutex_trylock (lock=0x7e72c0 ) at dr/git/src/core/utils.c:918
#6 0x00000000004fd728 in mutex_lock (lock=0x7e72c0 ) at dr/git/src/core/utils.c:857
#7 0x0000000000473e32 in dynamo_thread_init (dstack_in=0x0, mc=0x7f2c84004020, client_thread=false) at dr/git/src/core/dynamo.c:2109
#8 0x00000000006cc18d in os_thread_take_over (mc=0x7f2c84004020, sigset=0x7f2c840044a8) at dr/git/src/core/unix/os.c:9775
#9 0x00000000006d8b7a in sig_take_over (uc=0x7f2c84004380) at dr/git/src/core/unix/signal.c:4293
#10 0x00000000006d8daf in master_signal_handler_C (sig=12, siginfo=0x7f2c840044b0, ucxt=0x7f2c84004380, xsp=0x7f2c84004378 "\017\331i")
at dr/git/src/core/unix/signal.c:4425
Program received signal SIGSEGV, Segmentation fault.
safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
2382 DECLARE_FUNC(_dynamorio_runtime_resolve)
(gdb) bt
#0 safe_read_tls_magic () at dr/git/src/core/arch/x86/x86.asm:2382
#1 0x00000000006b70ac in is_thread_tls_initialized () at dr/git/src/core/unix/os.c:1446
#2 0x00000000006b9627 in get_tls_thread_id () at dr/git/src/core/unix/os.c:2588
#3 0x00000000006b9605 in get_thread_id () at dr/git/src/core/unix/os.c:2577
#4 0x00000000004fe352 in self_owns_write_lock (rw=0x498cf748) at dr/git/src/core/utils.c:1320
#5 0x00000000006e8bd3 in memcache_lock () at dr/git/src/core/unix/memcache.c:130
#6 0x00000000006c67cf in all_memory_areas_lock () at dr/git/src/core/unix/os.c:7539
#7 0x00000000005aad12 in dynamo_vm_areas_lock () at dr/git/src/core/vmareas.c:3504
#8 0x0000000000587e76 in get_guarded_real_memory (reserve_size=12288, commit_size=4096, prot=7, add_vm=true, guarded=true, min_addr=0x0, comment=0x73b859 "heap_mmap")
at dr/git/src/core/heap.c:2009
#9 0x0000000000588746 in heap_mmap_ex (reserve_size=4096, commit_size=4096, prot=7, guarded=true) at dr/git/src/core/heap.c:2121
#10 0x0000000000588c24 in heap_mmap_reserve (reserve_size=4096, commit_size=4096) at dr/git/src/core/heap.c:2147
#11 0x000000000058a43f in heap_mmap (size=4096) at dr/git/src/core/heap.c:2348
#12 0x00000000006b7e40 in os_tls_init () at dr/git/src/core/unix/os.c:1890
#13 0x0000000000473f52 in dynamo_thread_init (dstack_in=0x0, mc=0x7f2c84004020, client_thread=false) at dr/git/src/core/dynamo.c:2142
#14 0x00000000006cc18d in os_thread_take_over (mc=0x7f2c84004020, sigset=0x7f2c840044a8) at dr/git/src/core/unix/os.c:9775
#15 0x00000000006d8b7a in sig_take_over (uc=0x7f2c84004380) at dr/git/src/core/unix/signal.c:4293
#16 0x00000000006d8daf in master_signal_handler_C (sig=12, siginfo=0x7f2c840044b0, ucxt=0x7f2c84004380, xsp=0x7f2c84004378 "\017\331i")
at dr/git/src/core/unix/signal.c:4425
```
Contributor guide
Assessment
This issue has not been assessed yet.