ReactOS 0.4.16-dev-2104-gb84fa49
malloc.h File Reference
#include <corecrt.h>
#include <corecrt_malloc.h>
Include dependency graph for malloc.h:

Go to the source code of this file.

Classes

struct  _heapinfo
 

Macros

#define _HEAPEMPTY   -1
 
#define _HEAPOK   -2
 
#define _HEAPBADBEGIN   -3
 
#define _HEAPBADNODE   -4
 
#define _HEAPEND   -5
 
#define _HEAPBADPTR   -6
 
#define _FREEENTRY   0
 
#define _USEDENTRY   1
 
#define _HEAPINFO_DEFINED
 

Typedefs

typedef struct _heapinfo _HEAPINFO
 

Functions

_ACRTIMP int __cdecl _heapadd (void *, size_t)
 
_ACRTIMP int __cdecl _heapchk (void)
 
_ACRTIMP int __cdecl _heapmin (void)
 
_ACRTIMP int __cdecl _heapset (unsigned int)
 
_ACRTIMP size_t __cdecl _heapused (size_t *, size_t *)
 
_ACRTIMP int __cdecl _heapwalk (_HEAPINFO *)
 
_ACRTIMP intptr_t __cdecl _get_heap_handle (void)
 
_ACRTIMP size_t __cdecl _get_sbh_threshold (void)
 
_ACRTIMP int __cdecl _set_sbh_threshold (size_t size)
 

Variables

unsigned int _amblksiz
 

Macro Definition Documentation

◆ _FREEENTRY

#define _FREEENTRY   0

Definition at line 34 of file malloc.h.

◆ _HEAPBADBEGIN

#define _HEAPBADBEGIN   -3

Definition at line 29 of file malloc.h.

◆ _HEAPBADNODE

#define _HEAPBADNODE   -4

Definition at line 30 of file malloc.h.

◆ _HEAPBADPTR

#define _HEAPBADPTR   -6

Definition at line 32 of file malloc.h.

◆ _HEAPEMPTY

#define _HEAPEMPTY   -1

Definition at line 27 of file malloc.h.

◆ _HEAPEND

#define _HEAPEND   -5

Definition at line 31 of file malloc.h.

◆ _HEAPINFO_DEFINED

#define _HEAPINFO_DEFINED

Definition at line 38 of file malloc.h.

◆ _HEAPOK

#define _HEAPOK   -2

Definition at line 28 of file malloc.h.

◆ _USEDENTRY

#define _USEDENTRY   1

Definition at line 35 of file malloc.h.

Typedef Documentation

◆ _HEAPINFO

Function Documentation

◆ _get_heap_handle()

_ACRTIMP intptr_t __cdecl _get_heap_handle ( void  )

Definition at line 346 of file heap.c.

347{
348 return (intptr_t)heap;
349}
static HANDLE heap
Definition: heap.c:44
int intptr_t
Definition: corecrt.h:176

◆ _get_sbh_threshold()

_ACRTIMP size_t __cdecl _get_sbh_threshold ( void  )

Definition at line 515 of file heap.c.

516{
518}
static size_t MSVCRT_sbh_threshold
Definition: heap.c:54

◆ _heapadd()

_ACRTIMP int __cdecl _heapadd ( void mem,
size_t  size 
)

Definition at line 336 of file heap.c.

337{
338 TRACE("(%p,%Iu) unsupported in Win32\n", mem,size);
339 *_errno() = ENOSYS;
340 return -1;
341}
int *CDECL _errno(void)
Definition: errno.c:215
#define ENOSYS
Definition: errno.h:60
GLsizeiptr size
Definition: glext.h:5919
#define TRACE(s)
Definition: solgame.cpp:4
Definition: mem.c:349

◆ _heapchk()

_ACRTIMP int __cdecl _heapchk ( void  )

Definition at line 244 of file heap.c.

245{
246 if (!HeapValidate(heap, 0, NULL) ||
247 (sb_heap && !HeapValidate(sb_heap, 0, NULL)))
248 {
250 return _HEAPBADNODE;
251 }
252 return _HEAPOK;
253}
#define NULL
Definition: types.h:112
static HANDLE sb_heap
Definition: heap.c:44
#define _HEAPOK
Definition: malloc.h:28
#define _HEAPBADNODE
Definition: malloc.h:30
BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
Definition: heapmem.c:156
#define msvcrt_set_errno
Definition: heap.c:50
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ _heapmin()

