[msan] Disable mlock/mlockall to work around a linux kernel bug.

The same logic is present in ASan and TSan.

llvm-svn: 193755
This commit is contained in:
Evgeniy Stepanov 2013-10-31 15:51:22 +00:00
parent 3a9632d544
commit a7add488ae
2 changed files with 36 additions and 0 deletions

View File

@ -1172,6 +1172,35 @@ INTERCEPTOR(void *, shmat, int shmid, const void *shmaddr, int shmflg) {
return p;
}
// Linux kernel has a bug that leads to kernel deadlock if a process
// maps TBs of memory and then calls mlock().
static void MlockIsUnsupported() {
static atomic_uint8_t printed;
if (atomic_exchange(&printed, 1, memory_order_relaxed))
return;
if (common_flags()->verbosity > 0)
Printf("INFO: MemorySanitizer ignores mlock/mlockall/munlock/munlockall\n");
}
INTERCEPTOR(int, mlock, const void *addr, uptr len) {
MlockIsUnsupported();
return 0;
}
INTERCEPTOR(int, munlock, const void *addr, uptr len) {
MlockIsUnsupported();
return 0;
}
INTERCEPTOR(int, mlockall, int flags) {
MlockIsUnsupported();
return 0;
}
INTERCEPTOR(int, munlockall, void) {
MlockIsUnsupported();
return 0;
}
struct MSanInterceptorContext {
bool in_interceptor_scope;

View File

@ -3496,3 +3496,10 @@ TEST(MemorySanitizerAllocator, get_allocated_size_and_ownership) {
delete int_ptr;
}
TEST(MemorySanitizer, MlockTest) {
EXPECT_EQ(0, mlockall(MCL_CURRENT));
EXPECT_EQ(0, mlock((void*)0x12345, 0x5678));
EXPECT_EQ(0, munlockall());
EXPECT_EQ(0, munlock((void*)0x987, 0x654));
}