summary refs log tree commit diff stats
path: root/tinyc/win32/include/malloc.h
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-11-02 10:46:30 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-11-02 10:46:30 +0100
commit1eaeccc15d15d15d2f62ea1648f7dd64722dbd37 (patch)
treeb922cdabc780fa3a8837a6804d2df31793d9e2ca /tinyc/win32/include/malloc.h
parente9243a16167b24899d4fcf051f3252b3a5804811 (diff)
parentbd19b5f4d36bb40b4af93d7e15fdfa582e9fe3b7 (diff)
downloadNim-1eaeccc15d15d15d2f62ea1648f7dd64722dbd37.tar.gz
Merge branch 'devel' into araq
Diffstat (limited to 'tinyc/win32/include/malloc.h')
-rw-r--r--tinyc/win32/include/malloc.h226
1 files changed, 160 insertions, 66 deletions
diff --git a/tinyc/win32/include/malloc.h b/tinyc/win32/include/malloc.h
index ca4259689..fc783a8e3 100644
--- a/tinyc/win32/include/malloc.h
+++ b/tinyc/win32/include/malloc.h
@@ -1,87 +1,181 @@
-/*
- * malloc.h
- *
- * Support for programs which want to use malloc.h to get memory management
- * functions. Unless you absolutely need some of these functions and they are
- * not in the ANSI headers you should use the ANSI standard header files
- * instead.
- *
- * This file is part of the Mingw32 package.
- *
- * Contributors:
- *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
- *
- *  THIS SOFTWARE IS NOT COPYRIGHTED
- *
- *  This source code is offered for use in the public domain. You may
- *  use, modify or distribute it freely.
- *
- *  This code is distributed in the hope that it will be useful but
- *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
- *  DISCLAIMED. This includes but is not limited to warranties of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * $Revision: 1.2 $
- * $Author: bellard $
- * $Date: 2005/04/17 13:14:29 $
- *
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the w64 mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER within this package.
  */
-
-#ifndef	__STRICT_ANSI__
-
 #ifndef _MALLOC_H_
 #define _MALLOC_H_
 
-/* All the headers include this file. */
 #include <_mingw.h>
 
-#include <stdlib.h>
+#pragma pack(push,_CRT_PACKING)
 
-#ifndef RC_INVOKED
+#ifndef _MM_MALLOC_H_INCLUDED
+#define _MM_MALLOC_H_INCLUDED
+#endif
 
-/*
- * The structure used to walk through the heap with _heapwalk.
- */
-typedef	struct _heapinfo
-{
-	int*	_pentry;
-	size_t	_size;
-	int	_useflag;
-} _HEAPINFO;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef _WIN64
+#define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
+#else
+#define _HEAP_MAXREQ 0xFFFFFFE0
+#endif
+
+#ifndef _STATIC_ASSERT
+#define _STATIC_ASSERT(expr) extern void __static_assert_t(int [(expr)?1:-1])
+#endif
+
+/* Return codes for _heapwalk()  */
+#define _HEAPEMPTY (-1)
+#define _HEAPOK (-2)
+#define _HEAPBADBEGIN (-3)
+#define _HEAPBADNODE (-4)
+#define _HEAPEND (-5)
+#define _HEAPBADPTR (-6)
 
 /* Values for _heapinfo.useflag */
-#define _USEDENTRY 0
-#define _FREEENTRY 1
+#define _FREEENTRY 0
+#define _USEDENTRY 1
+
+#ifndef _HEAPINFO_DEFINED
+#define _HEAPINFO_DEFINED
+ /* The structure used to walk through the heap with _heapwalk.  */
+  typedef struct _heapinfo {
+    int *_pentry;
+    size_t _size;
+    int _useflag;
+  } _HEAPINFO;
+#endif
 
-#ifdef	__cplusplus
-extern "C" {
+  extern unsigned int _amblksiz;
+
+#define _mm_free(a) _aligned_free(a)
+#define _mm_malloc(a,b) _aligned_malloc(a,b)
+
+#ifndef _CRT_ALLOCATION_DEFINED
+#define _CRT_ALLOCATION_DEFINED
+  void *__cdecl calloc(size_t _NumOfElements,size_t _SizeOfElements);
+  void __cdecl free(void *_Memory);
+  void *__cdecl malloc(size_t _Size);
+  void *__cdecl realloc(void *_Memory,size_t _NewSize);
+  _CRTIMP void *__cdecl _recalloc(void *_Memory,size_t _Count,size_t _Size);
+  /*	_CRTIMP void __cdecl _aligned_free(void *_Memory);
+  _CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment); */
+  _CRTIMP void *__cdecl _aligned_offset_malloc(size_t _Size,size_t _Alignment,size_t _Offset);
+  _CRTIMP void *__cdecl _aligned_realloc(void *_Memory,size_t _Size,size_t _Alignment);
+  _CRTIMP void *__cdecl _aligned_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment);
+  _CRTIMP void *__cdecl _aligned_offset_realloc(void *_Memory,size_t _Size,size_t _Alignment,size_t _Offset);
+  _CRTIMP void *__cdecl _aligned_offset_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment,size_t _Offset);
 #endif
