Skip to content

Commit 6021e94

Browse files
author
Alexey Samsonov
committed
[TSan] Allocate fd table in user heap instead of using internal allocator. We need this to catch races on fds.
llvm-svn: 179841
1 parent 0e89ade commit 6021e94

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

compiler-rt/lib/tsan/rtl/tsan_fd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ static FdDesc *fddesc(ThreadState *thr, uptr pc, int fd) {
7474
uptr l1 = atomic_load(pl1, memory_order_consume);
7575
if (l1 == 0) {
7676
uptr size = kTableSizeL2 * sizeof(FdDesc);
77-
void *p = internal_alloc(MBlockFD, size);
77+
// We need this to reside in user memory to properly catch races on it.
78+
void *p = user_alloc(thr, pc, size);
7879
internal_memset(p, 0, size);
7980
MemoryResetRange(thr, (uptr)&fddesc, (uptr)p, size);
8081
if (atomic_compare_exchange_strong(pl1, &l1, (uptr)p, memory_order_acq_rel))
8182
l1 = (uptr)p;
8283
else
83-
internal_free(p);
84+
user_free(thr, pc, p);
8485
}
8586
return &((FdDesc*)l1)[fd % kTableSizeL2]; // NOLINT
8687
}

0 commit comments

Comments
 (0)