diff options
author | Doug Huff <mith@jrbobdobbs.org> | 2011-06-30 02:04:44 +0200 |
---|---|---|
committer | Matt Corallo <matt@bluematt.me> | 2011-07-10 18:15:05 +0200 |
commit | a48c671957e37594d8f9e0fd51b24e7a4f44300e (patch) | |
tree | ed3b96a30c128935a1b52ae30cf36dd0ccf39f51 /src/serialize.h | |
parent | c1aacf0be347b10a6ab9bbce841e8127412bce41 (diff) |
Make mlock() and munlock() portable to systems that require the address to be on a page boundary.
Diffstat (limited to 'src/serialize.h')
-rw-r--r-- | src/serialize.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/serialize.h b/src/serialize.h index 6952004e2e..38c533d9ae 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -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; |