Bug 674014 - Remove "check whether mmap() sees write()s". r=glandium

This commit is contained in:
Marco Castelluccio 2011-08-18 15:17:30 +02:00
parent e7cc82ef30
commit fe9bc7f764
6 changed files with 1 additions and 379 deletions

View File

@ -3588,53 +3588,6 @@ then
LDFLAGS="${_PTHREAD_LDFLAGS} ${LDFLAGS}"
fi
dnl ========================================================
dnl See if mmap sees writes
dnl For cross compiling, just define it as no, which is a safe default
dnl ========================================================
AC_MSG_CHECKING(whether 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 ========================================================

View File

@ -3494,53 +3494,6 @@ then
LDFLAGS="${_PTHREAD_LDFLAGS} ${LDFLAGS}"
fi
dnl ========================================================
dnl See if mmap sees writes
dnl For cross compiling, just define it as no, which is a safe default
dnl ========================================================
AC_MSG_CHECKING(whether 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 ========================================================

View File

@ -68,11 +68,6 @@ SDK_LIBRARY = $(LIBRARY)
include $(topsrcdir)/config/config.mk
DEFINES += -DUSE_BUFFERED_REGISTRY_IO
# Memory mapped files are not supported under QNX, Neutrino, HP-UX and BeOS
#ifeq (,$(filter BeOS HP-UX QNX,$(OS_ARCH)))
#CSRCS += mmapio.c
#DEFINES += -DUSE_MMAP_REGISTRY_IO
#endif
include $(topsrcdir)/config/rules.mk

View File

@ -1,213 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* James L. Nance.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* James L. Nance <jim_nance@yahoo.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <string.h>
#include "mmapio.h"
#include "prmem.h"
#include "prlog.h"
struct MmioFileStruct
{
PRFileDesc *fd;
PRFileMap *fileMap;
PRUint32 fsize; /* The size of the file */
PRUint32 msize; /* The size of the mmap()ed area */
PRInt32 pos; /* Our logical position for doing I/O */
char *addr; /* The base address of our mapping */
PRBool needSeek; /* Do we need to seek to pos before doing a write() */
};
PRStatus mmio_FileSeek(MmioFile *mmio, PRInt32 offset, PRSeekWhence whence)
{
mmio->needSeek = PR_TRUE;
switch(whence) {
case PR_SEEK_SET:
mmio->pos = offset;
break;
case PR_SEEK_END:
mmio->pos = mmio->fsize + offset;
break;
case PR_SEEK_CUR:
mmio->pos = mmio->pos + offset;
break;
default:
return PR_FAILURE;
}
if(mmio->pos<0) {
mmio->pos = 0;
}
return PR_SUCCESS;
}
PRInt32 mmio_FileRead(MmioFile *mmio, char *dest, PRInt32 count)
{
static PRFileMapProtect prot = PR_PROT_READONLY;
static PRInt64 fsize_l;
/* First see if we are going to try and read past the end of the file
* and shorten count if we are.
*/
if(mmio->pos+count > mmio->fsize) {
count = mmio->fsize - mmio->pos;
}
if(count<1) {
return 0;
}
/* Check to see if we need to remap for this read */
if(mmio->pos+count > mmio->msize) {
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;
}
LL_UI2L(fsize_l, mmio->fsize);
mmio->fileMap = PR_CreateFileMap(mmio->fd, fsize_l, prot);
if(!mmio->fileMap) {
return -1;
}
mmio->addr = PR_MemMap(mmio->fileMap, 0, fsize_l);
if(!mmio->addr) {
return -1;
}
mmio->msize = mmio->fsize;
}
memcpy(dest, mmio->addr+mmio->pos, count);
mmio->pos += count;
mmio->needSeek = PR_TRUE;
return count;
}
PRInt32 mmio_FileWrite(MmioFile *mmio, const char *src, PRInt32 count)
{
PRInt32 wcode;
if(mmio->needSeek) {
PR_Seek(mmio->fd, mmio->pos, PR_SEEK_SET);
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) {
mmio->pos += wcode;
if(mmio->pos>mmio->fsize) {
mmio->fsize=mmio->pos;
}
}
return wcode;
}
PRInt32 mmio_FileTell(MmioFile *mmio)
{
return mmio->pos;
}
PRStatus mmio_FileClose(MmioFile *mmio)
{
if(mmio->addr && mmio->msize) {
PR_ASSERT(mmio->fileMap);
PR_MemUnmap(mmio->addr, mmio->msize);
PR_CloseFileMap(mmio->fileMap);
}
PR_Close(mmio->fd);
memset(mmio, 0, sizeof(*mmio)); /* Catch people who try to keep using it */
PR_Free(mmio);
return PR_SUCCESS;
}
MmioFile *mmio_FileOpen(char *path, PRIntn flags, PRIntn mode)
{
PRFileDesc *fd = PR_Open(path, flags, mode);
PRFileInfo info;
MmioFile *mmio;
if(!fd) {
return NULL;
}
mmio = PR_MALLOC(sizeof(MmioFile));
if(!mmio || PR_FAILURE==PR_GetOpenFileInfo(fd, &info)) {
PR_Close(fd);
return NULL;
}
mmio->fd = fd;
mmio->fileMap = NULL;
mmio->fsize = info.size;
mmio->msize = 0;
mmio->pos = 0;
mmio->addr = NULL;
mmio->needSeek = PR_FALSE;
return mmio;
}

View File

@ -1,47 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* James L. Nance.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* James L. Nance <jim_nance@yahoo.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "prio.h"
typedef struct MmioFileStruct MmioFile;
PRStatus mmio_FileSeek(MmioFile *file, PRInt32 offset, PRSeekWhence whence);
PRInt32 mmio_FileRead(MmioFile *file, char *dest, PRInt32 count);
PRInt32 mmio_FileWrite(MmioFile *file, const char *src, PRInt32 count);
PRInt32 mmio_FileTell(MmioFile *file);
PRStatus mmio_FileClose(MmioFile *file);
MmioFile *mmio_FileOpen(char *path, PRIntn flags, PRIntn mode);

View File

@ -137,26 +137,7 @@ typedef FILE * XP_File;
/* Alternate fileI/O function mappings */
/*-------------------------------------*/
#if USE_MMAP_REGISTRY_IO
/*-----------------------------------------------*/
/* NSPR mememory-mapped I/O (write through) */
/* unfortunately this isn't supported on the Mac */
/*-----------------------------------------------*/
#define USE_NSPR_MODES
#include "mmapio.h"
#define XP_FileSeek(file,offset,whence) mmio_FileSeek((file),(offset),(whence))
#define XP_FileRead(dest,count,file) mmio_FileRead((file), (dest), (count))
#define XP_FileWrite(src,count,file) mmio_FileWrite((file), (src), (count))
#define XP_FileTell(file) mmio_FileTell(file)
#define XP_FileClose(file) mmio_FileClose(file)
#define XP_FileOpen(path, mode) mmio_FileOpen((path), mode )
#define XP_FileFlush(file) ((void)1)
#define XP_FileSetBufferSize(file, bufsize) (-1)
typedef MmioFile* XP_File;
#elif USE_BUFFERED_REGISTRY_IO
#if USE_BUFFERED_REGISTRY_IO
/*-----------------------------------------------*/
/* home-grown XP buffering */
/* writes are buffered too so use flush! */