"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libvips/iofuncs/mapfile.c" between
vips-8.10.6.tar.gz and vips-8.11.0.tar.gz

About: VIPS is a free image processing system (see also the GUI nip2).

mapfile.c  (vips-8.10.6):mapfile.c  (vips-8.11.0)
skipping to change at line 80 skipping to change at line 80
#ifdef HAVE_SYS_MMAN_H #ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h> #include <sys/mman.h>
#endif /*HAVE_SYS_MMAN_H*/ #endif /*HAVE_SYS_MMAN_H*/
#ifdef HAVE_SYS_FILE_H #ifdef HAVE_SYS_FILE_H
#include <sys/file.h> #include <sys/file.h>
#endif /*HAVE_SYS_FILE_H*/ #endif /*HAVE_SYS_FILE_H*/
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif /*HAVE_UNISTD_H*/ #endif /*HAVE_UNISTD_H*/
#ifdef OS_WIN32
#ifndef S_ISREG
#define S_ISREG(m) (!!(m & _S_IFREG))
#endif
#endif /*OS_WIN32*/
#include <vips/vips.h> #include <vips/vips.h>
#ifdef OS_WIN32 #ifdef G_OS_WIN32
#ifndef S_ISREG
#define S_ISREG(m) (!!(m & _S_IFREG))
#endif
#include <windows.h> #include <windows.h>
#include <io.h> #include <io.h>
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
/* Does this fd support mmap. Pipes won't, for example. /* Does this fd support mmap. Pipes won't, for example.
*/ */
gboolean gboolean
vips__mmap_supported( int fd ) vips__mmap_supported( int fd )
{ {
void *baseaddr; void *baseaddr;
size_t length = 4096; size_t length = 4096;
off_t offset = 0; off_t offset = 0;
#ifdef OS_WIN32 #ifdef G_OS_WIN32
{ {
HANDLE hFile = (HANDLE) _get_osfhandle( fd ); HANDLE hFile = (HANDLE) _get_osfhandle( fd );
DWORD flProtect; DWORD flProtect;
HANDLE hMMFile; HANDLE hMMFile;
DWORD dwDesiredAccess; DWORD dwDesiredAccess;
ULARGE_INTEGER quad; ULARGE_INTEGER quad;
DWORD dwFileOffsetHigh; DWORD dwFileOffsetHigh;
DWORD dwFileOffsetLow; DWORD dwFileOffsetLow;
skipping to change at line 131 skipping to change at line 129
dwFileOffsetLow = quad.LowPart; dwFileOffsetLow = quad.LowPart;
dwFileOffsetHigh = quad.HighPart; dwFileOffsetHigh = quad.HighPart;
if( !(baseaddr = (char *)MapViewOfFile( hMMFile, dwDesiredAccess, if( !(baseaddr = (char *)MapViewOfFile( hMMFile, dwDesiredAccess,
dwFileOffsetHigh, dwFileOffsetLow, length )) ) { dwFileOffsetHigh, dwFileOffsetLow, length )) ) {
CloseHandle( hMMFile ); CloseHandle( hMMFile );
return( FALSE ); return( FALSE );
} }
CloseHandle( hMMFile ); CloseHandle( hMMFile );
UnmapViewOfFile( baseaddr ); UnmapViewOfFile( baseaddr );
} }
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
{ {
int prot = PROT_READ; int prot = PROT_READ;
int flags = MAP_SHARED; int flags = MAP_SHARED;
baseaddr = mmap( 0, length, prot, flags, fd, (off_t) offset ); baseaddr = mmap( 0, length, prot, flags, fd, (off_t) offset );
if( baseaddr == MAP_FAILED ) if( baseaddr == MAP_FAILED )
return( FALSE ); return( FALSE );
munmap( baseaddr, length ); munmap( baseaddr, length );
} }
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
return( TRUE ); return( TRUE );
} }
void * void *
vips__mmap( int fd, int writeable, size_t length, gint64 offset ) vips__mmap( int fd, int writeable, size_t length, gint64 offset )
{ {
void *baseaddr; void *baseaddr;
#ifdef DEBUG #ifdef DEBUG
printf( "vips__mmap: length = 0x%zx, offset = 0x%lx\n", printf( "vips__mmap: length = 0x%zx, offset = 0x%lx\n",
length, offset ); length, offset );
#endif /*DEBUG*/ #endif /*DEBUG*/
#ifdef OS_WIN32 #ifdef G_OS_WIN32
{ {
HANDLE hFile = (HANDLE) _get_osfhandle( fd ); HANDLE hFile = (HANDLE) _get_osfhandle( fd );
DWORD flProtect; DWORD flProtect;
DWORD dwDesiredAccess; DWORD dwDesiredAccess;
HANDLE hMMFile; HANDLE hMMFile;
ULARGE_INTEGER quad; ULARGE_INTEGER quad;
DWORD dwFileOffsetHigh; DWORD dwFileOffsetHigh;
skipping to change at line 206 skipping to change at line 204
return( NULL ); return( NULL );
} }
/* Can close mapping now ... view stays until UnmapViewOfFile(). /* Can close mapping now ... view stays until UnmapViewOfFile().
FIXME ... is this a performance problem? FIXME ... is this a performance problem?
*/ */
CloseHandle( hMMFile ); CloseHandle( hMMFile );
} }
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
{ {
int prot; int prot;
int flags; int flags;
if( writeable ) if( writeable )
prot = PROT_WRITE; prot = PROT_WRITE;
else else
prot = PROT_READ; prot = PROT_READ;
flags = MAP_SHARED; flags = MAP_SHARED;
skipping to change at line 240 skipping to change at line 238
baseaddr = mmap( 0, length, prot, flags, fd, (off_t) offset ); baseaddr = mmap( 0, length, prot, flags, fd, (off_t) offset );
if( baseaddr == MAP_FAILED ) { if( baseaddr == MAP_FAILED ) {
vips_error_system( errno, "vips_mapfile", vips_error_system( errno, "vips_mapfile",
"%s", _( "unable to mmap" ) ); "%s", _( "unable to mmap" ) );
g_warning( _( "map failed (%s), " g_warning( _( "map failed (%s), "
"running very low on system resources, " "running very low on system resources, "
"expect a crash soon" ), strerror( errno ) ); "expect a crash soon" ), strerror( errno ) );
return( NULL ); return( NULL );
} }
} }
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
return( baseaddr ); return( baseaddr );
} }
int int
vips__munmap( const void *start, size_t length ) vips__munmap( const void *start, size_t length )
{ {
#ifdef OS_WIN32 #ifdef G_OS_WIN32
if( !UnmapViewOfFile( (void *) start ) ) { if( !UnmapViewOfFile( (void *) start ) ) {
vips_error_system( GetLastError(), "vips_mapfile", vips_error_system( GetLastError(), "vips_mapfile",
"%s", _( "unable to UnmapViewOfFile" ) ); "%s", _( "unable to UnmapViewOfFile" ) );
return( -1 ); return( -1 );
} }
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
if( munmap( (void *) start, length ) < 0 ) { if( munmap( (void *) start, length ) < 0 ) {
vips_error_system( errno, "vips_mapfile", vips_error_system( errno, "vips_mapfile",
"%s", _( "unable to munmap file" ) ); "%s", _( "unable to munmap file" ) );
return( -1 ); return( -1 );
} }
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
return( 0 ); return( 0 );
} }
int int
vips_mapfile( VipsImage *im ) vips_mapfile( VipsImage *im )
{ {
struct stat st; struct stat st;
mode_t m; mode_t m;
skipping to change at line 348 skipping to change at line 346
*/ */
int int
vips_remapfilerw( VipsImage *image ) vips_remapfilerw( VipsImage *image )
{ {
void *baseaddr; void *baseaddr;
#ifdef DEBUG #ifdef DEBUG
printf( "vips_remapfilerw:\n" ); printf( "vips_remapfilerw:\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
#ifdef OS_WIN32 #ifdef G_OS_WIN32
{ {
HANDLE hFile = (HANDLE) _get_osfhandle( image->fd ); HANDLE hFile = (HANDLE) _get_osfhandle( image->fd );
HANDLE hMMFile; HANDLE hMMFile;
if( !(hMMFile = CreateFileMapping( hFile, if( !(hMMFile = CreateFileMapping( hFile,
NULL, PAGE_READWRITE, 0, 0, NULL )) ) { NULL, PAGE_READWRITE, 0, 0, NULL )) ) {
vips_error_system( GetLastError(), "vips_mapfile", vips_error_system( GetLastError(), "vips_mapfile",
"%s", _( "unable to CreateFileMapping" ) ); "%s", _( "unable to CreateFileMapping" ) );
return( -1 ); return( -1 );
} }
skipping to change at line 380 skipping to change at line 378
return( -1 ); return( -1 );
} }
/* Can close mapping now ... view stays until UnmapViewOfFile(). /* Can close mapping now ... view stays until UnmapViewOfFile().
FIXME ... is this a performance problem? FIXME ... is this a performance problem?
*/ */
CloseHandle( hMMFile ); CloseHandle( hMMFile );
} }
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
{ {
assert( image->dtype == VIPS_IMAGE_MMAPIN ); assert( image->dtype == VIPS_IMAGE_MMAPIN );
baseaddr = mmap( image->baseaddr, image->length, baseaddr = mmap( image->baseaddr, image->length,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
image->fd, 0 ); image->fd, 0 );
if( baseaddr == (void *)-1 ) { if( baseaddr == (void *)-1 ) {
vips_error( "vips_mapfile", _( "unable to mmap: \"%s\" - %s" ), vips_error( "vips_mapfile", _( "unable to mmap: \"%s\" - %s" ),
image->filename, strerror( errno ) ); image->filename, strerror( errno ) );
return( -1 ); return( -1 );
} }
} }
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
image->dtype = VIPS_IMAGE_MMAPINRW; image->dtype = VIPS_IMAGE_MMAPINRW;
if( baseaddr != image->baseaddr ) { if( baseaddr != image->baseaddr ) {
vips_error( "vips_mapfile", _( "unable to mmap \"%s\" to same " vips_error( "vips_mapfile", _( "unable to mmap \"%s\" to same "
"address" ), image->filename ); "address" ), image->filename );
image->baseaddr = baseaddr; image->baseaddr = baseaddr;
return( -1 ); return( -1 );
} }
 End of changes. 15 change blocks. 
19 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)