Make mlock() and munlock() portable to systems that require the address to be on...
authorDoug Huff <mith@jrbobdobbs.org>
Thu, 30 Jun 2011 00:04:44 +0000 (02:04 +0200)
committerMatt Corallo <matt@bluematt.me>
Sun, 10 Jul 2011 16:15:05 +0000 (18:15 +0200)
src/serialize.h

index 6952004..38c533d 100644 (file)
@@ -38,6 +38,18 @@ typedef unsigned long long  uint64;
 #define munlock(p, n) VirtualUnlock((p), (n));
 #else
 #include <sys/mman.h>
+#include <limits.h>
+/* This comes from limits.h if it's not defined there set a sane default */
+#ifndef PAGESIZE
+#include <unistd.h>
+#define PAGESIZE sysconf(_SC_PAGESIZE)
+#endif
+#define mlock(a,b) \
+  mlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\
+  (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1))))
+#define munlock(a,b) \
+  munlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\
+  (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1))))
 #endif
 
 class CScript;