[PATCH] D42696: [scudo] Minor Secondary changes

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 10:28:42 PST 2018


cryptoad created this revision.
cryptoad added a reviewer: alekseyshl.
Herald added subscribers: Sanitizers, delcypher.

Few changes to the secondary:

- mark `const` variables as such;
- change some `CHECK` to `DCHECK`: I don't feel we need to be as conservative as we were with out checks, as they are the results of our own computation.
- mark a condition as `UNLIKELY`.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42696

Files:
  lib/scudo/scudo_allocator_secondary.h


Index: lib/scudo/scudo_allocator_secondary.h
===================================================================
--- lib/scudo/scudo_allocator_secondary.h
+++ lib/scudo/scudo_allocator_secondary.h
@@ -41,7 +41,7 @@
 
     ReservedAddressRange AddressRange;
     uptr MapBeg = AddressRange.Init(MapSize);
-    if (MapBeg == ~static_cast<uptr>(0))
+    if (UNLIKELY(MapBeg == ~static_cast<uptr>(0)))
       return ReturnNullOrDieOnFailure::OnOOM();
     // A page-aligned pointer is assumed after that, so check it now.
     CHECK(IsAligned(MapBeg, PageSize));
@@ -58,25 +58,25 @@
     if (Alignment > MinAlignment) {
       if (!IsAligned(UserBeg, Alignment)) {
         UserBeg = RoundUpTo(UserBeg, Alignment);
-        CHECK_GE(UserBeg, MapBeg);
-        uptr NewMapBeg = RoundDownTo(UserBeg - HeadersSize, PageSize) -
+        DCHECK_GE(UserBeg, MapBeg);
+        const uptr NewMapBeg = RoundDownTo(UserBeg - HeadersSize, PageSize) -
             PageSize;
-        CHECK_GE(NewMapBeg, MapBeg);
+        DCHECK_GE(NewMapBeg, MapBeg);
         if (NewMapBeg != MapBeg) {
           AddressRange.Unmap(MapBeg, NewMapBeg - MapBeg);
           MapBeg = NewMapBeg;
         }
         UserEnd = UserBeg + UserSize;
       }
-      uptr NewMapEnd = RoundUpTo(UserEnd, PageSize) + PageSize;
+      const uptr NewMapEnd = RoundUpTo(UserEnd, PageSize) + PageSize;
       if (NewMapEnd != MapEnd) {
         AddressRange.Unmap(NewMapEnd, MapEnd - NewMapEnd);
         MapEnd = NewMapEnd;
       }
       MapSize = MapEnd - MapBeg;
     }
 
-    CHECK_LE(UserEnd, MapEnd - PageSize);
+    DCHECK_LE(UserEnd, MapEnd - PageSize);
     // Actually mmap the memory, preserving the guard pages on either side
     CHECK_EQ(MapBeg + PageSize,
              AddressRange.Map(MapBeg + PageSize, MapSize - 2 * PageSize));
@@ -111,10 +111,10 @@
   }
 
   uptr GetActuallyAllocatedSize(void *Ptr) {
-    ReservedAddressRange *StoredRange = getReservedAddressRange(Ptr);
+    const ReservedAddressRange *StoredRange = getReservedAddressRange(Ptr);
     // Deduct PageSize as ReservedAddressRange size includes the trailing guard
     // page.
-    uptr MapEnd = reinterpret_cast<uptr>(StoredRange->base()) +
+    const uptr MapEnd = reinterpret_cast<uptr>(StoredRange->base()) +
         StoredRange->size() - PageSizeCached;
     return MapEnd - reinterpret_cast<uptr>(Ptr);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42696.132000.patch
Type: text/x-patch
Size: 2360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180130/ec0768a6/attachment.bin>


More information about the llvm-commits mailing list