MagickCore  7.0.10
memory_.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2020 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 #include <assert.h>
23 
24 #if defined(__cplusplus) || defined(c_plusplus)
25 extern "C" {
26 #endif
27 
28 typedef struct _MemoryInfo
29  MemoryInfo;
30 
31 typedef void
32  *(*AcquireMemoryHandler)(size_t) magick_alloc_size(1),
33  (*DestroyMemoryHandler)(void *),
34  *(*ResizeMemoryHandler)(void *,size_t) magick_alloc_size(2),
35  *(*AcquireAlignedMemoryHandler)(const size_t,const size_t),
37 
39  *AcquireVirtualMemory(const size_t,const size_t) magick_alloc_sizes(1,2),
41 
42 extern MagickExport size_t
43  GetMaxMemoryRequest(void);
44 
45 extern MagickExport void
46  *AcquireAlignedMemory(const size_t,const size_t)
47  magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
48  *AcquireMagickMemory(const size_t) magick_attribute((__malloc__))
50  *AcquireCriticalMemory(const size_t),
51  *AcquireQuantumMemory(const size_t,const size_t)
52  magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
53  *CopyMagickMemory(void *magick_restrict,const void *magick_restrict,
54  const size_t) magick_attribute((__nonnull__)),
55  DestroyMagickMemory(void),
58  *GetVirtualMemoryBlob(const MemoryInfo *),
59  *RelinquishAlignedMemory(void *),
60  *RelinquishMagickMemory(void *),
61  *ResetMagickMemory(void *,int,const size_t),
62  *ResizeMagickMemory(void *,const size_t)
63  magick_attribute((__malloc__)) magick_alloc_size(2),
64  *ResizeQuantumMemory(void *,const size_t,const size_t)
65  magick_attribute((__malloc__)) magick_alloc_sizes(2,3),
68  SetMagickMemoryMethods(AcquireMemoryHandler,ResizeMemoryHandler,
69  DestroyMemoryHandler);
70 
72  const size_t count,const size_t quantum)
73 {
74  if ((count == 0) || (quantum == 0))
75  return(MagickTrue);
76  if (quantum != ((count*quantum)/count))
77  {
78  errno=ENOMEM;
79  return(MagickTrue);
80  }
81  return(MagickFalse);
82 }
83 
85  const size_t count,const size_t quantum,size_t *const extent)
86 {
87  size_t
88  length;
89 
90  if ((count == 0) || (quantum == 0))
91  return(MagickTrue);
92  length=count*quantum;
93  if (quantum != (length/count))
94  {
95  errno=ENOMEM;
96  return(MagickTrue);
97  }
98  assert(extent != (size_t *const) NULL);
99  *extent=length;
100  return(MagickFalse);
101 }
102 
103 #if defined(__cplusplus) || defined(c_plusplus)
104 }
105 #endif
106 
107 #endif
#define magick_restrict
Definition: MagickCore.h:41
MagickExport MemoryInfo * RelinquishVirtualMemory(MemoryInfo *memory_info)
Definition: memory.c:1190
MagickExport void DestroyMagickMemory(void)
Definition: memory.c:848
MagickExport void SetMagickMemoryMethods(AcquireMemoryHandler acquire_memory_handler, ResizeMemoryHandler resize_memory_handler, DestroyMemoryHandler destroy_memory_handler)
Definition: memory.c:1488
MagickExport MemoryInfo * AcquireVirtualMemory(const size_t count, const size_t quantum)
Definition: memory.c:670
MagickExport void GetMagickMemoryMethods(AcquireMemoryHandler *acquire_memory_handler, ResizeMemoryHandler *resize_memory_handler, DestroyMemoryHandler *destroy_memory_handler)
Definition: memory.c:976
void *(*)(* DestroyMemoryHandler)(void *)
Definition: memory_.h:33
#define magick_alloc_size(x)
MagickExport void * ResizeMagickMemory(void *memory, const size_t size)
Definition: memory.c:1348
MagickExport void * ResizeQuantumMemory(void *memory, const size_t count, const size_t quantum)
Definition: memory.c:1408
#define magick_attribute(x)
MagickExport void * CopyMagickMemory(void *magick_restrict destination, const void *magick_restrict source, const size_t size)
Definition: memory.c:800
MagickBooleanType
Definition: magick-type.h:169
MagickExport void * ResetMagickMemory(void *memory, int byte, const size_t size)
Definition: memory.c:1249
MagickExport void * AcquireCriticalMemory(const size_t size)
Definition: memory.c:595
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:634
MagickExport void * RelinquishAlignedMemory(void *memory)
Definition: memory.c:1081
size_t length
Definition: memory.c:144
MagickExport void * AcquireAlignedMemory(const size_t count, const size_t quantum)
Definition: memory.c:337
static MagickBooleanType HeapOverflowSanityCheckGetSize(const size_t count, const size_t quantum, size_t *const extent)
Definition: memory_.h:84
MagickExport void * AcquireMagickMemory(const size_t size)
Definition: memory.c:521
MagickExport size_t GetMaxMemoryRequest(void)
Definition: memory.c:1007
MagickExport void SetMagickAlignedMemoryMethods(AcquireAlignedMemoryHandler acquire_aligned_memory_handler, RelinquishAlignedMemoryHandler relinquish_aligned_memory_handler)
Definition: memory.c:1449
void *(*)(*)*(*)*(*)(* RelinquishAlignedMemoryHandler)(void *)
Definition: memory_.h:36
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1123
#define MagickExport
MagickExport void * GetVirtualMemoryBlob(const MemoryInfo *memory_info)
Definition: memory.c:1051
void *(*)(*)*(* ResizeMemoryHandler)(void *, size_t) magick_alloc_size(2)
Definition: memory_.h:34
void *(*)(*)*(*)*(* AcquireAlignedMemoryHandler)(const size_t, const size_t)
Definition: memory_.h:35
static MagickBooleanType HeapOverflowSanityCheck(const size_t count, const size_t quantum)
Definition: memory_.h:71
#define magick_alloc_sizes(x, y)
void *(* AcquireMemoryHandler)(size_t) magick_alloc_size(1)
Definition: memory_.h:32