mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Added mmapio patch from jim_nance@yahoo.com (James L. Nance) to speed
registry-read. Enabled on XP_UNIX only.
This commit is contained in:
parent
52e5ad25fd
commit
b749ab2168
@ -27,7 +27,7 @@ LIBRARY_NAME = mozreg_s
|
||||
|
||||
REQUIRES = libreg pref js
|
||||
|
||||
CSRCS = reg.c VerReg.c vr_stubs.c
|
||||
CSRCS = reg.c VerReg.c vr_stubs.c mmapio.c
|
||||
|
||||
BIN_SRCS = VerReg.c reg.c vr_stubs.c
|
||||
BIN_OBJS = $(addprefix R_,$(BIN_SRCS:.c=.o))
|
||||
|
177
modules/libreg/src/mmapio.c
Normal file
177
modules/libreg/src/mmapio.c
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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 James L. Nance are Copyright (C) 1999, James
|
||||
* L. Nance. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): James L. Nance <jim_nance@yahoo.com>
|
||||
*/
|
||||
#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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
mmio->fileMap = PR_CreateFileMap(mmio->fd, mmio->fsize, prot);
|
||||
|
||||
if(!mmio->fileMap) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mmio->addr = PR_MemMap(mmio->fileMap, 0, mmio->fsize);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
30
modules/libreg/src/mmapio.h
Normal file
30
modules/libreg/src/mmapio.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 James L. Nance are Copyright (C) 1999, James
|
||||
* L. Nance. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): James L. Nance <jim_nance@yahoo.com>
|
||||
*/
|
||||
|
||||
#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);
|
@ -379,7 +379,7 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh)
|
||||
PR_ASSERT( fh != NULL );
|
||||
|
||||
/* Open the file for exclusive random read/write */
|
||||
(*fh) = PR_Open(path, PR_RDWR|PR_CREATE_FILE, 00644);
|
||||
(*fh) = XP_FileOpen(path, PR_RDWR|PR_CREATE_FILE, 00644);
|
||||
if ( !VALID_FILEHANDLE(*fh) )
|
||||
{
|
||||
switch (PR_GetError())
|
||||
@ -392,7 +392,7 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh)
|
||||
case PR_ILLEGAL_ACCESS_ERROR:
|
||||
case PR_NO_ACCESS_RIGHTS_ERROR:
|
||||
/* DVNOTE: should we try read only? */
|
||||
(*fh) = PR_Open(path, PR_RDONLY, 00644);
|
||||
(*fh) = XP_FileOpen(path, PR_RDONLY, 00644);
|
||||
if ( VALID_FILEHANDLE(*fh) )
|
||||
return REGERR_READONLY;
|
||||
else
|
||||
|
@ -152,6 +152,27 @@ typedef FILE * XP_File;
|
||||
#define SEEK_CUR PR_SEEK_CUR
|
||||
#define SEEK_END PR_SEEK_END
|
||||
#endif
|
||||
|
||||
#if defined(XP_UNIX)
|
||||
#define USE_MMAP_REGISTRY_IO 1
|
||||
#else
|
||||
#define USE_MMAP_REGISTRY_IO 0
|
||||
#endif
|
||||
|
||||
#if USE_MMAP_REGISTRY_IO
|
||||
|
||||
#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, flags, mode) mmio_FileOpen((path), (flags), (mode))
|
||||
#define XP_FileFlush(file) ((void)1)
|
||||
|
||||
typedef MmioFile* XP_File;
|
||||
|
||||
#else /*USE_MMAP_REGISTRY_IO*/
|
||||
/*
|
||||
** Note that PR_Seek returns the offset (if successful) and -1 otherwise. So
|
||||
** to make this code work
|
||||
@ -163,11 +184,17 @@ typedef FILE * XP_File;
|
||||
#define XP_FileWrite(src,count,file) PR_Write((file), (src), (count))
|
||||
#define XP_FileTell(file) PR_Seek(file, 0, PR_SEEK_CUR)
|
||||
#define XP_FileClose(file) PR_Close(file)
|
||||
#define XP_FileOpen(path, flags, mode) PR_Open((path), (flags), (mode))
|
||||
#ifdef XP_MAC
|
||||
#define XP_FileFlush(file) PR_Sync(file)
|
||||
#else
|
||||
#define XP_FileFlush(file) ((void)1)
|
||||
#endif
|
||||
|
||||
typedef PRFileDesc* XP_File;
|
||||
|
||||
#endif /*USE_MMAP_REGISTRY_IO*/
|
||||
|
||||
#define XP_ASSERT(x) PR_ASSERT((x))
|
||||
|
||||
#define XP_STRCAT(a,b) PL_strcat((a),(b))
|
||||
@ -187,7 +214,6 @@ typedef FILE * XP_File;
|
||||
#define XP_STRCASECMP(x,y) PL_strcasecmp((x),(y))
|
||||
#define XP_STRNCASECMP(x,y,n) PL_strncasecmp((x),(y),(n))
|
||||
|
||||
typedef PRFileDesc* XP_File;
|
||||
|
||||
#endif /*STANDALONE_REGISTRY*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user