[PATCH] [TSan] Allocate fd table in user heap instead of using internal allocator

Alexey Samsonov samsonov at google.com
Fri Apr 12 08:34:31 PDT 2013


Hi dvyukov,

We catch races on file descriptors assuming fd table is located in the
user memory (as we use functions like MemoryImitateWrite). Thus, it's wrong to allocate
this table with internal_alloc() - we were lucky up to now because internal_alloc()
us currently libc malloc.

http://llvm-reviews.chandlerc.com/D663

Files:
  lib/tsan/rtl/tsan_fd.cc

Index: lib/tsan/rtl/tsan_fd.cc
===================================================================
--- lib/tsan/rtl/tsan_fd.cc
+++ lib/tsan/rtl/tsan_fd.cc
@@ -74,13 +74,14 @@
   uptr l1 = atomic_load(pl1, memory_order_consume);
   if (l1 == 0) {
     uptr size = kTableSizeL2 * sizeof(FdDesc);
-    void *p = internal_alloc(MBlockFD, size);
+    // We need this to reside in user memory to properly catch races on it.
+    void *p = user_alloc(thr, pc, size);
     internal_memset(p, 0, size);
     MemoryResetRange(thr, (uptr)&fddesc, (uptr)p, size);
     if (atomic_compare_exchange_strong(pl1, &l1, (uptr)p, memory_order_acq_rel))
       l1 = (uptr)p;
     else
-      internal_free(p);
+      user_free(thr, pc, p);
   }
   return &((FdDesc*)l1)[fd % kTableSizeL2];  // NOLINT
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D663.1.patch
Type: text/x-patch
Size: 784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130412/37d4263f/attachment.bin>


More information about the llvm-commits mailing list