~ubuntu-branches/ubuntu/wily/tcc/wily

« back to all changes in this revision

Viewing changes to win32/include/malloc.h

  • Committer: Package Import Robot
  • Author(s): Thomas Preud'homme
  • Date: 2012-03-15 00:39:47 UTC
  • mfrom: (17.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20120315003947-ilv76fmcmb87yza3
Tags: 0.9.26~git20120104.83d57c0-5
* Document that -b is only available on i386 (Closes: #663692).
* Correctly parse unsigned long constants (ex: 1UL) on amd64
  (Closes: #663711).
* Support arguments to linker options to be passed in separate linker
  options as in -Wl,-rpath -Wl,<somedir> (Closes: #663693).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * malloc.h
3
 
 *
4
 
 * Support for programs which want to use malloc.h to get memory management
5
 
 * functions. Unless you absolutely need some of these functions and they are
6
 
 * not in the ANSI headers you should use the ANSI standard header files
7
 
 * instead.
8
 
 *
9
 
 * This file is part of the Mingw32 package.
10
 
 *
11
 
 * Contributors:
12
 
 *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
13
 
 *
14
 
 *  THIS SOFTWARE IS NOT COPYRIGHTED
15
 
 *
16
 
 *  This source code is offered for use in the public domain. You may
17
 
 *  use, modify or distribute it freely.
18
 
 *
19
 
 *  This code is distributed in the hope that it will be useful but
20
 
 *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
21
 
 *  DISCLAIMED. This includes but is not limited to warranties of
22
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23
 
 *
24
 
 * $Revision: 1.2 $
25
 
 * $Author: bellard $
26
 
 * $Date: 2005/04/17 13:14:29 $
27
 
 *
 
1
/**
 
2
 * This file has no copyright assigned and is placed in the Public Domain.
 
3
 * This file is part of the w64 mingw-runtime package.
 
4
 * No warranty is given; refer to the file DISCLAIMER within this package.
28
5
 */
29
 
 
30
 
#ifndef __STRICT_ANSI__
31
 
 
32
6
#ifndef _MALLOC_H_
33
7
#define _MALLOC_H_
34
8
 
35
 
/* All the headers include this file. */
36
9
#include <_mingw.h>
37
10
 
38
 
#include <stdlib.h>
 
11
#pragma pack(push,_CRT_PACKING)
 
12
 
 
13
#ifndef _MM_MALLOC_H_INCLUDED
 
14
#define _MM_MALLOC_H_INCLUDED
 
15
#endif
 
16
 
 
17
#ifdef __cplusplus
 
18
extern "C" {
 
19
#endif
 
20
 
 
21
#ifdef _WIN64
 
22
#define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
 
23
#else
 
24
#define _HEAP_MAXREQ 0xFFFFFFE0
 
25
#endif
 
26
 
 
27
#ifndef _STATIC_ASSERT
 
28
#define _STATIC_ASSERT(expr) typedef char __static_assert_t[(expr)]
 
29
#endif
 
30
 
 
31
/* Return codes for _heapwalk()  */
 
32
#define _HEAPEMPTY (-1)
 
33
#define _HEAPOK (-2)
 
34
#define _HEAPBADBEGIN (-3)
 
35
#define _HEAPBADNODE (-4)
 
36
#define _HEAPEND (-5)
 
37
#define _HEAPBADPTR (-6)
 
38
 
 
39
/* Values for _heapinfo.useflag */
 
40
#define _FREEENTRY 0
 
41
#define _USEDENTRY 1
 
42
 
 
43
#ifndef _HEAPINFO_DEFINED
 
44
#define _HEAPINFO_DEFINED
 
45
 /* The structure used to walk through the heap with _heapwalk.  */
 
46
  typedef struct _heapinfo {
 
47
    int *_pentry;
 
48
    size_t _size;
 
49
    int _useflag;
 
50
  } _HEAPINFO;
 
51
#endif
 
52
 
 
53
  extern unsigned int _amblksiz;
 
54
 
 
55
#define _mm_free(a) _aligned_free(a)
 
56
#define _mm_malloc(a,b) _aligned_malloc(a,b)
 
57
 
 
58
#ifndef _CRT_ALLOCATION_DEFINED
 
59
#define _CRT_ALLOCATION_DEFINED
 
60
  void *__cdecl calloc(size_t _NumOfElements,size_t _SizeOfElements);
 
61
  void __cdecl free(void *_Memory);
 
62
  void *__cdecl malloc(size_t _Size);
 
63
  void *__cdecl realloc(void *_Memory,size_t _NewSize);
 
64
  _CRTIMP void *__cdecl _recalloc(void *_Memory,size_t _Count,size_t _Size);
 
65
  /*    _CRTIMP void __cdecl _aligned_free(void *_Memory);
 
66
  _CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment); */
 
67
  _CRTIMP void *__cdecl _aligned_offset_malloc(size_t _Size,size_t _Alignment,size_t _Offset);
 
68
  _CRTIMP void *__cdecl _aligned_realloc(void *_Memory,size_t _Size,size_t _Alignment);
 
69
  _CRTIMP void *__cdecl _aligned_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment);
 
70
  _CRTIMP void *__cdecl _aligned_offset_realloc(void *_Memory,size_t _Size,size_t _Alignment,size_t _Offset);
 
71
  _CRTIMP void *__cdecl _aligned_offset_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t _Alignment,size_t _Offset);
 
72
#endif
 
73
 
 
74
#define _MAX_WAIT_MALLOC_CRT 60000
 
75
 
 
76
  _CRTIMP int __cdecl _resetstkoflw (void);
 
77
  _CRTIMP unsigned long __cdecl _set_malloc_crt_max_wait(unsigned long _NewValue);
 
78
 
 
79
  _CRTIMP void *__cdecl _expand(void *_Memory,size_t _NewSize);
 
80
  _CRTIMP size_t __cdecl _msize(void *_Memory);
 
81
#ifdef __GNUC__
 
82
#undef _alloca
 
83
#define _alloca(x) __builtin_alloca((x))
 
84
#else
 
85
  void *__cdecl _alloca(size_t _Size);
 
86
#endif
 
87
  _CRTIMP size_t __cdecl _get_sbh_threshold(void);
 
88
  _CRTIMP int __cdecl _set_sbh_threshold(size_t _NewValue);
 
89
  _CRTIMP errno_t __cdecl _set_amblksiz(size_t _Value);
 
90
  _CRTIMP errno_t __cdecl _get_amblksiz(size_t *_Value);
 
91
  _CRTIMP int __cdecl _heapadd(void *_Memory,size_t _Size);
 
92
  _CRTIMP int __cdecl _heapchk(void);
 
93
  _CRTIMP int __cdecl _heapmin(void);
 
94
  _CRTIMP int __cdecl _heapset(unsigned int _Fill);
 
95
  _CRTIMP int __cdecl _heapwalk(_HEAPINFO *_EntryInfo);
 
96
  _CRTIMP size_t __cdecl _heapused(size_t *_Used,size_t *_Commit);
 
97
  _CRTIMP intptr_t __cdecl _get_heap_handle(void);
 
98
 
 
99
#define _ALLOCA_S_THRESHOLD 1024
 
100
#define _ALLOCA_S_STACK_MARKER 0xCCCC
 
101
#define _ALLOCA_S_HEAP_MARKER 0xDDDD
 
102
 
 
103
#if(defined(_X86_) && !defined(__x86_64))
 
104
#define _ALLOCA_S_MARKER_SIZE 8
 
105
#elif defined(__ia64__) || defined(__x86_64)
 
106
#define _ALLOCA_S_MARKER_SIZE 16
 
107
#endif
 
108
 
 
109
#if !defined(RC_INVOKED)
 
110
  static __inline void *_MarkAllocaS(void *_Ptr,unsigned int _Marker) {
 
111
    if(_Ptr) {
 
112
      *((unsigned int*)_Ptr) = _Marker;
 
113
      _Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE;
 
114
    }
 
115
    return _Ptr;
 
116
  }
 
117
#endif
 
118
 
 
119
#undef _malloca
 
120
#define _malloca(size) \
 
121
  ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \
 
122
    _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_STACK_MARKER) : \
 
123
    _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_HEAP_MARKER))
 
