Index: Makefile.in ================================================================== --- Makefile.in +++ Makefile.in @@ -43,10 +43,11 @@ BCCFLAGS = @CPPFLAGS@ @CFLAGS@ TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H INSTALLDIR = $(DESTDIR)@prefix@/bin USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@ USE_LINENOISE = @USE_LINENOISE@ +USE_MMAN_H = @USE_MMAN_H@ USE_SEE = @USE_SEE@ FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@ include $(SRCDIR)/main.mk Index: auto.def ================================================================== --- auto.def +++ auto.def @@ -15,10 +15,11 @@ with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages} with-tcl:path => {Enable Tcl integration, with Tcl in the specified path} with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism} with-tcl-private-stubs=0 => {Enable Tcl integration via private stubs mechanism} + with-mman=0 => {Enable use of POSIX memory APIs from "sys/mman.h"} with-see=0 => {Enable the SQLite Encryption Extension (SEE)} internal-sqlite=1 => {Don't use the internal SQLite, use the system one} static=0 => {Link a static executable} fusefs=1 => {Disable the Fuse Filesystem} fossil-debug=0 => {Build with fossil debugging enabled} @@ -40,10 +41,11 @@ define EXTRA_CFLAGS "-Wall" define EXTRA_LDFLAGS "" define USE_SYSTEM_SQLITE 0 define USE_LINENOISE 0 define FOSSIL_ENABLE_MINIZ 0 +define USE_MMAN_H 0 define USE_SEE 0 # This procedure is a customized version of "cc-check-function-in-lib", # that does not modify the LIBS variable. Its use prevents prematurely # pulling in libraries that will be added later anyhow (e.g. "-ldl"). @@ -141,10 +143,16 @@ if {[opt-bool no-opt]} { define CFLAGS {-g -O0 -Wall} msg-result "Builting without compiler optimization" } + +if {[opt-bool with-mman]} { + define-append EXTRA_CFLAGS -DUSE_MMAN_H + define USE_MMAN_H 1 + msg-result "Enabling \"sys/mman.h\" support" +} if {[opt-bool with-see]} { define-append EXTRA_CFLAGS -DUSE_SEE define USE_SEE 1 msg-result "Enabling encryption support" Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -920,16 +920,20 @@ #if defined(FOSSIL_ENABLE_TCL) int rc; const char *zRc; #endif Stmt q; + size_t pageSize = 0; blob_zero(pOut); blob_appendf(pOut, "This is fossil version %s\n", get_version()); if( !bVerbose ) return; blob_appendf(pOut, "Compiled on %s %s using %s (%d-bit)\n", __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8); blob_appendf(pOut, "Schema version %s\n", AUX_SCHEMA_MAX); + fossil_get_page_size(&pageSize); + blob_appendf(pOut, "Detected memory page size is %lu bytes\n", + (unsigned long)pageSize); #if defined(FOSSIL_ENABLE_MINIZ) blob_appendf(pOut, "miniz %s, loaded %s\n", MZ_VERSION, mz_version()); #else blob_appendf(pOut, "zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion()); #endif @@ -992,10 +996,13 @@ blob_append(pOut, "FOSSIL_STATIC_BUILD\n", -1); #endif #if defined(HAVE_PLEDGE) blob_append(pOut, "HAVE_PLEDGE\n", -1); #endif +#if defined(USE_MMAN_H) + blob_append(pOut, "USE_MMAN_H\n", -1); +#endif #if defined(USE_SEE) blob_append(pOut, "USE_SEE\n", -1); #endif #if defined(FOSSIL_ALLOW_OUT_OF_ORDER_DATES) blob_append(pOut, "FOSSIL_ALLOW_OUT_OF_ORDER_DATES\n"); Index: src/makemake.tcl ================================================================== --- src/makemake.tcl +++ src/makemake.tcl @@ -623,10 +623,14 @@ # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1 #### Use 'system' SQLite # # USE_SYSTEM_SQLITE = 1 + +#### Use POSIX memory APIs from "sys/mman.h" +# +# USE_MMAN_H = 1 #### Use the SQLite Encryption Extension # # USE_SEE = 1 @@ -860,10 +864,16 @@ # With JSON support ifdef FOSSIL_ENABLE_JSON TCC += -DFOSSIL_ENABLE_JSON=1 RCC += -DFOSSIL_ENABLE_JSON=1 endif + +# With "sys/mman.h" support +ifdef USE_MMAN_H +TCC += -DUSE_MMAN_H=1 +RCC += -DUSE_MMAN_H=1 +endif # With SQLite Encryption Extension support ifdef USE_SEE TCC += -DUSE_SEE=1 RCC += -DUSE_SEE=1 Index: src/th_main.c ================================================================== --- src/th_main.c +++ src/th_main.c @@ -749,10 +749,11 @@ ** "tclPrivateStubs" = FOSSIL_ENABLE_TCL_PRIVATE_STUBS ** "json" = FOSSIL_ENABLE_JSON ** "markdown" = FOSSIL_ENABLE_MARKDOWN ** "unicodeCmdLine" = !BROKEN_MINGW_CMDLINE ** "dynamicBuild" = FOSSIL_DYNAMIC_BUILD +** "mman" = USE_MMAN_H ** "see" = USE_SEE ** ** Specifying an unknown feature will return a value of false, it will not ** raise a script error. */ @@ -829,10 +830,15 @@ #endif #if defined(FOSSIL_DYNAMIC_BUILD) else if( 0 == fossil_strnicmp( zArg, "dynamicBuild\0", 13 ) ){ rc = 1; } +#endif +#if defined(USE_MMAN_H) + else if( 0 == fossil_strnicmp( zArg, "mman\0", 5 ) ){ + rc = 1; + } #endif #if defined(USE_SEE) else if( 0 == fossil_strnicmp( zArg, "see\0", 4 ) ){ rc = 1; } Index: src/util.c ================================================================== --- src/util.c +++ src/util.c @@ -17,10 +17,14 @@ ** ** This file contains code for miscellaneous utility routines. */ #include "config.h" #include "util.h" +#if defined(USE_MMAN_H) +# include +# include +#endif /* ** For the fossil_timer_xxx() family of functions... */ #ifdef _WIN32 @@ -72,10 +76,12 @@ #if defined(_WIN32) SYSTEM_INFO sysInfo; memset(&sysInfo, 0, sizeof(SYSTEM_INFO)); GetSystemInfo(&sysInfo); *piPageSize = (size_t)sysInfo.dwPageSize; +#elif defined(USE_MMAN_H) + *piPageSize = (size_t)sysconf(_SC_PAGE_SIZE); #else *piPageSize = 4096; /* FIXME: What for POSIX? */ #endif } void *fossil_secure_alloc_page(size_t *pN){ @@ -91,10 +97,18 @@ fossil_fatal("VirtualAlloc failed: %lu\n", GetLastError()); } if( !VirtualLock(p, pageSize) ){ fossil_fatal("VirtualLock failed: %lu\n", GetLastError()); } +#elif defined(USE_MMAN_H) + p = mmap(0, pageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if( p==MAP_FAILED ){ + fossil_fatal("mmap failed: %d\n", errno); + } + if( mlock(p, pageSize) ){ + fossil_fatal("mlock failed: %d\n", errno); + } #else p = fossil_malloc(pageSize); #endif fossil_secure_zero(p, pageSize); if( pN ) *pN = pageSize; @@ -109,10 +123,17 @@ fossil_fatal("VirtualUnlock failed: %lu\n", GetLastError()); } if( !VirtualFree(p, 0, MEM_RELEASE) ){ fossil_fatal("VirtualFree failed: %lu\n", GetLastError()); } +#elif defined(USE_MMAN_H) + if( munlock(p, n) ){ + fossil_fatal("munlock failed: %d\n", errno); + } + if( munmap(p, n) ){ + fossil_fatal("munmap failed: %d\n", errno); + } #else fossil_free(p); #endif } Index: win/Makefile.mingw ================================================================== --- win/Makefile.mingw +++ win/Makefile.mingw @@ -96,10 +96,14 @@ # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1 #### Use 'system' SQLite # # USE_SYSTEM_SQLITE = 1 + +#### Use POSIX memory APIs from "sys/mman.h" +# +# USE_MMAN_H = 1 #### Use the SQLite Encryption Extension # # USE_SEE = 1 @@ -333,10 +337,16 @@ # With JSON support ifdef FOSSIL_ENABLE_JSON TCC += -DFOSSIL_ENABLE_JSON=1 RCC += -DFOSSIL_ENABLE_JSON=1 endif + +# With "sys/mman.h" support +ifdef USE_MMAN_H +TCC += -DUSE_MMAN_H=1 +RCC += -DUSE_MMAN_H=1 +endif # With SQLite Encryption Extension support ifdef USE_SEE TCC += -DUSE_SEE=1 RCC += -DUSE_SEE=1 Index: win/Makefile.mingw.mistachkin ================================================================== --- win/Makefile.mingw.mistachkin +++ win/Makefile.mingw.mistachkin @@ -96,10 +96,14 @@ FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1 #### Use 'system' SQLite # # USE_SYSTEM_SQLITE = 1 + +#### Use POSIX memory APIs from "sys/mman.h" +# +# USE_MMAN_H = 1 #### Use the SQLite Encryption Extension # # USE_SEE = 1 @@ -333,10 +337,16 @@ # With JSON support ifdef FOSSIL_ENABLE_JSON TCC += -DFOSSIL_ENABLE_JSON=1 RCC += -DFOSSIL_ENABLE_JSON=1 endif + +# With "sys/mman.h" support +ifdef USE_MMAN_H +TCC += -DUSE_MMAN_H=1 +RCC += -DUSE_MMAN_H=1 +endif # With SQLite Encryption Extension support ifdef USE_SEE TCC += -DUSE_SEE=1 RCC += -DUSE_SEE=1 Index: win/fossil.rc ================================================================== --- win/fossil.rc +++ win/fossil.rc @@ -161,10 +161,15 @@ #endif /* defined(FOSSIL_ENABLE_TCL_PRIVATE_STUBS) */ #endif /* defined(FOSSIL_ENABLE_TCL) */ #if defined(FOSSIL_ENABLE_JSON) VALUE "JsonEnabled", "Yes, cson " FOSSIL_JSON_API_VERSION "\0" #endif /* defined(FOSSIL_ENABLE_JSON) */ +#if defined(USE_MMAN_H) + VALUE "UseMmanEnabled", "Yes\0" +#else + VALUE "UseMmanEnabled", "No\0" +#endif /* defined(USE_MMAN_H) */ #if defined(USE_SEE) VALUE "UseSeeEnabled", "Yes\0" #else VALUE "UseSeeEnabled", "No\0" #endif /* defined(USE_SEE) */ Index: www/th1.md ================================================================== --- www/th1.md +++ www/th1.md @@ -345,10 +345,11 @@ 1. **tclPrivateStubs** -- _Uses Tcl private stubs (i.e. header-only)._ 1. **json** -- _Support for the JSON APIs._ 1. **markdown** -- _Support for Markdown documentation format._ 1. **unicodeCmdLine** -- _The command line arguments are Unicode._ 1. **dynamicBuild** -- _Dynamically linked to libraries._ + 1. **mman** -- _Uses POSIX memory APIs from "sys/mman.h"._ 1. **see** -- _Uses the SQLite Encryption Extension._ Specifying an unknown feature will return a value of false, it will not raise a script error.