-/*
-   The _heap* memory allocation functions are supported on NT
-   but not W9x. On latter, they always set errno to ENOSYS.
-*/
-int	_heapwalk (_HEAPINFO*);
 
-#ifndef	_NO_OLDNAMES
-int	heapwalk (_HEAPINFO*);
-#endif	/* Not _NO_OLDNAMES */
+#define _MAX_WAIT_MALLOC_CRT 60000
+
+  _CRTIMP int __cdecl _resetstkoflw (void);
+  _CRTIMP unsigned long __cdecl _set_malloc_crt_max_wait(unsigned long _NewValue);
+
+  _CRTIMP void *__cdecl _expand(void *_Memory,size_t _NewSize);
+  _CRTIMP size_t __cdecl _msize(void *_Memory);
+#ifdef __GNUC__
+#undef _alloca
+#define _alloca(x) __builtin_alloca((x))
+#else
+  /* tcc implements alloca internally and exposes it (since commit d778bde7).
+  /* alloca is declared at include/stddef.h (which is distributed with tcc).
+   */
+#ifdef _alloca
+#undef _alloca
+#endif
+#define _alloca(x) alloca((x))
+#endif
+  _CRTIMP size_t __cdecl _get_sbh_threshold(void);
+  _CRTIMP int __cdecl _set_sbh_threshold(size_t _NewValue);
+  _CRTIMP errno_t __cdecl _set_amblksiz(size_t _Value);
+  _CRTIMP errno_t __cdecl _get_amblksiz(size_t *_Value);
+  _CRTIMP int __cdecl _heapadd(void *_Memory,size_t _Size);
+  _CRTIMP int __cdecl _heapchk(void);
+  _CRTIMP int __cdecl _heapmin(void);
+  _CRTIMP int __cdecl _heapset(unsigned int _Fill);
+  _CRTIMP int __cdecl _heapwalk(_HEAPINFO *_EntryInfo);
+  _CRTIMP size_t __cdecl _heapused(size_t *_Used,size_t *_Commit);
+  _CRTIMP intptr_t __cdecl _get_heap_handle(void);
+
+#define _ALLOCA_S_THRESHOLD 1024
+#define _ALLOCA_S_STACK_MARKER 0xCCCC
+#define _ALLOCA_S_HEAP_MARKER 0xDDDD
+
+#if(defined(_X86_) && !defined(__x86_64))
+#define _ALLOCA_S_MARKER_SIZE 8
+#elif defined(__ia64__) || defined(__x86_64)
+#define _ALLOCA_S_MARKER_SIZE 16
+#endif
 
-int	_heapchk (void);	/* Verify heap integrety. */
-int	_heapmin (void);	/* Return unused heap to the OS. */
-int	_heapset (unsigned int);
+#if !defined(RC_INVOKED)
+  static __inline void *_MarkAllocaS(void *_Ptr,unsigned int _Marker) {
+    if(_Ptr) {
+      *((unsigned int*)_Ptr) = _Marker;
+      _Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE;
+    }
+    return _Ptr;
+  }
+#endif
 
-size_t	_msize (void*);
-size_t	_get_sbh_threshold (void); 
-int	_set_sbh_threshold (size_t);
-void *	_expand (void*, size_t); 
+#undef _malloca
+#define _malloca(size) \
+  ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \
+    _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_STACK_MARKER) : \
+    _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_HEAP_MARKER))
+#undef _FREEA_INLINE
+#define _FREEA_INLINE
 
-#ifdef __cplusplus
-}
+#ifndef RC_INVOKED
+#undef _freea
+  static __inline void __cdecl _freea(void *_Memory) {
+    unsigned int _Marker;
+    if(_Memory) {
+      _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
+      _Marker = *(unsigned int *)_Memory;
+      if(_Marker==_ALLOCA_S_HEAP_MARKER) {
+	free(_Memory);
+      }
+#ifdef _ASSERTE
+      else if(_Marker!=_ALLOCA_S_STACK_MARKER) {
+	_ASSERTE(("Corrupted pointer passed to _freea",0));
+      }
+#endif
+    }
+  }
+#endif /* RC_INVOKED */
+
+#ifndef	NO_OLDNAMES
+#ifdef __GNUC__
+#undef alloca
+#define alloca(x) __builtin_alloca((x))
+#endif
 #endif
 
-#endif	/* RC_INVOKED */
+#ifdef HEAPHOOK
+#ifndef _HEAPHOOK_DEFINED
+#define _HEAPHOOK_DEFINED
+  typedef int (__cdecl *_HEAPHOOK)(int,size_t,void *,void **);
+#endif
+
+  _CRTIMP _HEAPHOOK __cdecl _setheaphook(_HEAPHOOK _NewHook);
+
+#define _HEAP_MALLOC 1
+#define _HEAP_CALLOC 2
+#define _HEAP_FREE 3
+#define _HEAP_REALLOC 4
+#define _HEAP_MSIZE 5
+#define _HEAP_EXPAND 6
+#endif
 
-#endif /* Not _MALLOC_H_ */
+#ifdef __cplusplus
+}
+#endif
 
-#endif /* Not __STRICT_ANSI__ */
+#pragma pack(pop)
 
+#endif /* _MALLOC_H_ */