MagickCore  7.1.0
Convert, Edit, Or Compose Bitmap Images
memory_.h
Go to the documentation of this file.
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/script/license.php
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 #if defined(__cplusplus) || defined(c_plusplus)
24 extern "C" {
25 #endif
26 
27 typedef struct _MemoryInfo
28  MemoryInfo;
29 
30 typedef void
31  *(*AcquireMemoryHandler)(size_t) magick_alloc_size(1),
32  (*DestroyMemoryHandler)(void *),
33  *(*ResizeMemoryHandler)(void *,size_t) magick_alloc_size(2),
34  *(*AcquireAlignedMemoryHandler)(const size_t,const size_t),
36 
38  *AcquireVirtualMemory(const size_t,const size_t) magick_alloc_sizes(1,2),
40 
41 extern MagickExport size_t
42  GetMaxMemoryRequest(void);
43 
44 extern MagickExport void
45  *AcquireAlignedMemory(const size_t,const size_t)
46  magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
47  *AcquireMagickMemory(const size_t) magick_attribute((__malloc__))
49  *AcquireCriticalMemory(const size_t),
50  *AcquireQuantumMemory(const size_t,const size_t)
51  magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
53  const size_t) magick_attribute((__nonnull__)),
54  DestroyMagickMemory(void),
58  *RelinquishAlignedMemory(void *),
59  *RelinquishMagickMemory(void *),
60  *ResetMagickMemory(void *,int,const size_t),
61  *ResizeMagickMemory(void *,const size_t)
62  magick_attribute((__malloc__)) magick_alloc_size(2),
63  *ResizeQuantumMemory(void *,const size_t,const size_t)
64  magick_attribute((__malloc__)) magick_alloc_sizes(2,3),
69 
71  const size_t count,const size_t quantum)
72 {
73  if ((count == 0) || (quantum == 0))
74  return(MagickTrue);
75  if (quantum != ((count*quantum)/count))
76  {
77  errno=ENOMEM;
78  return(MagickTrue);
79  }
80  return(MagickFalse);
81 }
82 
84  const size_t count,const size_t quantum,size_t *const extent)
85 {
86  size_t
87  length;
88 
89  if ((count == 0) || (quantum == 0))
90  return(MagickTrue);
91  length=count*quantum;
92  if (quantum != (length/count))
93  {
94  errno=ENOMEM;
95  return(MagickTrue);
96  }
97  if (extent != NULL)
98  *extent=length;
99  return(MagickFalse);
100 }
101 
102 #if defined(__cplusplus) || defined(c_plusplus)
103 }
104 #endif
105 
106 #endif
#define magick_restrict
Definition: MagickCore.h:41
MagickExport MemoryInfo * RelinquishVirtualMemory(MemoryInfo *)
Definition: memory.c:1229
void *(* AcquireMemoryHandler)(size_t) magick_alloc_size(1)
Definition: memory_.h:31
MagickExport size_t GetMaxMemoryRequest(void)
Definition: memory.c:1044
void *(*)(* DestroyMemoryHandler)(void *)
Definition: memory_.h:32
MagickExport void * ResizeMagickMemory(void *, const size_t) magick_attribute((__malloc__)) magick_alloc_size(2)
MagickExport void * RelinquishMagickMemory(void *)
#define magick_alloc_size(x)
MagickExport MemoryInfo * AcquireVirtualMemory(const size_t, const size_t) magick_alloc_sizes(1
#define magick_attribute(x)
MagickBooleanType
Definition: magick-type.h:161
MagickExport void * RelinquishAlignedMemory(void *)
MagickExport void * ResetMagickMemory(void *, int, const size_t)
MagickExport void GetMagickMemoryMethods(AcquireMemoryHandler *, ResizeMemoryHandler *, DestroyMemoryHandler *)
void *(*)(*) *(*) *(*)(* RelinquishAlignedMemoryHandler)(void *)
Definition: memory_.h:35
MagickExport void * AcquireCriticalMemory(const size_t)
void *(*)(*) *(*) *(* AcquireAlignedMemoryHandler)(const size_t, const size_t)
Definition: memory_.h:34
size_t length
Definition: memory.c:172
MagickExport void * GetVirtualMemoryBlob(const MemoryInfo *)
MagickExport void SetMagickAlignedMemoryMethods(AcquireAlignedMemoryHandler, RelinquishAlignedMemoryHandler)
MagickExport void * AcquireQuantumMemory(const size_t, const size_t) magick_attribute((__malloc__)) magick_alloc_sizes(1
MagickExport void * CopyMagickMemory(void *magick_restrict, const void *magick_restrict, const size_t) magick_attribute((__nonnull__))
static MagickBooleanType HeapOverflowSanityCheckGetSize(const size_t count, const size_t quantum, size_t *const extent)
Definition: memory_.h:83
MagickExport void DestroyMagickMemory(void)
MagickExport void * AcquireMagickMemory(const size_t) magick_attribute((__malloc__)) magick_alloc_size(1)
MagickExport void SetMagickMemoryMethods(AcquireMemoryHandler, ResizeMemoryHandler, DestroyMemoryHandler)
Definition: memory.c:1539
MagickExport void * ResizeQuantumMemory(void *, const size_t, const size_t) magick_attribute((__malloc__)) magick_alloc_sizes(2
MagickExport void * AcquireAlignedMemory(const size_t, const size_t) magick_attribute((__malloc__)) magick_alloc_sizes(1
#define MagickExport
void *(*)(*) *(* ResizeMemoryHandler)(void *, size_t) magick_alloc_size(2)
Definition: memory_.h:33
static MagickBooleanType HeapOverflowSanityCheck(const size_t count, const size_t quantum)
Definition: memory_.h:70
#define magick_alloc_sizes(x, y)