ReactOS  0.4.13-dev-651-g5dbc677
heap.c File Reference
#include <precomp.h>
#include <malloc.h>
Include dependency graph for heap.c:

Go to the source code of this file.

Macros

#define LOCK_HEAP   _mlock( _HEAP_LOCK )
 
#define UNLOCK_HEAP   _munlock( _HEAP_LOCK )
 
#define SAVED_PTR(x)
 
#define ALIGN_PTR(ptr, alignment, offset)
 

Typedefs

typedef int(CDECLMSVCRT_new_handler_func) (size_t size)
 

Functions

void *CDECL MSVCRT_operator_new (size_t size)
 
void *CDECL MSVCRT_operator_new_dbg (size_t size, int type, const char *file, int line)
 
void CDECL MSVCRT_operator_delete (void *mem)
 
MSVCRT_new_handler_func CDECL MSVCRT__query_new_handler (void)
 
int CDECL MSVCRT__query_new_mode (void)
 
MSVCRT_new_handler_func CDECL MSVCRT__set_new_handler (MSVCRT_new_handler_func func)
 
MSVCRT_new_handler_func CDECL MSVCRT_set_new_handler (void *func)
 
int CDECL MSVCRT__set_new_mode (int mode)
 
int CDECL _callnewh (size_t size)
 
void *CDECL _expand (void *mem, size_t size)
 
int CDECL _heapchk (void)
 
int CDECL _heapmin (void)
 
int CDECL _heapwalk (_HEAPINFO *next)
 
int CDECL _heapset (unsigned int value)
 
int CDECL _heapadd (void *mem, size_t size)
 
intptr_t CDECL _get_heap_handle (void)
 
size_t CDECL _msize (void *mem)
 
void *CDECL calloc (size_t count, size_t size)
 
void CDECL free (void *ptr)
 
void *CDECL malloc (size_t size)
 
void *CDECL realloc (void *ptr, size_t size)
 
unsigned int *CDECL __p__amblksiz (void)
 
size_t CDECL _get_sbh_threshold (void)
 
int CDECL _set_sbh_threshold (size_t threshold)
 
void CDECL _aligned_free (void *memblock)
 
void *CDECL _aligned_offset_malloc (size_t size, size_t alignment, size_t offset)
 
void *CDECL _aligned_malloc (size_t size, size_t alignment)
 
void *CDECL _aligned_offset_realloc (void *memblock, size_t size, size_t alignment, size_t offset)
 
void *CDECL _aligned_realloc (void *memblock, size_t size, size_t alignment)
 
int CDECL memmove_s (void *dest, size_t numberOfElements, const void *src, size_t count)
 
int CDECL strncpy_s (char *dest, size_t numberOfElements, const char *src, size_t count)
 

Variables

static MSVCRT_new_handler_func MSVCRT_new_handler
 
static int MSVCRT_new_mode
 
static unsigned int MSVCRT_amblksiz = 16
 
static size_t MSVCRT_sbh_threshold = 0
 

Macro Definition Documentation

◆ ALIGN_PTR

#define ALIGN_PTR (   ptr,
  alignment,
  offset 
)
Value:
((void *) \
((((DWORD_PTR)((char *)ptr + alignment + sizeof(void *) + offset)) & \
~(alignment - 1)) - offset))
GLintptr offset
Definition: glext.h:5920
static PVOID ptr
Definition: dispmode.c:27
uint32_t DWORD_PTR
Definition: typedefs.h:63

Definition at line 34 of file heap.c.

◆ LOCK_HEAP

#define LOCK_HEAP   _mlock( _HEAP_LOCK )

Definition at line 28 of file heap.c.

◆ SAVED_PTR

#define SAVED_PTR (   x)
Value:
((void *)((DWORD_PTR)((char *)x - sizeof(void *)) & \
~(sizeof(void *) - 1)))
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
uint32_t DWORD_PTR
Definition: typedefs.h:63

Definition at line 32 of file heap.c.

◆ UNLOCK_HEAP

#define UNLOCK_HEAP   _munlock( _HEAP_LOCK )

