]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/msan/fork.cc
1 // Test that chained origins are fork-safe.
2 // Run a number of threads that create new chained origins, then fork
3 // and verify that origin reads do not deadlock in the child process.
5 // RUN: %clangxx_msan -std=c++11 -fsanitize-memory-track-origins=2 -g -O3 %s -o %t
6 // RUN: MSAN_OPTIONS=store_context_size=1000,origin_history_size=0,origin_history_per_stack_limit=0 %run %t |& FileCheck %s
8 // Fun fact: if test output is redirected to a file (as opposed to
9 // being piped directly to FileCheck), we may lose some "done"s due to
11 // https://lkml.org/lkml/2014/2/17/324
18 #include <sys/types.h>
24 #include <sanitizer/msan_interface.h>
28 void copy_uninit_thread2() {
34 if (__atomic_load_n(&done
, __ATOMIC_RELAXED
))
39 void copy_uninit_thread1(int level
) {
41 copy_uninit_thread2();
43 copy_uninit_thread1(level
- 1);
46 void *copy_uninit_thread(void *id
) {
47 copy_uninit_thread1((long)id
);
51 // Run through stackdepot in the child process.
52 // If any of the hash table cells are locked, this may deadlock.
56 for (int i
= 0; i
< 10000; ++i
) {
60 write(2, "done\n", 5);
64 const int kThreads
= 10;
65 pthread_t t
[kThreads
];
66 for (int i
= 0; i
< kThreads
; ++i
)
67 pthread_create(&t
[i
], NULL
, copy_uninit_thread
, (void*)(long)i
);
72 __atomic_store_n(&done
, 1, __ATOMIC_RELAXED
);
74 while ((p
= wait(NULL
)) == -1) { }
82 const int kChildren
= 20;
83 for (int i
= 0; i
< kChildren
; ++i
) {
93 for (int i
= 0; i
< kChildren
; ++i
) {
95 while ((p
= wait(NULL
)) == -1) { }
101 // Expect 20 (== kChildren) "done" messages.