parent
afd3f23c1d
commit
7b75bbaa04
File diff suppressed because it is too large
Load Diff
@ -69,16 +69,6 @@ typedef int pid_t;
|
||||
#define EXV_SEPERATOR_STR "\\"
|
||||
#define EXV_SEPERATOR_CHR '\\'
|
||||
|
||||
/* Define to 1 if you have the "sys/mman.h header file (and supporting code of course) */
|
||||
/* At this time (between 0.18.1 and 0.19) this is used by TIFF files to avoid reading */
|
||||
/* the total file into memory returning in a 6x improvement in exiv2 on 2mb tiff files */
|
||||
#define EXV_HAVE_SYS_MMAN_H 1
|
||||
#ifdef EXV_HAVE_SYS_MMAN_H
|
||||
#if EXV_HAVE_SYS_MMAN_H
|
||||
#define EXV_HAVE_MMAP 1
|
||||
#define EXV_HAVE_MUNMAP 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Shared library support */
|
||||
#ifdef EXV_HAVE_DLL
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
/*
|
||||
This file is part of the KDE libraries
|
||||
Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
|
||||
|
||||
These sources are based on ftp://g.oswego.edu/pub/misc/malloc.c
|
||||
file by Doug Lea, released to the public domain.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDEWIN_SYS_MMAN_H
|
||||
#define KDEWIN_SYS_MMAN_H
|
||||
|
||||
// include everywhere
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PROT_NONE 0
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define PROT_EXEC 4
|
||||
|
||||
/* These values don't really matter in windows mmap emulation */
|
||||
#define MAP_FILE 0
|
||||
#define MAP_SHARED 1
|
||||
#define MAP_PRIVATE 2
|
||||
#define MAP_TYPE 0xF
|
||||
#define MAP_FIXED 0x10
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
#define MAP_ANON MAP_ANONYMOUS
|
||||
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
|
||||
KDEWIN32_EXPORT void *mmap(void *start, size_t length, int prot , int flags, int fd, off_t offset);
|
||||
KDEWIN32_EXPORT int munmap(void *start, size_t length);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // KDEWIN_SYS_MMAN_H
|
||||
@ -1,7 +0,0 @@
|
||||
#ifndef _sys_socket_h_
|
||||
#define _sys_socket_h_
|
||||
|
||||
// rmills
|
||||
// minimum to enable mmap.cpp to compile without change
|
||||
|
||||
#endif
|
||||
@ -1,8 +0,0 @@
|
||||
#ifndef _types_h_
|
||||
#define _types_h_
|
||||
// rmills
|
||||
// minimum required by exiv2
|
||||
//
|
||||
#include "winposix_export.h"
|
||||
#endif
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
#ifndef _WINPOSIX_EXPORT_H_
|
||||
#define _WINPOSIX_EXPORT_H_
|
||||
|
||||
// rmills
|
||||
// msvc/include/winposix_export.h
|
||||
//
|
||||
// I'm very appreciative and respectful of the work of Jaroslaw Staniek <js@iidea.pl>
|
||||
// in the KDE libraries where I found msvc/src/mmap.cpp and msvc/mman.h
|
||||
//
|
||||
// http://websvn.kde.org/trunk/KDE/kdelibs/win/include/msvc/sys/mman.h?revision=517357&view=markup&pathrev=519502
|
||||
// http://websvn.kde.org/trunk/KDE/kdelibs/win/src/mmap.c?revision=519502&view=markup&pathrev=519502
|
||||
|
||||
// I have commented 2 essential tiny changes in mmap.cpp to make it compile with MSVC
|
||||
// I've also added a dummy sys/socket.h and sys/types.h file to keep everybody happy!
|
||||
//
|
||||
// the contents of this file are the minimum required to enable exiv2 to compile link and execute the mmap.cpp code
|
||||
//
|
||||
|
||||
#ifndef ENOTSUP
|
||||
#define ENOTSUP 911
|
||||
#endif
|
||||
|
||||
#ifndef off_t
|
||||
#define off_t size_t
|
||||
#endif
|
||||
|
||||
#ifndef KDEWIN32_EXPORT
|
||||
#define KDEWIN32_EXPORT
|
||||
#endif
|
||||
|
||||
// give MSVC 7.1 (VS 2003 .Net) encouragement to ignore _set_errno !
|
||||
#if _MSC_VER < 1400
|
||||
#ifndef _set_errno
|
||||
#define _set_errno(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,196 +0,0 @@
|
||||
/*
|
||||
This file is part of the KDE libraries
|
||||
Copyright (c) 2006 Christian Ehrlicher <ch.ehrlicher@gmx.de>
|
||||
|
||||
These sources are based on ftp://g.oswego.edu/pub/misc/malloc.c
|
||||
file by Doug Lea, released to the public domain.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <winposix_export.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef SECTION_MAP_EXECUTE_EXPLICIT
|
||||
//not defined in the February 2003 version of the Platform SDK
|
||||
#define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
|
||||
#endif
|
||||
|
||||
#ifndef FILE_MAP_EXECUTE
|
||||
//not defined in the February 2003 version of the Platform SDK
|
||||
#define FILE_MAP_EXECUTE SECTION_MAP_EXECUTE_EXPLICIT
|
||||
#endif
|
||||
|
||||
#define MUNMAP_FAILURE (-1)
|
||||
|
||||
#define USE_MALLOC_LOCK 1
|
||||
|
||||
struct mmapInfos {
|
||||
HANDLE hFile; // the duplicated fd
|
||||
HANDLE hMap; // handle returned by CreateFileMapping
|
||||
void* start; // ptr returned by MapViewOfFile
|
||||
};
|
||||
|
||||
CRITICAL_SECTION cs;
|
||||
|
||||
// rmills - only change is to add long to the following 2 lines
|
||||
static long g_curMMapInfos = 0;
|
||||
static long g_maxMMapInfos = -1;
|
||||
static struct mmapInfos *g_mmapInfos = NULL;
|
||||
#define NEW_MMAP_STRUCT_CNT 10
|
||||
|
||||
static int mapProtFlags(int flags, DWORD *dwAccess)
|
||||
{
|
||||
if ( ( flags & PROT_READ ) == PROT_READ ) {
|
||||
if ( ( flags & PROT_WRITE ) == PROT_WRITE ) {
|
||||
*dwAccess = FILE_MAP_WRITE;
|
||||
if ( ( flags & PROT_EXEC ) == PROT_EXEC ) {
|
||||
return PAGE_EXECUTE_READWRITE;
|
||||
}
|
||||
return PAGE_READWRITE;
|
||||
}
|
||||
if ( ( flags & PROT_EXEC ) == PROT_EXEC ) {
|
||||
*dwAccess = FILE_MAP_EXECUTE;
|
||||
return PAGE_EXECUTE_READ;
|
||||
}
|
||||
*dwAccess = FILE_MAP_READ;
|
||||
return PAGE_READONLY;
|
||||
}
|
||||
if ( ( flags & PROT_WRITE ) == PROT_WRITE ) {
|
||||
*dwAccess = FILE_MAP_COPY;
|
||||
return PAGE_WRITECOPY;
|
||||
}
|
||||
if ( ( flags & PROT_EXEC ) == PROT_EXEC ) {
|
||||
*dwAccess = FILE_MAP_EXECUTE;
|
||||
return PAGE_EXECUTE_READ;
|
||||
}
|
||||
*dwAccess = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *mmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
|
||||
{
|
||||
struct mmapInfos mmi;
|
||||
DWORD dwAccess;
|
||||
DWORD flProtect;
|
||||
HANDLE hfd;
|
||||
|
||||
if ( g_maxMMapInfos == -1 ) {
|
||||
g_maxMMapInfos = 0;
|
||||
InitializeCriticalSection( &cs );
|
||||
}
|
||||
|
||||
flProtect = mapProtFlags( flags, &dwAccess );
|
||||
if ( flProtect == 0 ) {
|
||||
_set_errno( EINVAL );
|
||||
return MAP_FAILED;
|
||||
}
|
||||
// we don't support this atm
|
||||
if ( prot == MAP_FIXED ) {
|
||||
_set_errno( ENOTSUP );
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
if ( fd == -1 ) {
|
||||
_set_errno( EBADF );
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
hfd = (HANDLE)_get_osfhandle( fd );
|
||||
if ( hfd == INVALID_HANDLE_VALUE )
|
||||
return MAP_FAILED;
|
||||
|
||||
if ( !DuplicateHandle( GetCurrentProcess(), hfd, GetCurrentProcess(),
|
||||
&mmi.hFile, 0, FALSE, DUPLICATE_SAME_ACCESS ) ) {
|
||||
#ifdef _DEBUG
|
||||
DWORD dwLastErr = GetLastError();
|
||||
#endif
|
||||
return MAP_FAILED;
|
||||
}
|
||||
mmi.hMap = CreateFileMapping( mmi.hFile, NULL, flProtect,
|
||||
0, length, NULL );
|
||||
if ( mmi.hMap == 0 ) {
|
||||
_set_errno( EACCES );
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
mmi.start = MapViewOfFile( mmi.hMap, dwAccess, 0, offset, 0 );
|
||||
if ( mmi.start == 0 ) {
|
||||
DWORD dwLastErr = GetLastError();
|
||||
if ( dwLastErr == ERROR_MAPPED_ALIGNMENT )
|
||||
_set_errno( EINVAL );
|
||||
else
|
||||
_set_errno( EACCES );
|
||||
return MAP_FAILED;
|
||||
}
|
||||
EnterCriticalSection( &cs );
|
||||
if ( g_mmapInfos == NULL ) {
|
||||
g_maxMMapInfos = NEW_MMAP_STRUCT_CNT;
|
||||
g_mmapInfos = ( struct mmapInfos* )calloc( g_maxMMapInfos,
|
||||
sizeof( struct mmapInfos ) );
|
||||
}
|
||||
if( g_curMMapInfos == g_maxMMapInfos) {
|
||||
g_maxMMapInfos += NEW_MMAP_STRUCT_CNT;
|
||||
g_mmapInfos = ( struct mmapInfos* )realloc( g_mmapInfos,
|
||||
g_maxMMapInfos * sizeof( struct mmapInfos ) );
|
||||
}
|
||||
memcpy( &g_mmapInfos[g_curMMapInfos], &mmi, sizeof( struct mmapInfos) );
|
||||
g_curMMapInfos++;
|
||||
|
||||
LeaveCriticalSection( &cs );
|
||||
|
||||
return mmi.start;
|
||||
}
|
||||
|
||||
int munmap(void *start, size_t length)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for( i = 0; i < g_curMMapInfos; i++ ) {
|
||||
if( g_mmapInfos[i].start == start )
|
||||
break;
|
||||
}
|
||||
if( i == g_curMMapInfos ) {
|
||||
_set_errno( EINVAL );
|
||||
return -1;
|
||||
}
|
||||
|
||||
UnmapViewOfFile( g_mmapInfos[i].start );
|
||||
CloseHandle( g_mmapInfos[i].hMap );
|
||||
CloseHandle( g_mmapInfos[i].hFile );
|
||||
|
||||
EnterCriticalSection( &cs );
|
||||
for( j = i + 1; j < g_curMMapInfos; j++ ) {
|
||||
memcpy( &g_mmapInfos[ j - 1 ], &g_mmapInfos[ j ],
|
||||
sizeof( struct mmapInfos ) );
|
||||
}
|
||||
g_curMMapInfos--;
|
||||
|
||||
if( g_curMMapInfos == 0 ) {
|
||||
free( g_mmapInfos );
|
||||
g_mmapInfos = NULL;
|
||||
g_maxMMapInfos = 0;
|
||||
}
|
||||
LeaveCriticalSection( &cs );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -77,6 +77,7 @@ namespace Exiv2 {
|
||||
|
||||
FileIo::~FileIo()
|
||||
{
|
||||
munmap();
|
||||
close();
|
||||
}
|
||||
|
||||
@ -367,7 +368,9 @@ namespace Exiv2 {
|
||||
|
||||
int FileIo::open(const std::string& mode)
|
||||
{
|
||||
close();
|
||||
if (fp_ != 0) {
|
||||
std::fclose(fp_);
|
||||
}
|
||||
|
||||
openMode_ = mode;
|
||||
opMode_ = opSeek;
|
||||
@ -383,7 +386,6 @@ namespace Exiv2 {
|
||||
|
||||
int FileIo::close()
|
||||
{
|
||||
munmap();
|
||||
if (fp_ != 0) {
|
||||
std::fclose(fp_);
|
||||
fp_= 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user