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
This commit is contained in:
alecf%netscape.com
1999-10-05 00:29:09 +00:00
parent 4c19332cbb
commit d721125978
2 changed files with 63 additions and 0 deletions

View File

@@ -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 <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
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

View File

@@ -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) {