#include "MagickCore/exception-private.h"
#include "MagickCore/memory_.h"
#include "MagickCore/memory-private.h"
+#include "MagickCore/policy.h"
#include "MagickCore/resource_.h"
#include "MagickCore/semaphore.h"
#include "MagickCore/string_.h"
size_t
extent;
+ static ssize_t
+ virtual_anonymous_memory = (-1);
+
if (HeapOverflowSanityCheck(count,quantum) != MagickFalse)
return((MemoryInfo *) NULL);
memory_info=(MemoryInfo *) MagickAssumeAligned(AcquireAlignedMemory(1,
extent=count*quantum;
memory_info->length=extent;
memory_info->signature=MagickCoreSignature;
- if (AcquireMagickResource(MemoryResource,extent) != MagickFalse)
+ if (virtual_anonymous_memory < 0)
{
- memory_info->blob=AcquireAlignedMemory(1,extent);
- if (memory_info->blob != NULL)
+ char
+ *value;
+
+ /*
+ Does the security policy require anonymous mapping for pixel cache?
+ */
+ virtual_anonymous_memory=0;
+ value=GetPolicyValue("system:memory-map");
+ if (LocaleCompare(value,"anonymous") == 0)
{
- memory_info->type=AlignedVirtualMemory;
- return(memory_info);
+#if defined(MAGICKCORE_HAVE_MMAP) && defined(MAP_ANONYMOUS)
+ virtual_anonymous_memory=1;
+#endif
}
+ value=DestroyString(value);
}
- RelinquishMagickResource(MemoryResource,extent);
- if (AcquireMagickResource(MapResource,extent) != MagickFalse)
+ if (virtual_anonymous_memory <= 0)
{
- /*
- Heap memory failed, try anonymous memory mapping.
- */
- memory_info->blob=MapBlob(-1,IOMode,0,extent);
- if (memory_info->blob != NULL)
+ if (AcquireMagickResource(MemoryResource,extent) != MagickFalse)
{
- memory_info->type=MapVirtualMemory;
- return(memory_info);
+ memory_info->blob=AcquireAlignedMemory(1,extent);
+ if (memory_info->blob != NULL)
+ {
+ memory_info->type=AlignedVirtualMemory;
+ return(memory_info);
+ }
}
- if (AcquireMagickResource(DiskResource,extent) != MagickFalse)
+ RelinquishMagickResource(MemoryResource,extent);
+ }
+ else
+ {
+ if (AcquireMagickResource(MapResource,extent) != MagickFalse)
{
- int
- file;
-
/*
- Anonymous memory mapping failed, try file-backed memory mapping.
- If the MapResource request failed, there is no point in trying
- file-backed memory mapping.
+ Acquire anonymous memory map.
*/
- file=AcquireUniqueFileResource(memory_info->filename);
- if (file != -1)
+ memory_info->blob=MapBlob(-1,IOMode,0,extent);
+ if (memory_info->blob != NULL)
+ {
+ memory_info->type=MapVirtualMemory;
+ return(memory_info);
+ }
+ if (AcquireMagickResource(DiskResource,extent) != MagickFalse)
{
- MagickOffsetType
- offset;
+ int
+ file;
- offset=(MagickOffsetType) lseek(file,extent-1,SEEK_SET);
- if ((offset == (MagickOffsetType) (extent-1)) &&
- (write(file,"",1) == 1))
+ /*
+ Anonymous memory mapping failed, try file-backed memory mapping.
+ If the MapResource request failed, there is no point in trying
+ file-backed memory mapping.
+ */
+ file=AcquireUniqueFileResource(memory_info->filename);
+ if (file != -1)
{
- memory_info->blob=MapBlob(file,IOMode,0,extent);
- if (memory_info->blob != NULL)
+ MagickOffsetType
+ offset;
+
+ offset=(MagickOffsetType) lseek(file,extent-1,SEEK_SET);
+ if ((offset == (MagickOffsetType) (extent-1)) &&
+ (write(file,"",1) == 1))
{
- (void) close(file);
- memory_info->type=MapVirtualMemory;
- return(memory_info);
+ memory_info->blob=MapBlob(file,IOMode,0,extent);
+ if (memory_info->blob != NULL)
+ {
+ (void) close(file);
+ memory_info->type=MapVirtualMemory;
+ return(memory_info);
+ }
}
+ /*
+ File-backed memory mapping fail, delete the temporary file.
+ */
+ (void) close(file);
+ (void) RelinquishUniqueFileResource(memory_info->filename);
+ *memory_info->filename = '\0';
}
- /*
- File-backed memory mapping failed, delete the temporary file.
- */
- (void) close(file);
- (void) RelinquishUniqueFileResource(memory_info->filename);
- *memory_info->filename = '\0';
}
+ RelinquishMagickResource(DiskResource,extent);
}
- RelinquishMagickResource(DiskResource,extent);
}
RelinquishMagickResource(MapResource,extent);
if (memory_info->blob == NULL)