Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmalloc.c
Go to the documentation of this file.
00001 /* 00002 * msvcrt.dll heap functions 00003 * 00004 * Copyright 2000 Jon Griffiths 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 * Note: Win32 heap operations are MT safe. We only lock the new 00021 * handler and non atomic heap operations 00022 */ 00023 00024 #include <precomp.h> 00025 #include <stdlib.h> 00026 #include <malloc.h> 00027 00028 #define ROUND_DOWN(n, align) \ 00029 (((ULONG)n) & ~((align) - 1l)) 00030 00031 #define ROUND_UP(n, align) \ 00032 ROUND_DOWN(((ULONG)n) + (align) - 1, (align)) 00033 00034 /* round to 16 bytes + alloc at minimum 16 bytes */ 00035 #define ROUND_SIZE(size) (max(16, ROUND_UP(size, 16))) 00036 00037 /* 00038 * @implemented 00039 */ 00040 void* malloc(size_t _size) 00041 { 00042 size_t nSize = ROUND_SIZE(_size); 00043 00044 if (nSize<_size) 00045 return NULL; 00046 00047 return HeapAlloc(GetProcessHeap(), 0, nSize); 00048 } 00049 00050 /* 00051 * @implemented 00052 */ 00053 void free(void* _ptr) 00054 { 00055 HeapFree(GetProcessHeap(),0,_ptr); 00056 } 00057 00058 /* 00059 * @implemented 00060 */ 00061 void* calloc(size_t _nmemb, size_t _size) 00062 { 00063 size_t nSize = _nmemb * _size; 00064 size_t cSize = ROUND_SIZE(nSize); 00065 00066 if ( (_nmemb > ((size_t)-1 / _size)) || (cSize<nSize)) 00067 return NULL; 00068 00069 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cSize ); 00070 } 00071 00072 /* 00073 * @implemented 00074 */ 00075 void* realloc(void* _ptr, size_t _size) 00076 { 00077 size_t nSize; 00078 00079 if (_ptr == NULL) 00080 return malloc(_size); 00081 00082 if (_size == 0) 00083 { 00084 free(_ptr); 00085 return NULL; 00086 } 00087 00088 nSize = ROUND_SIZE(_size); 00089 00090 /* check for integer overflow */ 00091 if (nSize<_size) 00092 return NULL; 00093 00094 return HeapReAlloc(GetProcessHeap(), 0, _ptr, nSize); 00095 } 00096 00097 /* 00098 * @implemented 00099 */ 00100 void* _expand(void* _ptr, size_t _size) 00101 { 00102 size_t nSize; 00103 00104 nSize = ROUND_SIZE(_size); 00105 00106 if (nSize<_size) 00107 return NULL; 00108 00109 return HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, _ptr, nSize); 00110 } 00111 00112 /* 00113 * @implemented 00114 */ 00115 size_t _msize(void* _ptr) 00116 { 00117 return HeapSize(GetProcessHeap(), 0, _ptr); 00118 } 00119 00120 /* 00121 * @implemented 00122 */ 00123 int _heapchk(void) 00124 { 00125 if (!HeapValidate(GetProcessHeap(), 0, NULL)) 00126 return -1; 00127 return 0; 00128 } 00129 00130 /* 00131 * @implemented 00132 */ 00133 int _heapmin(void) 00134 { 00135 if (!HeapCompact(GetProcessHeap(), 0)) 00136 return -1; 00137 return 0; 00138 } 00139 00140 /* 00141 * @implemented 00142 */ 00143 int _heapset(unsigned int unFill) 00144 { 00145 if (_heapchk() == -1) 00146 return -1; 00147 return 0; 00148 00149 } 00150 00151 /* 00152 * @implemented 00153 */ 00154 int _heapwalk(struct _heapinfo* entry) 00155 { 00156 return 0; 00157 } 00158 Generated on Sun May 27 2012 04:25:53 for ReactOS by
1.7.6.1
|