124
#undef _FREEA_INLINE
 
125
#define _FREEA_INLINE
39
126
 
40
127
#ifndef RC_INVOKED
41
 
 
42
 
/*
43
 
 * The structure used to walk through the heap with _heapwalk.
44
 
 */
45
 
typedef struct _heapinfo
46
 
{
47
 
        int*    _pentry;
48
 
        size_t  _size;
49
 
        int     _useflag;
50
 
} _HEAPINFO;
51
 
 
52
 
/* Values for _heapinfo.useflag */
53
 
#define _USEDENTRY 0
54
 
#define _FREEENTRY 1
55
 
 
56
 
#ifdef  __cplusplus
57
 
extern "C" {
58
 
#endif
59
 
/*
60
 
   The _heap* memory allocation functions are supported on NT
61
 
   but not W9x. On latter, they always set errno to ENOSYS.
62
 
*/
63
 
int     _heapwalk (_HEAPINFO*);
64
 
 
65
 
#ifndef _NO_OLDNAMES
66
 
int     heapwalk (_HEAPINFO*);
67
 
#endif  /* Not _NO_OLDNAMES */
68
 
 
69
 
int     _heapchk (void);        /* Verify heap integrety. */
70
 
int     _heapmin (void);        /* Return unused heap to the OS. */
71
 
int     _heapset (unsigned int);
72
 
 
73
 
size_t  _msize (void*);
74
 
size_t  _get_sbh_threshold (void); 
75
 
int     _set_sbh_threshold (size_t);
76
 
void *  _expand (void*, size_t); 
 
128
#undef _freea
 
129
  static __inline void __cdecl _freea(void *_Memory) {
 
130
    unsigned int _Marker;
 
131
    if(_Memory) {
 
132
      _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
 
133
      _Marker = *(unsigned int *)_Memory;
 
134
      if(_Marker==_ALLOCA_S_HEAP_MARKER) {
 
135
        free(_Memory);
 
136
      }
 
137
#ifdef _ASSERTE
 
138
      else if(_Marker!=_ALLOCA_S_STACK_MARKER) {
 
139
        _ASSERTE(("Corrupted pointer passed to _freea",0));
 
140
      }
 
141
#endif
 
142
    }
 
143
  }
 
144
#endif /* RC_INVOKED */
 
145
 
 
146
#ifndef NO_OLDNAMES
 
147
#ifdef __GNUC__
 
148
#undef alloca
 
149
#define alloca(x) __builtin_alloca((x))
 
150
#endif
 
151
#endif
 
152
 
 
153
#ifdef HEAPHOOK
 
154
#ifndef _HEAPHOOK_DEFINED
 
155
#define _HEAPHOOK_DEFINED
 
156
  typedef int (__cdecl *_HEAPHOOK)(int,size_t,void *,void **);
 
157
#endif
 
158
 
 
159
  _CRTIMP _HEAPHOOK __cdecl _setheaphook(_HEAPHOOK _NewHook);
 
160
 
 
161
#define _HEAP_MALLOC 1
 
162
#define _HEAP_CALLOC 2
 
163
#define _HEAP_FREE 3
 
164
#define _HEAP_REALLOC 4
 
165
#define _HEAP_MSIZE 5
 
166
#define _HEAP_EXPAND 6
 
167
#endif
77
168
 
78
169
#ifdef __cplusplus
79
170
}
80
171
#endif
81
172
 
82
 
#endif  /* RC_INVOKED */
83
 
 
84
 
#endif /* Not _MALLOC_H_ */
85
 
 
86
 
#endif /* Not __STRICT_ANSI__ */
87
 
 
 
173
#pragma pack(pop)
 
174
 
 
175
#endif /* _MALLOC_H_ */