memory_.h

Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2020 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004 
00005   You may not use this file except in compliance with the License.  You may
00006   obtain a copy of the License at
00007 
00008     https://imagemagick.org/script/license.php
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   MagickCore memory methods.
00017 */
00018 #ifndef MAGICKCORE_MEMORY_H
00019 #define MAGICKCORE_MEMORY_H
00020 
00021 #include <errno.h>
00022 #include <assert.h>
00023 
00024 #if defined(__cplusplus) || defined(c_plusplus)
00025 extern "C" {
00026 #endif
00027 
00028 typedef struct _MemoryInfo
00029   MemoryInfo;
00030 
00031 typedef void
00032   *(*AcquireMemoryHandler)(size_t) magick_alloc_size(1),
00033   (*DestroyMemoryHandler)(void *),
00034   *(*ResizeMemoryHandler)(void *,size_t) magick_alloc_size(2),
00035   *(*AcquireAlignedMemoryHandler)(const size_t,const size_t),
00036   (*RelinquishAlignedMemoryHandler)(void *);
00037 
00038 extern MagickExport MemoryInfo
00039   *AcquireVirtualMemory(const size_t,const size_t) magick_alloc_sizes(1,2),
00040   *RelinquishVirtualMemory(MemoryInfo *);
00041 
00042 extern MagickExport size_t
00043   GetMaxMemoryRequest(void);
00044 
00045 extern MagickExport void
00046   *AcquireAlignedMemory(const size_t,const size_t)
00047     magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
00048   *AcquireMagickMemory(const size_t) magick_attribute((__malloc__))
00049     magick_alloc_size(1),
00050   *AcquireCriticalMemory(const size_t),
00051   *AcquireQuantumMemory(const size_t,const size_t)
00052     magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
00053   *CopyMagickMemory(void *magick_restrict,const void *magick_restrict,
00054     const size_t) magick_attribute((__nonnull__)),
00055   DestroyMagickMemory(void),
00056   GetMagickMemoryMethods(AcquireMemoryHandler *,ResizeMemoryHandler *,
00057     DestroyMemoryHandler *),
00058   *GetVirtualMemoryBlob(const MemoryInfo *),
00059   *RelinquishAlignedMemory(void *),
00060   *RelinquishMagickMemory(void *),
00061   *ResetMagickMemory(void *,int,const size_t),
00062   *ResizeMagickMemory(void *,const size_t)
00063     magick_attribute((__malloc__)) magick_alloc_size(2),
00064   *ResizeQuantumMemory(void *,const size_t,const size_t)
00065     magick_attribute((__malloc__)) magick_alloc_sizes(2,3),
00066   SetMagickAlignedMemoryMethods(AcquireAlignedMemoryHandler,
00067     RelinquishAlignedMemoryHandler),
00068   SetMagickMemoryMethods(AcquireMemoryHandler,ResizeMemoryHandler,
00069     DestroyMemoryHandler);
00070 
00071 static inline MagickBooleanType HeapOverflowSanityCheck(
00072   const size_t count,const size_t quantum)
00073 {
00074   if ((count == 0) || (quantum == 0))
00075     return(MagickTrue);
00076   if (quantum != ((count*quantum)/count))
00077     {
00078       errno=ENOMEM;
00079       return(MagickTrue);
00080     }
00081   return(MagickFalse);
00082 }
00083 
00084 static inline MagickBooleanType HeapOverflowSanityCheckGetSize(
00085   const size_t count,const size_t quantum,size_t *const extent)
00086 {
00087   size_t
00088     length;
00089 
00090   if ((count == 0) || (quantum == 0))
00091     return(MagickTrue);
00092   length=count*quantum;
00093   if (quantum != (length/count))
00094     {
00095       errno=ENOMEM;
00096       return(MagickTrue);
00097     }
00098   assert(extent != (size_t *const) NULL);
00099   *extent=length;
00100   return(MagickFalse);
00101 }
00102 
00103 #if defined(__cplusplus) || defined(c_plusplus)
00104 }
00105 #endif
00106 
00107 #endif

Generated on 25 May 2020 for MagickCore by  doxygen 1.6.1