]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: make the thread harmless during the mmap/munmap syscalls
authorWilly Tarreau <w@1wt.eu>
Thu, 4 Jul 2019 14:18:23 +0000 (16:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 9 Jul 2019 08:40:33 +0000 (10:40 +0200)
These calls can take quite some time and leave the thread harmless so
it's better to mark it as such. This makes "show sess" respond way
faster during high loads running on processes build with DEBUG_UAF
since these calls are stressed a lot.

include/common/memory.h

index 5f96ac079b16fcaa6130a1471cb3f6d0ecc8d2db..3283d2be1e58fa4c662450cdc7798ebb9a7cbd83 100644 (file)
@@ -418,16 +418,21 @@ static inline void *pool_alloc_area(size_t size)
        size_t pad = (4096 - size) & 0xFF0;
        void *ret;
 
+       thread_harmless_now();
        ret = mmap(NULL, (size + 4095) & -4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-       if (ret == MAP_FAILED)
-               return NULL;
-       /* let's dereference the page before returning so that the real
-        * allocation in the system is performed without holding the lock.
-        */
-       *(int *)ret = 0;
-       if (pad >= sizeof(void *))
-               *(void **)(ret + pad - sizeof(void *)) = ret + pad;
-       return ret + pad;
+       if (ret != MAP_FAILED) {
+               /* let's dereference the page before returning so that the real
+                * allocation in the system is performed without holding the lock.
+                */
+               *(int *)ret = 0;
+               if (pad >= sizeof(void *))
+                       *(void **)(ret + pad - sizeof(void *)) = ret + pad;
+               ret += pad;
+       } else {
+               ret = NULL;
+       }
+       thread_harmless_end();
+       return ret;
 }
 
 /* frees an area <area> of size <size> allocated by pool_alloc_area(). The
@@ -443,7 +448,9 @@ static inline void pool_free_area(void *area, size_t size)
        if (pad >= sizeof(void *) && *(void **)(area - sizeof(void *)) != area)
                *(volatile int *)0 = 0;
 
+       thread_harmless_now();
        munmap(area - pad, (size + 4095) & -4096);
+       thread_harmless_end();
 }
 
 #endif /* DEBUG_UAF */