Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:21

0001 /*
0002   Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
0003   dedicated to making software imaging solutions freely available.
0004 
0005   You may not use this file except in compliance with the License.  You may
0006   obtain a copy of the License at
0007 
0008     https://imagemagick.org/script/license.php
0009 
0010   Unless required by applicable law or agreed to in writing, software
0011   distributed under the License is distributed on an "AS IS" BASIS,
0012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013   See the License for the specific language governing permissions and
0014   limitations under the License.
0015 
0016   MagickCore memory methods.
0017 */
0018 #ifndef MAGICKCORE_MEMORY_H
0019 #define MAGICKCORE_MEMORY_H
0020 
0021 #include <errno.h>
0022 
0023 #if defined(__cplusplus) || defined(c_plusplus)
0024 extern "C" {
0025 #endif
0026 
0027 typedef struct _MemoryInfo
0028   MemoryInfo;
0029 
0030 typedef void
0031   *(*AcquireMemoryHandler)(size_t) magick_alloc_size(1),
0032   (*DestroyMemoryHandler)(void *),
0033   *(*ResizeMemoryHandler)(void *,size_t) magick_alloc_size(2),
0034   *(*AcquireAlignedMemoryHandler)(const size_t,const size_t),
0035   (*RelinquishAlignedMemoryHandler)(void *);
0036 
0037 extern MagickExport MemoryInfo
0038   *AcquireVirtualMemory(const size_t,const size_t) magick_alloc_sizes(1,2),
0039   *RelinquishVirtualMemory(MemoryInfo *);
0040 
0041 extern MagickExport size_t
0042   GetMaxMemoryRequest(void);
0043 
0044 extern MagickExport void
0045   *AcquireAlignedMemory(const size_t,const size_t)
0046     magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
0047   *AcquireMagickMemory(const size_t) magick_attribute((__malloc__))
0048     magick_alloc_size(1),
0049   *AcquireCriticalMemory(const size_t),
0050   *AcquireQuantumMemory(const size_t,const size_t)
0051     magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
0052   *CopyMagickMemory(void *magick_restrict,const void *magick_restrict,
0053     const size_t) magick_attribute((__nonnull__)),
0054   DestroyMagickMemory(void),
0055   GetMagickMemoryMethods(AcquireMemoryHandler *,ResizeMemoryHandler *,
0056     DestroyMemoryHandler *),
0057   *GetVirtualMemoryBlob(const MemoryInfo *),
0058   *RelinquishAlignedMemory(void *),
0059   *RelinquishMagickMemory(void *),
0060   *ResetMagickMemory(void *,int,const size_t),
0061   *ResizeMagickMemory(void *,const size_t)
0062     magick_attribute((__malloc__)) magick_alloc_size(2),
0063   *ResizeQuantumMemory(void *,const size_t,const size_t)
0064     magick_attribute((__malloc__)) magick_alloc_sizes(2,3),
0065   SetMagickAlignedMemoryMethods(AcquireAlignedMemoryHandler,
0066     RelinquishAlignedMemoryHandler),
0067   SetMagickMemoryMethods(AcquireMemoryHandler,ResizeMemoryHandler,
0068     DestroyMemoryHandler);
0069 
0070 static inline MagickBooleanType HeapOverflowSanityCheck(
0071   const size_t count,const size_t quantum)
0072 {
0073   if ((count == 0) || (quantum == 0))
0074     return(MagickTrue);
0075   if (quantum != ((count*quantum)/count))
0076     {
0077       errno=ENOMEM;
0078       return(MagickTrue);
0079     }
0080   return(MagickFalse);
0081 }
0082 
0083 static inline MagickBooleanType HeapOverflowSanityCheckGetSize(
0084   const size_t count,const size_t quantum,size_t *const extent)
0085 {
0086   size_t
0087     length;
0088 
0089   if ((count == 0) || (quantum == 0))
0090     return(MagickTrue);
0091   length=count*quantum;
0092   if (quantum != (length/count))
0093     {
0094       errno=ENOMEM;
0095       return(MagickTrue);
0096     }
0097   if (extent != NULL)
0098     *extent=length;
0099   return(MagickFalse);
0100 }
0101 
0102 #if defined(__cplusplus) || defined(c_plusplus)
0103 }
0104 #endif
0105 
0106 #endif