From d7211259789d10798d1ef8a42f60b8821587d0b8 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Tue, 5 Oct 1999 00:29:09 +0000 Subject: [PATCH] add detection for broken mmap()/write() behavior contributed by jim_nance@yahoo.com r=alecf git-svn-id: svn://10.0.0.236/trunk@49761 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/configure.in | 47 +++++++++++++++++++++++++++++ mozilla/modules/libreg/src/mmapio.c | 16 ++++++++++ 2 files changed, 63 insertions(+) diff --git a/mozilla/configure.in b/mozilla/configure.in index 17cfd71b8b5..b0d7dd9933e 100644 --- a/mozilla/configure.in +++ b/mozilla/configure.in @@ -1700,6 +1700,53 @@ else MOZ_NATIVE_NSPR=1 fi +dnl See if mmap sees writes +dnl ======================================================== +dnl For cross compiling, just define it as no, which is a safe default +AC_MSG_CHECKING(if mmap() sees write()s) + +changequote(,) +mmap_test_prog=' + #include + #include + #include + #include + #include + #include + + char fname[] = "conftest.file"; + char zbuff[1024]; /* Fractional page is probably worst case */ + + int main() { + char *map; + int fd; + int i; + unlink(fname); + fd = open(fname, O_RDWR | O_CREAT, 0660); + if(fd<0) return 1; + unlink(fname); + write(fd, zbuff, sizeof(zbuff)); + lseek(fd, 0, SEEK_SET); + map = (char*)mmap(0, sizeof(zbuff), PROT_READ, MAP_SHARED, fd, 0); + if(map==(char*)-1) return 2; + for(i=0; fname[i]; i++) { + int rc = write(fd, &fname[i], 1); + if(map[i]!=fname[i]) return 4; + } + return 0; + } +' +changequote([,]) + +AC_TRY_RUN($mmap_test_prog , result="yes", result="no", result="yes") + +AC_MSG_RESULT("$result") + +if test "$result" = "no"; then + AC_DEFINE(MMAP_MISSES_WRITES) +fi + + dnl Checks for library functions. dnl ======================================================== AC_PROG_GCC_TRADITIONAL diff --git a/mozilla/modules/libreg/src/mmapio.c b/mozilla/modules/libreg/src/mmapio.c index 4d21a9a7b5d..f9fb2f0a2b5 100644 --- a/mozilla/modules/libreg/src/mmapio.c +++ b/mozilla/modules/libreg/src/mmapio.c @@ -117,6 +117,22 @@ PRInt32 mmio_FileWrite(MmioFile *mmio, const char *src, PRInt32 count) mmio->needSeek = PR_FALSE; } + /* If this system does not keep mmap() and write() synchronized, we can + ** force it to by doing an munmap() when we do a write. This will + ** obviously slow things down but fortunatly we do not do that many + ** writes from within mozilla. Platforms which need this may want to + ** use the new USE_BUFFERED_REGISTRY_IO code instead of this code though. + */ +#if MMAP_MISSES_WRITES + if(mmio->addr && mmio->msize) { + PR_ASSERT(mmio->fileMap); + PR_MemUnmap(mmio->addr, mmio->msize); + PR_CloseFileMap(mmio->fileMap); + mmio->addr = NULL; + mmio->msize = 0; + } +#endif + wcode = PR_Write(mmio->fd, src, count); if(wcode>0) {