1 /** 2 * @file malloc.h 3 * Copyright 2012, 2013 MinGW.org project 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 */ 24 #ifndef _MALLOC_H 25 #define _MALLOC_H 26 #pragma GCC system_header 27 #include <_mingw.h> 28 29 /* 30 * Support for programs which want to use malloc.h to get memory management 31 * functions. Unless you absolutely need some of these functions and they are 32 * not in the ANSI headers you should use the ANSI standard header files 33 * instead. 34 */ 35 36 #include <stdlib.h> 37 38 #ifndef RC_INVOKED 39 40 /* 41 * The structure used to walk through the heap with _heapwalk. 42 */ 43 typedef struct _heapinfo 44 { 45 int* _pentry; 46 size_t _size; 47 int _useflag; 48 } _HEAPINFO; 49 50 /* Values for _heapinfo.useflag */ 51 #define _FREEENTRY 0 52 #define _USEDENTRY 1 53 54 /* Return codes for _heapwalk() */ 55 #define _HEAPEMPTY (-1) 56 #define _HEAPOK (-2) 57 #define _HEAPBADBEGIN (-3) 58 #define _HEAPBADNODE (-4) 59 #define _HEAPEND (-5) 60 #define _HEAPBADPTR (-6) 61 62 /* maximum size of a user request for memory */ 63 #define _HEAP_MAXREQ 0xFFFFFFE0 64 65 #ifdef __cplusplus 66 extern "C" { 67 #endif 68 /* 69 The _heap* memory allocation functions are supported on NT 70 but not W9x. On latter, they always set errno to ENOSYS. 71 */ 72 _CRTIMP int __cdecl __MINGW_NOTHROW _heapwalk (_HEAPINFO*); 73 #define _alloca(x) __builtin_alloca((x)) 74 75 #ifndef _NO_OLDNAMES 76 _CRTIMP int __cdecl __MINGW_NOTHROW heapwalk (_HEAPINFO*); 77 #define alloca(x) __builtin_alloca((x)) 78 #endif /* Not _NO_OLDNAMES */ 79 80 _CRTIMP int __cdecl __MINGW_NOTHROW _heapchk (void); /* Verify heap integrety. */ 81 _CRTIMP int __cdecl __MINGW_NOTHROW _heapmin (void); /* Return unused heap to the OS. */ 82 _CRTIMP int __cdecl __MINGW_NOTHROW _heapset (unsigned int); 83 84 _CRTIMP size_t __cdecl __MINGW_NOTHROW _msize (void*); 85 _CRTIMP size_t __cdecl __MINGW_NOTHROW _get_sbh_threshold (void); 86 _CRTIMP int __cdecl __MINGW_NOTHROW _set_sbh_threshold (size_t); 87 _CRTIMP void* __cdecl __MINGW_NOTHROW _expand (void*, size_t); 88 89 _CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_malloc(size_t, size_t, size_t); 90 _CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_realloc(void*, size_t, size_t, size_t); 91 _CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_recalloc(void*, size_t, size_t, size_t, size_t); 92 93 _CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_malloc (size_t, size_t); 94 _CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_realloc (void*, size_t, size_t); 95 _CRTIMP void* __cdecl __MINGW_NOTHROW _aligned_recalloc(void*, size_t, size_t, size_t); 96 _CRTIMP void __cdecl __MINGW_NOTHROW _aligned_free (void*); 97 98 /* These require libmingwex.a. */ 99 void * __cdecl __MINGW_NOTHROW __mingw_aligned_offset_malloc (size_t, size_t, size_t); 100 void * __cdecl __MINGW_NOTHROW __mingw_aligned_offset_realloc (void*, size_t, size_t, size_t); 101 102 void * __cdecl __MINGW_NOTHROW __mingw_aligned_malloc (size_t, size_t); 103 void * __cdecl __MINGW_NOTHROW __mingw_aligned_realloc (void*, size_t, size_t); 104 void __cdecl __MINGW_NOTHROW __mingw_aligned_free (void*); 105 106 #ifdef __cplusplus 107 } 108 #endif 109 110 #endif /* RC_INVOKED */ 111 112 #endif /* Not _MALLOC_H */ 113