Definition at line 29 of file heap.c.

Typedef Documentation

◆ MSVCRT_new_handler_func

typedef int(CDECL * MSVCRT_new_handler_func) (size_t size)

Definition at line 39 of file heap.c.

Function Documentation

◆ __p__amblksiz()

unsigned int* CDECL __p__amblksiz ( void  )

Definition at line 330 of file heap.c.

331 {
332  return &MSVCRT_amblksiz;
333 }
static unsigned int MSVCRT_amblksiz
Definition: heap.c:45

◆ _aligned_free()

void CDECL _aligned_free ( void memblock)

Definition at line 358 of file heap.c.

359 {
360  TRACE("(%p)\n", memblock);
361 
362  if (memblock)
363  {
364  void **saved = SAVED_PTR(memblock);
365  free(*saved);
366  }
367 }
void CDECL free(void *ptr)
Definition: heap.c:299
#define SAVED_PTR(x)
Definition: heap.c:32
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by _aligned_offset_realloc().

◆ _aligned_malloc()

void* CDECL _aligned_malloc ( size_t  size,
size_t  alignment 
)

Definition at line 415 of file heap.c.

416 {
417  TRACE("(%lu, %lu)\n", size, alignment);
418  return _aligned_offset_malloc(size, alignment, 0);
419 }
void *CDECL _aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
Definition: heap.c:372
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919

◆ _aligned_offset_malloc()

void* CDECL _aligned_offset_malloc ( size_t  size,
size_t  alignment,
size_t  offset 
)

Definition at line 372 of file heap.c.

373 {
374  void *memblock, *temp, **saved;
375  TRACE("(%lu, %lu, %lu)\n", size, alignment, offset);
376 
377  /* alignment must be a power of 2 */
378  if ((alignment & (alignment - 1)) != 0)
379  {
380  *_errno() = EINVAL;
381  return NULL;
382  }
383 
384  /* offset must be less than size */
385  if (offset >= size)
386  {
387  *_errno() = EINVAL;
388  return NULL;
389  }
390 
391  /* don't align to less than void pointer size */
392  if (alignment < sizeof(void *))
393  alignment = sizeof(void *);
394 
395  /* allocate enough space for void pointer and alignment */
396  temp = malloc(size + alignment + sizeof(void *));
397 
398  if (!temp)
399  return NULL;
400 
401  /* adjust pointer for proper alignment and offset */
402  memblock = ALIGN_PTR(temp, alignment, offset);
403 
404  /* Save the real allocation address below returned address */
405  /* so it can be found later to free. */
406  saved = SAVED_PTR(memblock);
407  *saved = temp;
408 
409  return memblock;
410 }
Definition: arc.h:39
GLintptr offset
Definition: glext.h:5920
void *CDECL malloc(size_t size)
Definition: heap.c:308
#define ALIGN_PTR(ptr, alignment, offset)
Definition: heap.c:34
smooth NULL
Definition: ftsmooth.c:416
#define SAVED_PTR(x)
Definition: heap.c:32
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
static calc_node_t temp
Definition: rpn_ieee.c:38

Referenced by _aligned_malloc(), and _aligned_offset_realloc().

◆ _aligned_offset_realloc()

void* CDECL _aligned_offset_realloc ( void memblock,
size_t  size,
size_t  alignment,
size_t  offset 
)

Definition at line 424 of file heap.c.

