Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:01:35

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   GetMaxProfileSize(void);
0044 
0045 extern MagickExport void
0046   *AcquireAlignedMemory(const size_t,const size_t)
0047     magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
0048   *AcquireMagickMemory(const size_t) magick_attribute((__malloc__))
0049     magick_alloc_size(1),
0050   *AcquireCriticalMemory(const size_t),
0051   *AcquireQuantumMemory(const size_t,const size_t)
0052     magick_attribute((__malloc__)) magick_alloc_sizes(1,2),
0053   *CopyMagickMemory(void *magick_restrict,const void *magick_restrict,
0054     const size_t) magick_attribute((__nonnull__)),
0055   DestroyMagickMemory(void),
0056   GetMagickMemoryMethods(AcquireMemoryHandler *,ResizeMemoryHandler *,
0057     DestroyMemoryHandler *),
0058   *GetVirtualMemoryBlob(const MemoryInfo *),
0059   *RelinquishAlignedMemory(void *),
0060   *RelinquishMagickMemory(void *),
0061   *ResetMagickMemory(void *,int,const size_t),
0062   *ResizeMagickMemory(void *,const size_t)
0063     magick_attribute((__malloc__)) magick_alloc_size(2),
0064   *ResizeQuantumMemory(void *,const size_t,const size_t)
0065     magick_attribute((__malloc__)) magick_alloc_sizes(2,3),
0066   SetMagickAlignedMemoryMethods(AcquireAlignedMemoryHandler,
0067     RelinquishAlignedMemoryHandler),
0068   SetMagickMemoryMethods(AcquireMemoryHandler,ResizeMemoryHandler,
0069     DestroyMemoryHandler);
0070 
0071 static inline MagickBooleanType HeapOverflowSanityCheck(
0072   const size_t count,const size_t quantum)
0073 {
0074   if ((count == 0) || (quantum == 0))
0075     return(MagickTrue);
0076   if (quantum != ((count*quantum)/count))
0077     {
0078       errno=ENOMEM;
0079       return(MagickTrue);
0080     }
0081   return(MagickFalse);
0082 }
0083 
0084 static inline MagickBooleanType HeapOverflowSanityCheckGetSize(
0085   const size_t count,const size_t quantum,size_t *const extent)
0086 {
0087   size_t
0088     length;
0089 
0090   if ((count == 0) || (quantum == 0))
0091     return(MagickTrue);
0092   length=count*quantum;
0093   if (quantum != (length/count))
0094     {
0095       errno=ENOMEM;
0096       return(MagickTrue);
0097     }
0098   if (extent != NULL)
0099     *extent=length;
0100   return(MagickFalse);
0101 }
0102 
0103 #if defined(__cplusplus) || defined(c_plusplus)
0104 }
0105 #endif
0106 
0107 #endif