| | @@ -17,10 +17,13 @@ |
| 17 | 17 | ** |
| 18 | 18 | ** This file contains code for miscellaneous utility routines. |
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "util.h" |
| 22 | +#if defined(USE_MMAN_H) |
| 23 | +# include <sys/mman.h> |
| 24 | +#endif |
| 22 | 25 | |
| 23 | 26 | /* |
| 24 | 27 | ** For the fossil_timer_xxx() family of functions... |
| 25 | 28 | */ |
| 26 | 29 | #ifdef _WIN32 |
| | @@ -91,10 +94,18 @@ |
| 91 | 94 | fossil_fatal("VirtualAlloc failed: %lu\n", GetLastError()); |
| 92 | 95 | } |
| 93 | 96 | if( !VirtualLock(p, pageSize) ){ |
| 94 | 97 | fossil_fatal("VirtualLock failed: %lu\n", GetLastError()); |
| 95 | 98 | } |
| 99 | +#elif defined(USE_MMAN_H) |
| 100 | + p = mmap(0, pageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
| 101 | + if( p==MAP_FAILED ){ |
| 102 | + fossil_fatal("mmap failed: %d\n", errno); |
| 103 | + } |
| 104 | + if( mlock(p, pageSize) ){ |
| 105 | + fossil_fatal("mlock failed: %d\n", errno); |
| 106 | + } |
| 96 | 107 | #else |
| 97 | 108 | p = fossil_malloc(pageSize); |
| 98 | 109 | #endif |
| 99 | 110 | fossil_secure_zero(p, pageSize); |
| 100 | 111 | if( pN ) *pN = pageSize; |
| | @@ -109,10 +120,17 @@ |
| 109 | 120 | fossil_fatal("VirtualUnlock failed: %lu\n", GetLastError()); |
| 110 | 121 | } |
| 111 | 122 | if( !VirtualFree(p, 0, MEM_RELEASE) ){ |
| 112 | 123 | fossil_fatal("VirtualFree failed: %lu\n", GetLastError()); |
| 113 | 124 | } |
| 125 | +#elif defined(USE_MMAN_H) |
| 126 | + if( munlock(p, n) ){ |
| 127 | + fossil_fatal("munlock failed: %d\n", errno); |
| 128 | + } |
| 129 | + if( munmap(p, n) ){ |
| 130 | + fossil_fatal("munmap failed: %d\n", errno); |
| 131 | + } |
| 114 | 132 | #else |
| 115 | 133 | fossil_free(p); |
| 116 | 134 | #endif |
| 117 | 135 | } |
| 118 | 136 | |
| 119 | 137 | |