MagickCore 7.1.2-32
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
memory_.h
1/*
2 Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License. You may
6 obtain a copy of the License at
7
8 https://imagemagick.org/license/
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 MagickCore memory methods.
17*/
18#ifndef MAGICKCORE_MEMORY_H
19#define MAGICKCORE_MEMORY_H
20
21#include <errno.h>
22
23#ifdef _WIN64
24# if !defined(SSIZE_MAX)
25# define SSIZE_MAX LLONG_MAX
26# endif
27#else
28# if !defined(SSIZE_MAX)
29# define SSIZE_MAX LONG_MAX
30# endif
31#endif
32
33#define MAGICK_INT_MAX (INT_MAX)
34#define MAGICK_PTRDIFF_MAX (PTRDIFF_MAX)
35#define MAGICK_PTRDIFF_MIN (-PTRDIFF_MAX-1)
36#define MAGICK_SIZE_MAX (SIZE_MAX)
37#define MAGICK_SSIZE_MAX (SSIZE_MAX)
38#define MAGICK_SSIZE_MIN (-SSIZE_MAX-1)
39#define MAGICK_UCHAR_MAX (UCHAR_MAX)
40#define MAGICK_UINT_MAX (UINT_MAX)
41#define MAGICK_ULONG_MAX (ULONG_MAX)
42#define MAGICK_USHORT_MAX (USHRT_MAX)
43
44#if defined(__cplusplus) || defined(c_plusplus)
45extern "C" {
46#endif
47
48typedef struct _MemoryInfo
49 MemoryInfo;
50
51typedef void
52 *(*AcquireMemoryHandler)(size_t) magick_alloc_size(1),
53 (*DestroyMemoryHandler)(void *),
54 *(*ResizeMemoryHandler)(void *,size_t) magick_alloc_size(2),
55 *(*AcquireAlignedMemoryHandler)(const size_t,const size_t),
56 (*RelinquishAlignedMemoryHandler)(void *);
57
58extern MagickExport MemoryInfo
59 *AcquireVirtualMemory(const size_t,const size_t) magick_alloc_sizes(1,2),
60 *RelinquishVirtualMemory(MemoryInfo *);
61
62extern MagickExport size_t
63 GetMaxMemoryRequest(void),
64 GetMaxProfileSize(void);
65
66extern MagickExport void
67 *AcquireAlignedMemory(const size_t,const size_t)
68 magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
69 *AcquireMagickMemory(const size_t) magick_attribute((__malloc__))
70 magick_alloc_size(1),
71 *AcquireCriticalMemory(const size_t),
72 *AcquireQuantumMemory(const size_t,const size_t)
73 magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
74 *CopyMagickMemory(void *magick_restrict,const void *magick_restrict,
75 const size_t) magick_attribute((__nonnull__)),
76 DestroyMagickMemory(void),
77 GetMagickMemoryMethods(AcquireMemoryHandler *,ResizeMemoryHandler *,
78 DestroyMemoryHandler *),
79 *GetVirtualMemoryBlob(const MemoryInfo *),
80 *RelinquishAlignedMemory(void *),
81 *RelinquishMagickMemory(void *),
82 *ResetMagickMemory(void *,int,const size_t),
83 *ResizeMagickMemory(void *,const size_t)
84 magick_attribute((__malloc__)) magick_alloc_size(2),
85 *ResizeQuantumMemory(void *,const size_t,const size_t)
86 magick_attribute((__malloc__)) magick_alloc_sizes(2,3),
87 SetMagickAlignedMemoryMethods(AcquireAlignedMemoryHandler,
88 RelinquishAlignedMemoryHandler),
89 SetMagickMemoryMethods(AcquireMemoryHandler,ResizeMemoryHandler,
90 DestroyMemoryHandler);
91
92static inline MagickBooleanType HeapOverflowSanityCheck(
93 const size_t count,const size_t quantum)
94{
95 if ((count == 0) || (quantum == 0))
96 return(MagickTrue);
97 if (count > (MAGICK_SIZE_MAX/quantum))
98 {
99 errno=ENOMEM;
100 return(MagickTrue);
101 }
102 return(MagickFalse);
103}
104
105static inline MagickBooleanType HeapOverflowSanityCheckGetSize(
106 const size_t count,const size_t quantum,size_t *const extent)
107{
108 if ((count == 0) || (quantum == 0))
109 return(MagickTrue);
110 if (count > (MAGICK_SIZE_MAX/quantum))
111 {
112 errno=ENOMEM;
113 return(MagickTrue);
114 }
115 if (extent != NULL)
116 *extent=count*quantum;
117 return(MagickFalse);
118}
119
120#if defined(__cplusplus) || defined(c_plusplus)
121}
122#endif
123
124#endif