MagickCore  6.9.10
Convert, Edit, Or Compose Bitmap Images
memory-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2019 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.
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 private memory methods.
17 */
18 #ifndef MAGICKCORE_MEMORY_PRIVATE_H
19 #define MAGICKCORE_MEMORY_PRIVATE_H
20 
21 #include "magick/magick-config.h"
22 #include <stdint.h>
23 
24 #if defined(__cplusplus) || defined(c_plusplus)
25 extern "C" {
26 #endif
27 
29 
30 #if defined(__powerpc__)
31 # define CACHE_LINE_SIZE (16*sizeof(void *))
32 #else
33 # define CACHE_LINE_SIZE (8*sizeof(void *))
34 #endif
35 
36 #define CacheAlign(size) ((size) < CACHE_LINE_SIZE ? CACHE_LINE_SIZE : (size))
37 
38 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 6))
39 #if !defined(__ICC)
40 #define MagickAssumeAligned(address) \
41  __builtin_assume_aligned((address),CACHE_LINE_SIZE)
42 #else
43 #define MagickAssumeAligned(address) (address)
44 #endif
45 #else
46 #define MagickAssumeAligned(address) (address)
47 #endif
48 
49 #ifndef HeapOverflowSanityCheckDefined
51  HeapOverflowSanityCheck(const size_t,const size_t) magick_alloc_sizes(1,2);
52 #define HeapOverflowSanityCheckDefined
53 #endif
54 
55 MagickExport size_t
56  GetMaxMemoryRequest(void);
57 
58 static inline void *AcquireCriticalMemory(const size_t size)
59 {
60  register void
61  *memory;
62 
63  /*
64  Fail if memory request cannot be fulfilled.
65  */
66  memory=AcquireMagickMemory(size);
67  if (memory == (void *) NULL)
68  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
69  return(memory);
70 }
71 
72 static inline MagickBooleanType HeapOverflowCheckAdd(const size_t size,
73  const size_t increment)
74 {
75  if (size > (SIZE_MAX-increment))
76  {
77  errno=ENOMEM;
78  return(MagickTrue);
79  }
80  return(MagickFalse);
81 }
82 
83 #if defined(__cplusplus) || defined(c_plusplus)
84 }
85 #endif
86 
87 #endif
#define ThrowFatalException(severity, tag)
Definition: exception-private.h:42
static void * AcquireCriticalMemory(const size_t size)
Definition: memory-private.h:58
Definition: exception.h:78
MagickBooleanType
Definition: magick-type.h:191
static MagickBooleanType HeapOverflowCheckAdd(const size_t size, const size_t increment)
Definition: memory-private.h:72
Definition: magick-type.h:194
Definition: magick-type.h:193
MagickExport void * AcquireMagickMemory(const size_t size)
Definition: memory.c:476
MagickExport MagickBooleanType HeapOverflowSanityCheck(const size_t, const size_t) magick_alloc_sizes(1
MagickExport size_t GetMaxMemoryRequest(void)
Definition: memory.c:918
#define MagickExport
Definition: method-attribute.h:80
#define magick_alloc_sizes(x, y)
Definition: method-attribute.h:114