File indexing completed on 2025-01-18 10:01:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef MAGICKCORE_MEMORY_H
0019 #define MAGICKCORE_MEMORY_H
0020
0021 #include <errno.h>
0022
0023 #if defined(__cplusplus) || defined(c_plusplus)
0024 extern "C" {
0025 #endif
0026
0027 typedef struct _MemoryInfo
0028 MemoryInfo;
0029
0030 typedef void
0031 *(*AcquireMemoryHandler)(size_t) magick_alloc_size(1),
0032 (*DestroyMemoryHandler)(void *),
0033 *(*ResizeMemoryHandler)(void *,size_t) magick_alloc_size(2),
0034 *(*AcquireAlignedMemoryHandler)(const size_t,const size_t),
0035 (*RelinquishAlignedMemoryHandler)(void *);
0036
0037 extern MagickExport MemoryInfo
0038 *AcquireVirtualMemory(const size_t,const size_t) magick_alloc_sizes(1,2),
0039 *RelinquishVirtualMemory(MemoryInfo *);
0040
0041 extern MagickExport size_t
0042 GetMaxMemoryRequest(void);
0043
0044 extern MagickExport void
0045 *AcquireAlignedMemory(const size_t,const size_t)
0046 magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
0047 *AcquireMagickMemory(const size_t) magick_attribute((__malloc__))
0048 magick_alloc_size(1),
0049 *AcquireCriticalMemory(const size_t),
0050 *AcquireQuantumMemory(const size_t,const size_t)
0051 magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
0052 *CopyMagickMemory(void *magick_restrict,const void *magick_restrict,
0053 const size_t) magick_attribute((__nonnull__)),
0054 DestroyMagickMemory(void),
0055 GetMagickMemoryMethods(AcquireMemoryHandler *,ResizeMemoryHandler *,
0056 DestroyMemoryHandler *),
0057 *GetVirtualMemoryBlob(const MemoryInfo *),
0058 *RelinquishAlignedMemory(void *),
0059 *RelinquishMagickMemory(void *),
0060 *ResetMagickMemory(void *,int,const size_t),
0061 *ResizeMagickMemory(void *,const size_t)
0062 magick_attribute((__malloc__)) magick_alloc_size(2),
0063 *ResizeQuantumMemory(void *,const size_t,const size_t)
0064 magick_attribute((__malloc__)) magick_alloc_sizes(2,3),
0065 SetMagickAlignedMemoryMethods(AcquireAlignedMemoryHandler,
0066 RelinquishAlignedMemoryHandler),
0067 SetMagickMemoryMethods(AcquireMemoryHandler,ResizeMemoryHandler,
0068 DestroyMemoryHandler);
0069
0070 static inline MagickBooleanType HeapOverflowSanityCheck(
0071 const size_t count,const size_t quantum)
0072 {
0073 if ((count == 0) || (quantum == 0))
0074 return(MagickTrue);
0075 if (quantum != ((count*quantum)/count))
0076 {
0077 errno=ENOMEM;
0078 return(MagickTrue);
0079 }
0080 return(MagickFalse);
0081 }
0082
0083 static inline MagickBooleanType HeapOverflowSanityCheckGetSize(
0084 const size_t count,const size_t quantum,size_t *const extent)
0085 {
0086 size_t
0087 length;
0088
0089 if ((count == 0) || (quantum == 0))
0090 return(MagickTrue);
0091 length=count*quantum;
0092 if (quantum != (length/count))
0093 {
0094 errno=ENOMEM;
0095 return(MagickTrue);
0096 }
0097 if (extent != NULL)
0098 *extent=length;
0099 return(MagickFalse);
0100 }
0101
0102 #if defined(__cplusplus) || defined(c_plusplus)
0103 }
0104 #endif
0105
0106 #endif