426 {
427  void * temp, **saved;
428  size_t old_padding, new_padding, old_size;
429  TRACE("(%p, %lu, %lu, %lu)\n", memblock, size, alignment, offset);
430 
431  if (!memblock)
432  return _aligned_offset_malloc(size, alignment, offset);
433 
434  /* alignment must be a power of 2 */
435  if ((alignment & (alignment - 1)) != 0)
436  {
437  *_errno() = EINVAL;
438  return NULL;
439  }
440 
441  /* offset must be less than size */
442  if (offset >= size)
443  {
444  *_errno() = EINVAL;
445  return NULL;
446  }
447 
448  if (size == 0)
449  {
450  _aligned_free(memblock);
451  return NULL;
452  }
453 
454  /* don't align to less than void pointer size */
455  if (alignment < sizeof(void *))
456  alignment = sizeof(void *);
457 
458  /* make sure alignment and offset didn't change */
459  saved = SAVED_PTR(memblock);
460  if (memblock != ALIGN_PTR(*saved, alignment, offset))
461  {
462  *_errno() = EINVAL;
463  return NULL;
464  }
465 
466  old_padding = (char *)memblock - (char *)*saved;
467 
468  /* Get previous size of block */
469  old_size = _msize(*saved);
470  if (old_size == -1)
471  {
472  /* It seems this function was called with an invalid pointer. Bail out. */
473  return NULL;
474  }
475 
476  /* Adjust old_size to get amount of actual data in old block. */
477  if (old_size < old_padding)
478  {
479  /* Shouldn't happen. Something's weird, so bail out. */
480  return NULL;
481  }
482  old_size -= old_padding;
483 
484  temp = realloc(*saved, size + alignment + sizeof(void *));
485 
486  if (!temp)
487  return NULL;
488 
489  /* adjust pointer for proper alignment and offset */
490  memblock = ALIGN_PTR(temp, alignment, offset);
491 
492  /* Save the real allocation address below returned address */
493  /* so it can be found later to free. */
494  saved = SAVED_PTR(memblock);
495 
496  new_padding = (char *)memblock - (char *)temp;
497 
498 /*
499  Memory layout of old block is as follows:
500  +-------+---------------------+-+--------------------------+-----------+
501  | ... | "old_padding" bytes | | ... "old_size" bytes ... | ... |
502  +-------+---------------------+-+--------------------------+-----------+
503  ^ ^ ^
504  | | |
505  *saved saved memblock
506 
507  Memory layout of new block is as follows:
508  +-------+-----------------------------+-+----------------------+-------+
509  | ... | "new_padding" bytes | | ... "size" bytes ... | ... |
510  +-------+-----------------------------+-+----------------------+-------+
511  ^ ^ ^
512  | | |
513  temp saved memblock
514 
515  However, in the new block, actual data is still written as follows
516  (because it was copied by MSVCRT_realloc):
517  +-------+---------------------+--------------------------------+-------+
518  | ... | "old_padding" bytes | ... "old_size" bytes ... | ... |
519  +-------+---------------------+--------------------------------+-------+
520  ^ ^ ^
521  | | |
522  temp saved memblock
523 
524  Therefore, min(old_size,size) bytes of actual data have to be moved
525  from the offset they were at in the old block (temp + old_padding),
526  to the offset they have to be in the new block (temp + new_padding == memblock).
527 */
528  if (new_padding != old_padding)
529  memmove((char *)memblock, (char *)temp + old_padding, (old_size < size) ? old_size : size);
530 
531  *saved = temp;
532 
533  return memblock;
534 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
Definition: arc.h:39
GLintptr offset
Definition: glext.h:5920
void *CDECL realloc(void *ptr, size_t size)
Definition: heap.c:319
void *CDECL _aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
Definition: heap.c:372
#define ALIGN_PTR(ptr, alignment, offset)
Definition: heap.c:34
smooth NULL
Definition: ftsmooth.c:416
#define SAVED_PTR(x)
Definition: heap.c:32
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
void CDECL _aligned_free(void *memblock)
Definition: heap.c:358
static calc_node_t temp
Definition: rpn_ieee.c:38
size_t CDECL _msize(void *mem)
Definition: heap.c:277

Referenced by _aligned_realloc().

◆ _aligned_realloc()

void* CDECL _aligned_realloc ( void memblock,
size_t  size,
size_t  alignment 
)

Definition at line 539 of file heap.c.

540 {
541  TRACE("(%p, %lu, %lu)\n", memblock, size, alignment);
542  return _aligned_offset_realloc(memblock, size, alignment, 0);
543 }
void *CDECL _aligned_offset_realloc(void *memblock, size_t size, size_t alignment, size_t offset)
Definition: heap.c:424
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919

◆ _callnewh()

int CDECL _callnewh ( size_t  size)

Definition at line 154 of file heap.c.

155 {
157  (*MSVCRT_new_handler)(size);
158  return 0;
159 }
GLsizeiptr size
Definition: glext.h:5919
static MSVCRT_new_handler_func MSVCRT_new_handler
Definition: heap.c:41

◆ _expand()

void* CDECL _expand ( void mem,
size_t  size 
)

Definition at line 164 of file heap.c.

165 {
167 }
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
#define HeapReAlloc
Definition: compat.h:393
Definition: mem.c:156
#define HEAP_REALLOC_IN_PLACE_ONLY
Definition: nt_native.h:1696

◆ _get_heap_handle()

intptr_t CDECL _get_heap_handle ( void  )

Definition at line 269 of file heap.c.

270 {
271  return (intptr_t)GetProcessHeap();
272 }
#define GetProcessHeap()
Definition: compat.h:395
int intptr_t
Definition: crtdefs.h:283

◆ _get_sbh_threshold()

size_t CDECL _get_sbh_threshold ( void  )

Definition at line 338 of file heap.c.

339 {
340  return MSVCRT_sbh_threshold;
341 }
static size_t MSVCRT_sbh_threshold
Definition: heap.c:47

Referenced by test_sbheap().

◆ _heapadd()

int CDECL _heapadd ( void mem,
size_t  size 
)

Definition at line 259 of file heap.c.

260 {
261  TRACE("(%p,%ld) unsupported in Win32\n", mem,size);
262  *_errno() = ENOSYS;
263  return -1;
264 }
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define ENOSYS
Definition: errno.h:45
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
Definition: mem.c:156

◆ _heapchk()

int CDECL _heapchk ( void  )

Definition at line 172 of file heap.c.

173 {
174  if (!HeapValidate( GetProcessHeap(), 0, NULL))
175  {
177  return _HEAPBADNODE;
178  }
179  return _HEAPOK;
180 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
Definition: heapmem.c:156
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define _HEAPBADNODE
Definition: malloc.h:35
#define _HEAPOK
Definition: malloc.h:33

◆ _heapmin()

int CDECL _heapmin ( void  )

Definition at line 185 of file heap.c.

186 {
187  if (!HeapCompact( GetProcessHeap(), 0 ))
188  {
191  return -1;
192  }
193  return 0;
194 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define GetProcessHeap()
Definition: compat.h:395
SIZE_T WINAPI HeapCompact(HANDLE hHeap, DWORD dwFlags)
Definition: heapmem.c:145
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ _heapset()

int CDECL _heapset ( unsigned int  value)

Definition at line 240 of file heap.c.

241 {
242  int retval;
243  _HEAPINFO heap;
244 
245  memset( &heap, 0, sizeof(heap) );
246  LOCK_HEAP;
247  while ((retval = _heapwalk(&heap)) == _HEAPOK)
248  {
249  if (heap._useflag == _FREEENTRY)
250  memset(heap._pentry, value, heap._size);
251  }
252  UNLOCK_HEAP;
253  return retval == _HEAPEND? _HEAPOK : retval;
254 }
#define _FREEENTRY
Definition: malloc.h:40
size_t _size
Definition: malloc.h:48
#define _HEAPEND
Definition: malloc.h:36
#define LOCK_HEAP
Definition: heap.c:28
int _useflag
Definition: malloc.h:49
int CDECL _heapwalk(_HEAPINFO *next)
Definition: heap.c:199
#define UNLOCK_HEAP
Definition: heap.c:29
#define _HEAPOK
Definition: malloc.h:33
int * _pentry
Definition: malloc.h:47
#define memset(x, y, z)
Definition: compat.h:39

◆ _heapwalk()

int CDECL _heapwalk ( _HEAPINFO next)

Definition at line 199 of file heap.c.

200 {
201  PROCESS_HEAP_ENTRY phe;
202 
203  LOCK_HEAP;
204  phe.lpData = next->_pentry;
205  phe.cbData = (DWORD)next->_size;
206  phe.wFlags = next->_useflag == _USEDENTRY ? PROCESS_HEAP_ENTRY_BUSY : 0;
207 
208  if (phe.lpData && phe.wFlags & PROCESS_HEAP_ENTRY_BUSY &&
209  !HeapValidate( GetProcessHeap(), 0, phe.lpData ))
210  {
211  UNLOCK_HEAP;
213  return _HEAPBADNODE;
214  }
215 
216  do
217  {
218  if (!HeapWalk( GetProcessHeap(), &phe ))
219  {
220  UNLOCK_HEAP;
222  return _HEAPEND;
224  if (!phe.lpData)
225  return _HEAPBADBEGIN;
226  return _HEAPBADNODE;
227  }
229 
230  UNLOCK_HEAP;
231  next->_pentry = phe.lpData;
232  next->_size = phe.cbData;
234  return _HEAPOK;
235 }
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
#define PROCESS_HEAP_UNCOMMITTED_RANGE
Definition: winbase.h:332
#define _HEAPBADBEGIN
Definition: malloc.h:34
#define _FREEENTRY
Definition: malloc.h:40
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
Definition: heapmem.c:156
#define DWORD
Definition: nt_native.h:44
#define PROCESS_HEAP_REGION
Definition: winbase.h:331
#define _HEAPEND
Definition: malloc.h:36
#define PROCESS_HEAP_ENTRY_BUSY
Definition: winbase.h:333
BOOL WINAPI HeapWalk(HANDLE hHeap, LPPROCESS_HEAP_ENTRY lpEntry)
Definition: heapmem.c:291
#define GetProcessHeap()
Definition: compat.h:395
if(!(yy_init))
Definition: macro.lex.yy.c:714
DWORD cbData
Definition: winbase.h:1223
#define LOCK_HEAP
Definition: heap.c:28
Definition: winbase.h:1221
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
static unsigned __int64 next
Definition: rand_nt.c:6
#define _USEDENTRY
Definition: malloc.h:41
#define _HEAPBADNODE
Definition: malloc.h:35
#define UNLOCK_HEAP
Definition: heap.c:29
#define _HEAPOK
Definition: malloc.h:33
WORD wFlags
Definition: winbase.h:1226
PVOID lpData
Definition: winbase.h:1222

Referenced by _heapset().

◆ _msize()

size_t CDECL _msize ( void mem)

Definition at line 277 of file heap.c.

278 {
279  size_t size = HeapSize(GetProcessHeap(),0,mem);
280  if (size == ~(size_t)0)
281  {
282  WARN(":Probably called with non wine-allocated memory, ret = -1\n");
283  /* At least the Win32 crtdll/msvcrt also return -1 in this case */
284  }
285  return size;
286 }
#define WARN(fmt,...)
Definition: debug.h:111
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
Definition: mem.c:156

Referenced by _aligned_offset_realloc().

◆ _set_sbh_threshold()

int CDECL _set_sbh_threshold ( size_t  threshold)

Definition at line 346 of file heap.c.

347 {
348  if(threshold > 1016)
349  return 0;
350  else
351  MSVCRT_sbh_threshold = threshold;
352  return 1;
353 }
static size_t MSVCRT_sbh_threshold
Definition: heap.c:47

Referenced by test_sbheap().

◆ calloc()

void* CDECL calloc ( size_t  count,
size_t  size 
)

Definition at line 291 of file heap.c.

292 {
294 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define HEAP_ZERO_MEMORY
Definition: compat.h:123

Referenced by test_calloc().

◆ free()

void CDECL free ( void ptr)

Definition at line 299 of file heap.c.

300 {
301  if(ptr == NULL) return;
303 }
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by _aligned_free(), realloc(), START_TEST(), test_aligned_offset_realloc(), test_aligned_realloc(), test_calloc(), and test_sbheap().

◆ malloc()

void* CDECL malloc ( size_t  size)

Definition at line 308 of file heap.c.

309 {
310  void *ret = HeapAlloc(GetProcessHeap(),0,size);
311  if (!ret)
312  *_errno() = ENOMEM;
313  return ret;
314 }
Definition: arc.h:48
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret

Referenced by _aligned_offset_malloc(), realloc(), START_TEST(), test_aligned_offset_realloc(), test_aligned_realloc(), and test_sbheap().

◆ memmove_s()

int CDECL memmove_s ( void dest,
size_t  numberOfElements,
const void src,
size_t  count 
)

Definition at line 548 of file heap.c.

549 {
550  TRACE("(%p %lu %p %lu)\n", dest, numberOfElements, src, count);
551 
552  if(!count)
553  return 0;
554 
555  if(!dest || !src) {
556  if(dest)
558 
559  *_errno() = EINVAL;
560  return EINVAL;
561  }
562 
563  if(count > numberOfElements) {
565 
566  *_errno() = ERANGE;
567  return ERANGE;
568  }
569 
570  memmove(dest, src, count);
571  return 0;
572 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
Definition: arc.h:39
GLuint GLuint GLsizei count
Definition: gl.h:1545
static size_t numberOfElements
Definition: string.c:87
#define TRACE(s)
Definition: solgame.cpp:4
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define ERANGE
Definition: acclib.h:92
GLenum src
Definition: glext.h:6340
static char * dest
Definition: rtl.c:135
#define memset(x, y, z)
Definition: compat.h:39

Referenced by ATL::CElementTraitsBase< T >::RelocateElements().

◆ MSVCRT__query_new_handler()

MSVCRT_new_handler_func CDECL MSVCRT__query_new_handler ( void  )

Definition at line 101 of file heap.c.

102 {
103  return MSVCRT_new_handler;
104 }
static MSVCRT_new_handler_func MSVCRT_new_handler
Definition: heap.c:41

◆ MSVCRT__query_new_mode()

int CDECL MSVCRT__query_new_mode ( void  )

Definition at line 110 of file heap.c.

111 {
112  return MSVCRT_new_mode;
113 }
static int MSVCRT_new_mode
Definition: heap.c:42

◆ MSVCRT__set_new_handler()

MSVCRT_new_handler_func CDECL MSVCRT__set_new_handler ( MSVCRT_new_handler_func  func)

Definition at line 118 of file heap.c.

119 {
120  MSVCRT_new_handler_func old_handler;
121  LOCK_HEAP;
122  old_handler = MSVCRT_new_handler;
124  UNLOCK_HEAP;
125  return old_handler;
126 }
GLenum func
Definition: glext.h:6028
int(CDECL * MSVCRT_new_handler_func)(size_t size)
Definition: heap.c:39
#define LOCK_HEAP
Definition: heap.c:28
static MSVCRT_new_handler_func MSVCRT_new_handler
Definition: heap.c:41
#define UNLOCK_HEAP
Definition: heap.c:29

Referenced by MSVCRT_set_new_handler().

◆ MSVCRT__set_new_mode()

int CDECL MSVCRT__set_new_mode ( int  mode)

Definition at line 141 of file heap.c.

142 {
143  int old_mode;
144  LOCK_HEAP;
145  old_mode = MSVCRT_new_mode;
147  UNLOCK_HEAP;
148  return old_mode;
149 }
static int MSVCRT_new_mode
Definition: heap.c:42
#define LOCK_HEAP
Definition: heap.c:28
GLenum mode
Definition: glext.h:6217
#define UNLOCK_HEAP
Definition: heap.c:29

◆ MSVCRT_operator_delete()

◆ MSVCRT_operator_new()

void* CDECL MSVCRT_operator_new ( size_t  )
  • FIXME: This should be declared in new.h but it's not an extern "C" so

Definition at line 52 of file heap.c.

53 {
54  void *retval;
55  int freed;
56 
57  do
58  {
59  retval = HeapAlloc(GetProcessHeap(), 0, size);
60  if(retval)
61  {
62  TRACE("(%ld) returning %p\n", size, retval);
63  return retval;
64  }
65 
66  LOCK_HEAP;
68  freed = (*MSVCRT_new_handler)(size);
69  else
70  freed = 0;
72  } while(freed);
73 
74  TRACE("(%ld) out of memory\n", size);
75  return NULL;
76 }
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define LOCK_HEAP
Definition: heap.c:28
static MSVCRT_new_handler_func MSVCRT_new_handler
Definition: heap.c:41
#define UNLOCK_HEAP
Definition: heap.c:29

Referenced by MSVCRT_operator_new_dbg().

◆ MSVCRT_operator_new_dbg()

void* CDECL MSVCRT_operator_new_dbg ( size_t  size,
int  type,
const char file,
int  line 
)

Definition at line 82 of file heap.c.

83 {
84  return MSVCRT_operator_new( size );
85 }
void *CDECL MSVCRT_operator_new(size_t size)
Definition: heap.c:52
GLsizeiptr size
Definition: glext.h:5919

◆ MSVCRT_set_new_handler()

MSVCRT_new_handler_func CDECL MSVCRT_set_new_handler ( void func)

Definition at line 131 of file heap.c.

132 {
133  TRACE("(%p)\n",func);
135  return NULL;
136 }
GLenum func
Definition: glext.h:6028
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
MSVCRT_new_handler_func CDECL MSVCRT__set_new_handler(MSVCRT_new_handler_func func)
Definition: heap.c:118

◆ realloc()

void* CDECL realloc ( void ptr,
size_t  size 
)

Definition at line 319 of file heap.c.

320 {
321  if (!ptr) return malloc(size);
322  if (size) return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
323  free(ptr);
324  return NULL;
325 }
void CDECL free(void *ptr)
Definition: heap.c:299
void *CDECL malloc(size_t size)
Definition: heap.c:308
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
#define HeapReAlloc
Definition: compat.h:393

Referenced by _aligned_offset_realloc(), START_TEST(), and test_sbheap().

◆ strncpy_s()

int CDECL strncpy_s ( char dest,
size_t  numberOfElements,
const char src,
size_t  count 
)

Definition at line 577 of file heap.c.

579 {
580  size_t i, end;
581 
582  TRACE("(%s %lu %s %lu)\n", dest, numberOfElements, src, count);
583 
584  if(!count)
585  return 0;
586 
587  if (!MSVCRT_CHECK_PMT(dest != NULL) || !MSVCRT_CHECK_PMT(src != NULL) ||
589  *_errno() = EINVAL;
590  return EINVAL;
591  }
592 
594  end = count;
595  else
596  end = numberOfElements-1;
597 
598  for(i=0; i<end && src[i]; i++)
599  dest[i] = src[i];
600 
601  if(!src[i] || end==count || count==_TRUNCATE) {
602  dest[i] = '\0';
603  return 0;
604  }
605 
606  MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL);
607  dest[0] = '\0';
608  return EINVAL;
609 }
Definition: arc.h:39
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
static size_t numberOfElements
Definition: string.c:87
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MSVCRT_INVALID_PMT(x)
Definition: mbstowcs_s.c:25
smooth NULL
Definition: ftsmooth.c:416
#define _TRUNCATE
Definition: crtdefs.h:241
#define TRACE(s)
Definition: solgame.cpp:4
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
GLenum src
Definition: glext.h:6340
static char * dest
Definition: rtl.c:135

Referenced by __Named_exception::__Named_exception(), and __Named_exception::operator=().

Variable Documentation

◆ MSVCRT_amblksiz

unsigned int MSVCRT_amblksiz = 16
static

Definition at line 45 of file heap.c.

Referenced by __p__amblksiz().

◆ MSVCRT_new_handler

MSVCRT_new_handler_func MSVCRT_new_handler
static

◆ MSVCRT_new_mode

int MSVCRT_new_mode
static

Definition at line 42 of file heap.c.

Referenced by MSVCRT__query_new_mode(), and MSVCRT__set_new_mode().

◆ MSVCRT_sbh_threshold

size_t MSVCRT_sbh_threshold = 0
static

Definition at line 47 of file heap.c.

Referenced by _get_sbh_threshold(), and _set_sbh_threshold().