ClonePixelCacheMethods(Cache,const Cache),
GetPixelCacheTileSize(const Image *,size_t *,size_t *),
GetPixelCacheMethods(CacheMethods *),
+ ResetCacheAnonymousMemory(void),
ResetPixelCacheEpoch(void),
ResetPixelCacheChannels(Image *),
SetPixelCacheMethods(Cache,CacheMethods *);
% %
% %
% %
++ R e s e t C a c h e A n o n y m o u s M e m o r y %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ResetCacheAnonymousMemory() resets the anonymous_memory value.
+%
+% The format of the ResetCacheAnonymousMemory method is:
+%
+% void ResetCacheAnonymousMemory(void)
+%
+*/
+MagickPrivate void ResetCacheAnonymousMemory(void)
+{
+ cache_anonymous_memory=0;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ R e s e t P i x e l C a c h e E p o c h %
% %
% %
MagickComponentGenesis(void);
extern MagickPrivate void
- MagickComponentTerminus(void);
+ MagickComponentTerminus(void),
+ ResetMagickPrecision(void);
#if defined(__cplusplus) || defined(c_plusplus)
}
instantiate_magickcore = MagickFalse,
magickcore_signal_in_progress = MagickFalse,
magick_list_initialized = MagickFalse;
+
+static int
+ magick_precision = 0;
\f
/*
Forward declarations.
% %
% %
% %
++ R e s e t M a g i c k P r e c i s i o n %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ResetMagickPrecision() resets the magick_precision value.
+%
+% The format of the ResetMagickPrecision method is:
+%
+% void ResetMagickPrecision(void)
+%
+*/
+MagickPrivate void ResetMagickPrecision(void)
+{
+ magick_precision=0;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% S e t M a g i c k P r e c i s i o n %
% %
% %
{
#define MagickPrecision 6
- static int
- magick_precision = 0;
-
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
if (precision > 0)
magick_precision=precision;
MagickExport MagickBooleanType
HeapOverflowSanityCheck(const size_t,const size_t) magick_alloc_sizes(1,2);
+extern MagickPrivate void
+ ResetMaxMemoryRequest(void),
+ ResetVirtualAnonymousMemory(void);
+
static inline void *AcquireCriticalMemory(const size_t size)
{
register void
/*
Global declarations.
*/
+static size_t
+ max_memory_request = 0,
+ virtual_anonymous_memory = 0;
+
#if defined _MSC_VER
static void* MSCMalloc(size_t size)
{
%
*/
-static inline size_t StringToSizeType(const char *string,const double interval)
-{
- double
- value;
-
- value=SiPrefixToDoubleInterval(string,interval);
- if (value >= (double) MagickULLConstant(~0))
- return((size_t) MagickULLConstant(~0));
- return((size_t) value);
-}
-
MagickExport MemoryInfo *AcquireVirtualMemory(const size_t count,
const size_t quantum)
{
size_t
extent;
- static size_t
- max_memory_request = 0,
- virtual_anonymous_memory = 0;
-
if (HeapOverflowSanityCheck(count,quantum) != MagickFalse)
return((MemoryInfo *) NULL);
if (max_memory_request == 0)
% %
% %
% %
++ R e s e t M a x M e m o r y R e q u e s t %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ResetMaxMemoryRequest() resets the anonymous_memory value.
+%
+% The format of the ResetMaxMemoryRequest method is:
+%
+% void ResetMaxMemoryRequest(void)
+%
+*/
+MagickPrivate void ResetMaxMemoryRequest(void)
+{
+ max_memory_request=0;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ R e s e t V i r t u a l A n o n y m o u s M e m o r y %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ResetVirtualAnonymousMemory() resets the anonymous_memory value.
+%
+% The format of the ResetVirtualAnonymousMemory method is:
+%
+% void ResetVirtualAnonymousMemory(void)
+%
+*/
+MagickPrivate void ResetVirtualAnonymousMemory(void)
+{
+ virtual_anonymous_memory=0;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% R e s i z e M a g i c k M e m o r y %
% %
% %
Include declarations.
*/
#include "MagickCore/studio.h"
+#include "MagickCore/cache-private.h"
#include "MagickCore/client.h"
#include "MagickCore/configure.h"
#include "MagickCore/configure-private.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
+#include "MagickCore/magick-private.h"
#include "MagickCore/memory_.h"
#include "MagickCore/memory-private.h"
#include "MagickCore/monitor.h"
#include "MagickCore/option.h"
#include "MagickCore/policy.h"
#include "MagickCore/policy-private.h"
+#include "MagickCore/resource_.h"
#include "MagickCore/resource-private.h"
#include "MagickCore/semaphore.h"
+#include "MagickCore/stream-private.h"
#include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
#include "MagickCore/token.h"
#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
%
% A description of each parameter follows:
%
-% o policy_info: The policy info.
+% o name: The name of the policy.
%
*/
MagickExport char *GetPolicyValue(const char *name)
return(MagickFalse);
return(ResourceComponentGenesis());
}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% S e t M a g i c k S e c u r i t y P o l i c y V a l u e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetMagickSecurityPolicyValue() sets the a value in the ImageMagick security
+% policy. It returns MagickFalse if the policy cannot be changed or if the
+% policy does not parse.
+%
+% The format of the SetMagickSecurityPolicyValue method is:
+%
+% MagickBooleanType SetMagickSecurityPolicyValue(
+% const PolicyDomain domain,const char *name,const char *value,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o domain: the domain of the policy (e.g. system, resource).
+%
+% o name: the name of the policy.
+%
+% o value: the value to set the policy to.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+
+static MagickBooleanType SetPolicyValue(const PolicyDomain domain,
+ const char *name,const char *value)
+{
+ MagickBooleanType
+ status;
+
+ register PolicyInfo
+ *p;
+
+ register char
+ *q;
+
+ status=MagickTrue;
+ LockSemaphoreInfo(policy_semaphore);
+ ResetLinkedListIterator(policy_cache);
+ p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
+ while (p != (PolicyInfo *) NULL)
+ {
+ if ((p->domain == domain) && (LocaleCompare(name,p->name) == 0))
+ break;
+ p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
+ }
+ if (p != (PolicyInfo *) NULL)
+ {
+ if (p->value != (char *) NULL)
+ p->value=DestroyString(p->value);
+ }
+ else
+ {
+ p=(PolicyInfo *) AcquireCriticalMemory(sizeof(*p));
+ (void) ResetMagickMemory(p,0,sizeof(*p));
+ p->exempt=MagickFalse;
+ p->signature=MagickCoreSignature;
+ p->name=ConstantString(name);
+ status=AppendValueToLinkedList(policy_cache,p);
+ }
+ p->value=ConstantString(value);
+ UnlockSemaphoreInfo(policy_semaphore);
+ if (status == MagickFalse)
+ p=(PolicyInfo *) RelinquishMagickMemory(p);
+ return(status);
+}
+
+MagickExport MagickBooleanType SetMagickSecurityPolicyValue(
+ const PolicyDomain domain,const char *name,const char *value,
+ ExceptionInfo *exception)
+{
+ char
+ *current_value;
+
+ magick_unreferenced(exception);
+ assert(exception != (ExceptionInfo *) NULL);
+ if ((name == (const char *) NULL) || (value == (const char *) NULL))
+ return(MagickFalse);
+ switch(domain)
+ {
+ case CachePolicyDomain:
+ {
+ if (LocaleCompare(name,"synchronize") == 0)
+ return(SetPolicyValue(domain,name,value));
+ if (LocaleCompare(name,"memory-map") == 0)
+ {
+ if (LocaleCompare(value,"anonymous") != 0)
+ return(MagickFalse);
+ ResetCacheAnonymousMemory();
+ ResetStreamAnonymousMemory();
+ return(SetPolicyValue(domain,name,value));
+ }
+ }
+ case SystemPolicyDomain:
+ {
+ if (LocaleCompare(name,"precision") == 0)
+ {
+ ResetMagickPrecision();
+ return(SetPolicyValue(domain,name,value));
+ }
+ if (LocaleCompare(name,"shred") == 0)
+ {
+ current_value=GetPolicyValue("system:shred");
+ if ((current_value == (char *) NULL) ||
+ (StringToInteger(value) > StringToInteger(current_value)))
+ return(SetPolicyValue(domain,name,value));
+ }
+ else if (LocaleCompare(name,"memory-map") == 0)
+ {
+ if (LocaleCompare(value,"anonymous") != 0)
+ return(MagickFalse);
+ ResetVirtualAnonymousMemory();
+ return(SetPolicyValue(domain,name,value));
+ }
+ else if (LocaleCompare(name,"max-memory-request") == 0)
+ {
+ current_value=GetPolicyValue("system:max-memory-request");
+ if ((current_value == (char *) NULL) ||
+ (StringToSizeType(value,100.0) < StringToSizeType(
+ current_value,100.0)))
+ {
+ ResetMaxMemoryRequest();
+ return(SetPolicyValue(domain,name,value));
+ }
+ }
+ }
+ case ResourcePolicyDomain:
+ {
+ if (LocaleCompare(name,"temporary-path") == 0)
+ return(SetPolicyValue(domain,name,value));
+ else
+ {
+ MagickSizeType
+ limit;
+
+ ResourceType
+ type;
+
+ type=(ResourceType) ParseCommandOption(MagickResourceOptions,
+ MagickFalse,value);
+ limit=MagickResourceInfinity;
+ if (LocaleCompare("unlimited",value) != 0)
+ limit=StringToMagickSizeType(value,100.0);
+ return(SetMagickResourceLimit(type,limit));
+ }
+ }
+ default:
+ case CoderPolicyDomain:
+ case DelegatePolicyDomain:
+ case FilterPolicyDomain:
+ case PathPolicyDomain:
+ break;
+ }
+ return(MagickFalse);
+}
extern MagickExport MagickBooleanType
IsRightsAuthorized(const PolicyDomain,const PolicyRights,const char *),
ListPolicyInfo(FILE *,ExceptionInfo *),
- SetMagickSecurityPolicy(const char *,ExceptionInfo *);
+ SetMagickSecurityPolicy(const char *,ExceptionInfo *),
+ SetMagickSecurityPolicyValue(const PolicyDomain,const char *,const char *,
+ ExceptionInfo *);
#if defined(__cplusplus) || defined(c_plusplus)
}
%
*/
-static inline MagickSizeType StringToSizeType(const char *string,
- const double interval)
-{
- double
- value;
-
- value=SiPrefixToDoubleInterval(string,interval);
- if (value >= (double) MagickULLConstant(~0))
- return(MagickULLConstant(~0));
- return((MagickSizeType) value);
-}
-
MagickPrivate MagickBooleanType ResourceComponentGenesis(void)
{
char
limit=GetEnvironmentValue("MAGICK_WIDTH_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(WidthResource,StringToSizeType(limit,
+ (void) SetMagickResourceLimit(WidthResource,StringToMagickSizeType(limit,
100.0));
limit=DestroyString(limit);
}
limit=GetEnvironmentValue("MAGICK_HEIGHT_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(HeightResource,StringToSizeType(limit,
- 100.0));
+ (void) SetMagickResourceLimit(HeightResource,StringToMagickSizeType(
+ limit,100.0));
limit=DestroyString(limit);
}
pagesize=GetMagickPageSize();
limit=GetEnvironmentValue("MAGICK_AREA_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(AreaResource,StringToSizeType(limit,100.0));
+ (void) SetMagickResourceLimit(AreaResource,StringToMagickSizeType(limit,
+ 100.0));
limit=DestroyString(limit);
}
(void) SetMagickResourceLimit(MemoryResource,memory);
limit=GetEnvironmentValue("MAGICK_MEMORY_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(MemoryResource,
- StringToSizeType(limit,100.0));
+ (void) SetMagickResourceLimit(MemoryResource,StringToMagickSizeType(
+ limit,100.0));
limit=DestroyString(limit);
}
(void) SetMagickResourceLimit(MapResource,2*memory);
limit=GetEnvironmentValue("MAGICK_MAP_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(MapResource,StringToSizeType(limit,100.0));
+ (void) SetMagickResourceLimit(MapResource,StringToMagickSizeType(limit,
+ 100.0));
limit=DestroyString(limit);
}
(void) SetMagickResourceLimit(DiskResource,MagickResourceInfinity);
limit=GetEnvironmentValue("MAGICK_DISK_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(DiskResource,StringToSizeType(limit,100.0));
+ (void) SetMagickResourceLimit(DiskResource,StringToMagickSizeType(limit,
+ 100.0));
limit=DestroyString(limit);
}
files=(-1);
limit=GetEnvironmentValue("MAGICK_FILE_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(FileResource,StringToSizeType(limit,
+ (void) SetMagickResourceLimit(FileResource,StringToMagickSizeType(limit,
100.0));
limit=DestroyString(limit);
}
limit=GetEnvironmentValue("MAGICK_THREAD_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(ThreadResource,StringToSizeType(limit,
- 100.0));
+ (void) SetMagickResourceLimit(ThreadResource,StringToMagickSizeType(
+ limit,100.0));
limit=DestroyString(limit);
}
(void) SetMagickResourceLimit(ThrottleResource,0);
limit=GetEnvironmentValue("MAGICK_THROTTLE_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(ThrottleResource,StringToSizeType(limit,
- 100.0));
+ (void) SetMagickResourceLimit(ThrottleResource,StringToMagickSizeType(
+ limit,100.0));
limit=DestroyString(limit);
}
(void) SetMagickResourceLimit(TimeResource,MagickResourceInfinity);
limit=GetEnvironmentValue("MAGICK_TIME_LIMIT");
if (limit != (char *) NULL)
{
- (void) SetMagickResourceLimit(TimeResource,StringToSizeType(limit,100.0));
+ (void) SetMagickResourceLimit(TimeResource,StringToMagickSizeType(limit,
+ 100.0));
limit=DestroyString(limit);
}
return(MagickTrue);
resource_info.width_limit=limit;
value=GetPolicyValue("resource:width");
if (value != (char *) NULL)
- resource_info.width_limit=MagickMin(limit,StringToSizeType(value,
+ resource_info.width_limit=MagickMin(limit,StringToMagickSizeType(value,
100.0));
break;
}
resource_info.height_limit=limit;
value=GetPolicyValue("resource:height");
if (value != (char *) NULL)
- resource_info.height_limit=MagickMin(limit,StringToSizeType(value,
- 100.0));
+ resource_info.height_limit=MagickMin(limit,StringToMagickSizeType(
+ value,100.0));
break;
}
case AreaResource:
resource_info.area_limit=limit;
value=GetPolicyValue("resource:area");
if (value != (char *) NULL)
- resource_info.area_limit=MagickMin(limit,StringToSizeType(value,100.0));
+ resource_info.area_limit=MagickMin(limit,StringToMagickSizeType(value,
+ 100.0));
break;
}
case MemoryResource:
resource_info.memory_limit=limit;
value=GetPolicyValue("resource:memory");
if (value != (char *) NULL)
- resource_info.memory_limit=MagickMin(limit,StringToSizeType(value,
- 100.0));
+ resource_info.memory_limit=MagickMin(limit,StringToMagickSizeType(
+ value,100.0));
break;
}
case MapResource:
resource_info.map_limit=limit;
value=GetPolicyValue("resource:map");
if (value != (char *) NULL)
- resource_info.map_limit=MagickMin(limit,StringToSizeType(value,100.0));
+ resource_info.map_limit=MagickMin(limit,StringToMagickSizeType(value,
+ 100.0));
break;
}
case DiskResource:
resource_info.disk_limit=limit;
value=GetPolicyValue("resource:disk");
if (value != (char *) NULL)
- resource_info.disk_limit=MagickMin(limit,StringToSizeType(value,100.0));
+ resource_info.disk_limit=MagickMin(limit,StringToMagickSizeType(value,
+ 100.0));
break;
}
case FileResource:
resource_info.file_limit=limit;
value=GetPolicyValue("resource:file");
if (value != (char *) NULL)
- resource_info.file_limit=MagickMin(limit,StringToSizeType(value,100.0));
+ resource_info.file_limit=MagickMin(limit,StringToMagickSizeType(value,
+ 100.0));
break;
}
case ThreadResource:
resource_info.thread_limit=limit;
value=GetPolicyValue("resource:thread");
if (value != (char *) NULL)
- resource_info.thread_limit=MagickMin(limit,StringToSizeType(value,
- 100.0));
+ resource_info.thread_limit=MagickMin(limit,StringToMagickSizeType(
+ value,100.0));
if (resource_info.thread_limit > GetOpenMPMaximumThreads())
resource_info.thread_limit=GetOpenMPMaximumThreads();
else
resource_info.throttle_limit=limit;
value=GetPolicyValue("resource:throttle");
if (value != (char *) NULL)
- resource_info.throttle_limit=MagickMax(limit,StringToSizeType(value,
- 100.0));
+ resource_info.throttle_limit=MagickMax(limit,StringToMagickSizeType(
+ value,100.0));
break;
}
case TimeResource:
resource_info.time_limit=limit;
value=GetPolicyValue("resource:time");
if (value != (char *) NULL)
- resource_info.time_limit=MagickMin(limit,StringToSizeType(value,100.0));
+ resource_info.time_limit=MagickMin(limit,StringToMagickSizeType(value,
+ 100.0));
ResetPixelCacheEpoch();
break;
}
*GetStreamInfoClientData(StreamInfo *);
extern MagickPrivate void
+ ResetStreamAnonymousMemory(void),
SetStreamInfoClientData(StreamInfo *,const void *);
#if defined(__cplusplus) || defined(c_plusplus)
% %
% %
% %
++ 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 %
% %
% %
return(strtol(value,(char **) NULL,10));
}
+static inline MagickSizeType StringToMagickSizeType(const char *string,
+ const double interval)
+{
+ double
+ value;
+
+ value=SiPrefixToDoubleInterval(string,interval);
+ if (value >= (double) MagickULLConstant(~0))
+ return(MagickULLConstant(~0));
+ return((MagickSizeType) value);
+}
+
+static inline size_t StringToSizeType(const char *string,
+ const double interval)
+{
+ double
+ value;
+
+ value=SiPrefixToDoubleInterval(string,interval);
+ if (value >= (double) MagickULLConstant(~0))
+ return((size_t) MagickULLConstant(~0));
+ return((size_t) value);
+}
+
static inline unsigned long StringToUnsignedLong(
const char *magick_restrict value)
{