Skip to content

Commit 2d7b1db

Browse files
committed
druntime/dmain2: disable RTSan monitoring in init_rt ...
... this function is not real-time safe and also not rtsan safe (will lock-up rtsan's stack scanner)
1 parent 120e752 commit 2d7b1db

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

runtime/druntime/src/ldc/sanitizers_optionally_linked.d

+27
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ version (SupportSanitizers)
3939
void __sanitizer_finish_switch_fiber(void* fake_stack_save, const(void)** bottom_old, size_t* size_old);
4040
void* __asan_get_current_fake_stack();
4141
void* __asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg, void **end);
42+
void __rtsan_disable();
43+
void __rtsan_enable();
44+
void __rtsan_notify_blocking_call(const(char)* name);
4245
});
4346
}
4447

@@ -79,6 +82,30 @@ version (SupportSanitizers)
7982
return null;
8083
}
8184

85+
nothrow @nogc
86+
void rtsanDisable()
87+
{
88+
auto fptr = getOptionalSanitizerFunc!"__rtsan_disable"();
89+
if (fptr)
90+
fptr();
91+
}
92+
93+
nothrow @nogc
94+
void rtsanEnable()
95+
{
96+
auto fptr = getOptionalSanitizerFunc!"__rtsan_enable"();
97+
if (fptr)
98+
fptr();
99+
}
100+
101+
nothrow @nogc
102+
void rtsanNotifyBlockingCall(const(char) *name)
103+
{
104+
auto fptr = getOptionalSanitizerFunc!"__rtsan_notify_blocking_call"();
105+
if (fptr)
106+
fptr(name);
107+
}
108+
82109
// This uses the forward declaration of `functionName` and returns a pointer to that function
83110
// if it is found in the executable, and `null` otherwise. Templated such that it can internally
84111
// cache the function pointer. Thread-safe.

runtime/druntime/src/rt/dmain2.d

+7
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ private shared size_t _initCount;
103103
*/
104104
extern (C) int rt_init()
105105
{
106+
version (SupportSanitizers)
107+
{
108+
import ldc.sanitizers_optionally_linked;
109+
rtsanNotifyBlockingCall("rt_init");
110+
rtsanDisable();
111+
scope (exit) rtsanEnable();
112+
}
106113
/* @@BUG 11380 @@ Need to synchronize rt_init/rt_term calls for
107114
version (Shared) druntime, because multiple C threads might
108115
initialize different D libraries without knowing about the

0 commit comments

Comments
 (0)