_ACRTIMP int __cdecl _heapmin ( void  )

Definition at line 258 of file heap.c.

259{
260 if (!HeapCompact( heap, 0 ) ||
261 (sb_heap && !HeapCompact( sb_heap, 0 )))
262 {
265 return -1;
266 }
267 return 0;
268}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
SIZE_T WINAPI HeapCompact(HANDLE hHeap, DWORD dwFlags)
Definition: heapmem.c:145

◆ _heapset()

_ACRTIMP int __cdecl _heapset ( unsigned int  value)

Definition at line 317 of file heap.c.

318{
319 int retval;
321
322 memset( &heap, 0, sizeof(heap) );
323 LOCK_HEAP;
324 while ((retval = _heapwalk(&heap)) == _HEAPOK)
325 {
326 if (heap._useflag == _FREEENTRY)
327 memset(heap._pentry, value, heap._size);
328 }
330 return retval == _HEAPEND ? _HEAPOK : retval;
331}
#define UNLOCK_HEAP
Definition: heap.c:33
int CDECL _heapwalk(_HEAPINFO *next)
Definition: heap.c:273
#define LOCK_HEAP
Definition: heap.c:32
#define _HEAPEND
Definition: malloc.h:31
#define _FREEENTRY
Definition: malloc.h:34
#define memset(x, y, z)
Definition: compat.h:39
Definition: pdh_main.c:96
int retval
Definition: wcstombs.cpp:91

◆ _heapused()

_ACRTIMP size_t __cdecl _heapused ( size_t pUsed,
size_t pCommit 
)

Definition at line 22 of file stubs.c.

23{
25 return( 0 );
26}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15

◆ _heapwalk()

_ACRTIMP int __cdecl _heapwalk ( _HEAPINFO next)

Definition at line 273 of file heap.c.

274{
276
277 if (sb_heap)
278 FIXME("small blocks heap not supported\n");
279
280 LOCK_HEAP;
281 phe.lpData = next->_pentry;
282 phe.cbData = next->_size;
283 phe.wFlags = next->_useflag == _USEDENTRY ? PROCESS_HEAP_ENTRY_BUSY : 0;
284
285 if (phe.lpData && phe.wFlags & PROCESS_HEAP_ENTRY_BUSY &&
286 !HeapValidate( heap, 0, phe.lpData ))
287 {
290 return _HEAPBADNODE;
291 }
292
293 do
294 {
295 if (!HeapWalk( heap, &phe ))
296 {
299 return _HEAPEND;
301 if (!phe.lpData)
302 return _HEAPBADBEGIN;
303 return _HEAPBADNODE;
304 }
306
308 next->_pentry = phe.lpData;
309 next->_size = phe.cbData;
311 return _HEAPOK;
312}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define _HEAPBADBEGIN
Definition: malloc.h:29
#define _USEDENTRY
Definition: malloc.h:35
BOOL WINAPI HeapWalk(HANDLE hHeap, LPPROCESS_HEAP_ENTRY lpEntry)
Definition: heapmem.c:291
#define PROCESS_HEAP_UNCOMMITTED_RANGE
Definition: minwinbase.h:76
#define PROCESS_HEAP_ENTRY_BUSY
Definition: minwinbase.h:77
#define PROCESS_HEAP_REGION
Definition: minwinbase.h:75
static unsigned __int64 next
Definition: rand_nt.c:6
Definition: minwinbase.h:361
WORD wFlags
Definition: minwinbase.h:366
PVOID lpData
Definition: minwinbase.h:362
DWORD cbData
Definition: minwinbase.h:363

Referenced by _heapset().

◆ _set_sbh_threshold()

_ACRTIMP int __cdecl _set_sbh_threshold ( size_t  size)

Definition at line 523 of file heap.c.

524{
525#ifdef _WIN64
526 return 0;
527#else
528 if(threshold > 1016)
529 return 0;
530
531 if(!sb_heap)
532 {
533 sb_heap = HeapCreate(0, 0, 0);
534 if(!sb_heap)
535 return 0;
536 }
537
538 MSVCRT_sbh_threshold = (threshold+0xf) & ~0xf;
539 return 1;
540#endif
541}
HANDLE WINAPI HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
Definition: heapmem.c:45

Variable Documentation

◆ _amblksiz

unsigned int _amblksiz
extern