% March 2000 %
% %
% %
-% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
#include "MagickCore/memory-private.h"
#include "MagickCore/pixel.h"
#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/policy.h"
#include "MagickCore/quantum.h"
#include "MagickCore/quantum-private.h"
#include "MagickCore/semaphore.h"
}
#endif
\f
+static ssize_t
+ cache_anonymous_memory = (-1);
+\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
StreamInfo
*stream_info;
- stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
- if (stream_info == (StreamInfo *) NULL)
- ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
- (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
+ stream_info=(StreamInfo *) AcquireCriticalMemory(sizeof(*stream_info));
+ (void) memset(stream_info,0,sizeof(*stream_info));
stream_info->pixels=(unsigned char *) MagickAssumeAligned(
AcquireAlignedMemory(1,sizeof(*stream_info->pixels)));
if (stream_info->pixels == (unsigned char *) NULL)
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel = GetPixelChannelChannel(image,i);
pixel[channel]=p[i];
}
return(MagickTrue);
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel = GetPixelChannelChannel(image,i);
pixel[channel]=p[i];
}
return(MagickTrue);
% %
% %
% %
-+ G e t V i r t u a l P i x e l s F r o m S t r e a m %
++ G e t V i r t u a l P i x e l s F r o m S t r e a m %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% GetVirtualPixelsStream() returns the pixels associated with the last
-% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
+% GetVirtualPixelsStream() returns the pixels associated with the last call to
+% QueueAuthenticPixelsStream() or GetVirtualPixelStream().
%
% The format of the GetVirtualPixelsStream() method is:
%
{
if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
return(MagickFalse);
- cache_info->mapped=MagickFalse;
- cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,(size_t)
- cache_info->length);
- if (cache_info->pixels == (Quantum *) NULL)
+ if (cache_anonymous_memory < 0)
{
- cache_info->mapped=MagickTrue;
- cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
- cache_info->length);
+ char
+ *value;
+
+ /*
+ Does the security policy require anonymous mapping for pixel cache?
+ */
+ cache_anonymous_memory=0;
+ value=GetPolicyValue("pixel-cache-memory");
+ if (value == (char *) NULL)
+ value=GetPolicyValue("cache:memory-map");
+ if (LocaleCompare(value,"anonymous") == 0)
+ {
+#if defined(MAGICKCORE_HAVE_MMAP) && defined(MAP_ANONYMOUS)
+ cache_anonymous_memory=1;
+#else
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ MissingDelegateError,"DelegateLibrarySupportNotBuiltIn",
+ "'%s' (policy requires anonymous memory mapping)",
+ cache_info->filename);
+#endif
+ }
+ value=DestroyString(value);
}
+ if (cache_anonymous_memory <= 0)
+ {
+ cache_info->mapped=MagickFalse;
+ cache_info->pixels=(Quantum *) MagickAssumeAligned(
+ AcquireAlignedMemory(1,(size_t) cache_info->length));
+ }
+ else
+ {
+ cache_info->mapped=MagickTrue;
+ cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
+ cache_info->length);
+ }
if (cache_info->pixels == (Quantum *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
number_pixels=(MagickSizeType) columns*rows;
length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
if (cache_info->number_channels == 0)
- length=number_pixels*sizeof(Quantum);
+ length=(size_t) number_pixels*sizeof(Quantum);
if (cache_info->metacontent_extent != 0)
length+=number_pixels*cache_info->metacontent_extent;
if (cache_info->pixels == (Quantum *) NULL)
number_pixels=(MagickSizeType) columns*rows;
length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
if (cache_info->number_channels == 0)
- length=number_pixels*sizeof(Quantum);
+ length=(size_t) number_pixels*sizeof(Quantum);
if (cache_info->metacontent_extent != 0)
length+=number_pixels*cache_info->metacontent_extent;
if (cache_info->pixels == (Quantum *) NULL)
read_info->stream=stream;
image=ReadImage(read_info,exception);
if (image != (Image *) NULL)
- (void) SyncImagePixelCache(image,exception);
+ {
+ InitializePixelChannelMap(image);
+ ResetPixelCacheChannels(image);
+ }
read_info=DestroyImageInfo(read_info);
return(image);
}
% %
% %
% %
++ R e s e t S t r e a m A n o n y m o u s M e m o r y %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ResetStreamAnonymousMemory() resets the anonymous_memory value.
+%
+% The format of the ResetStreamAnonymousMemory method is:
+%
+% void ResetStreamAnonymousMemory(void)
+%
+*/
+MagickPrivate void ResetStreamAnonymousMemory(void)
+{
+ cache_anonymous_memory=0;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ S e t S t r e a m I n f o C l i e n t D a t a %
% %
% %
stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
if (stream_info->pixels == (unsigned char *) NULL)
return(0);
- (void) ResetMagickMemory(stream_info->pixels,0,length);
+ (void) memset(stream_info->pixels,0,length);
stream_info->image=image;
write_info=CloneImageInfo(stream_info->image_info);
(void) SetImageInfo(write_info,1,stream_info->exception);
read_info=CloneImageInfo(image_info);
stream_info->image_info=image_info;
stream_info->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL);
+ if (stream_info->quantum_info == (QuantumInfo *) NULL)
+ {
+ read_info=DestroyImageInfo(read_info);
+ return((Image *) NULL);
+ }
stream_info->exception=exception;
read_info->client_data=(void *) stream_info;
image=ReadStream(read_info,&WriteStreamImage,exception);
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return(MagickFalse);
}
+ (void) memset(quantum_map,0,length*sizeof(*quantum_map));
for (i=0; i < (ssize_t) length; i++)
{
switch (stream_info->map[i])