Blame SOURCES/dyninst-9.2.0-pr176-constrain-trymmap.patch

43d1af
commit 42729454d3a69ae30694646dc5a95737b887b829
43d1af
Author: Josh Stone <jistone@redhat.com>
43d1af
Date:   Fri Sep 9 14:27:49 2016 -0700
43d1af
43d1af
    RT: trymmap should retry if the result is out of range
43d1af
    
43d1af
    An address passed to `mmap` is just taken as a hint, and the OS may
43d1af
    return something wildly different if that address is not available.
43d1af
    This is undesirable when we're trying to create a constrained alloc.
43d1af
    
43d1af
    Now we will check that the address is in the requested range before
43d1af
    accepting it.  Otherwise, unmap it and try a new hint.
43d1af
43d1af
diff --git a/dyninstAPI_RT/src/RTheap.c b/dyninstAPI_RT/src/RTheap.c
43d1af
index eae69700d3ef..ddb4a363bf25 100644
43d1af
--- a/dyninstAPI_RT/src/RTheap.c
43d1af
+++ b/dyninstAPI_RT/src/RTheap.c
43d1af
@@ -128,8 +128,13 @@ static Address trymmap(size_t len, Address beg, Address end, size_t inc, int fd)
43d1af
   /* until we get one that succeeds.*/
43d1af
   for (addr = beg; addr + len <= end; addr += inc) {
43d1af
     result = map_region((void *) addr, len, fd);
43d1af
-    if (result)
43d1af
+    if (result) {
43d1af
+      /* Success doesn't necessarily mean it actually mapped at the hinted
43d1af
+       * address.  Return if it's in range, else unmap and try again. */
43d1af
+      if ((Address) result >= beg && (Address) result + len <= end)
43d1af
         return (Address) result;
43d1af
+      unmap_region(result, len);
43d1af
+    }
43d1af
   }
43d1af
   return (Address) NULL;
43d1af
 }