1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#
# This file defines probes for local features that vmalloc requires.
# Such probes are interpreted by the "iffe" language interpreter.
# Results are stored in the FEATURE directory. Some of the
# {lib,hdr,sys,typ} tests may also be done in the AST features/lib;
# repeating them here allows for single standalone and AST sources.
#
ref -D_def_map_ast=1
lib atexit,getpagesize,mallinfo,mallopt,memalign,mstats
lib onexit,pvalloc,strdup,valloc,vmalloc
lib _malloc,__malloc,__libc_malloc
hdr alloca,malloc,stat,stdlib,unistd
mem mallinfo.arena,mstats.bytes_total malloc.h
sys stat
typ ssize_t
tst mem_sbrk note{ brk()/sbrk() work as expected }end execute{
#include <sys/types.h>
#include <unistd.h>
#undef uchar
#define uchar unsigned char
int main()
{ uchar *brk0, *brk1;
/* allocate a big chunk */
if(!(brk0 = (uchar*)sbrk(0)) || brk0 == (uchar*)(-1))
return 1;
brk0 += 256*1024;
if(brk(brk0) != 0)
return 1;
if((brk1 = (uchar*)sbrk(0)) != brk0)
return 1;
/* now return half of it */
brk1 -= 128*1024;
if(brk(brk1) != 0 )
return 1;
if((brk0 = (uchar*)sbrk(0)) != brk1)
return 1;
return 0;
}
}end
tst map_malloc note{ map malloc to _ast_malloc }end noexecute{
#if __CYGWIN__
int main() { return 1; }
#else
static int user = 0;
_BEGIN_EXTERNS_
#if _lib_strdup
extern char* strdup _ARG_((const char*));
#define LOCAL() strdup("s")
#else
extern void* calloc _ARG_((unsigned int, unsigned int));
#define LOCAL() calloc(1,1)
#endif
#if __CYGWIN__
#define extern __declspec(dllexport)
#endif
#define HT double
static HT heap[1024 * 4];
static HT* hp = &heap[1];
static HT* op;
#define MALLOC(n) if(user)return&heap[0];op=hp;hp+=(n+sizeof(HT)-1)/sizeof(HT);return(void*)op;
#define INTERCEPTED(p) (((char*)(p))==((char*)&heap[0]))
#if _STD_
extern void free(void* p) { }
extern void _free(void* p) { }
extern void __free(void* p) { }
extern void __libc_free(void* p) { }
extern void* malloc(unsigned int n) { MALLOC(n); }
extern void* _malloc(unsigned int n) { MALLOC(n); }
extern void* __malloc(unsigned int n) { MALLOC(n); }
extern void* __libc_malloc(unsigned int n) { MALLOC(n); }
#else
extern void free(p) char* p; { }
extern void _free(p) char* p; { }
extern void __free(p) char* p; { }
extern void __libc_free(p) char* p; { }
extern void* malloc(n) unsigned int n; { MALLOC(n); }
extern void* _malloc(n) unsigned int n; { MALLOC(n); }
extern void* __malloc(n) unsigned int n; { MALLOC(n); }
extern void* __libc_malloc(n) unsigned int n; { MALLOC(n); }
#endif
_END_EXTERNS_
int main() { user = 1; return !INTERCEPTED(LOCAL()); }
#endif
}end
tst map_malloc note{ map malloc to _ast_malloc -- wimp-o mach? }end noexecute{
#if _map_malloc
int main() { return 0; }
#else
_BEGIN_EXTERNS_
#if _STD_
void* calloc(unsigned n, unsigned m) { exit(1); }
#else
void* calloc(n, m) unsigned n, m; { exit(1); }
#endif
_END_EXTERNS_
int main() { return 0; }
#endif
}end
lib alloca note{ alloca exists }end link{
#if _hdr_alloca
#include <alloca.h>
#endif
int
main()
{ alloca(10);
}
}end
tst mal_alloca note{ alloca is based on malloc() }end execute{
#if __CYGWIN__
int main() { return 1; }
#else
#if _hdr_alloca
#include <alloca.h>
#endif
#if _STD_
void* malloc(unsigned int size)
#else
void* malloc(size) unsigned int size;
#endif
{ exit(0);
return 0;
}
int main()
{ alloca(10);
return 1;
}
#endif
}end
tst stk_down note{ stack grows downward }end execute{
static growdown()
{ static char* addr = 0;
char array[4];
if(!addr)
{ addr = &array[0];
return growdown();
}
else if(addr < &array[0])
return 0;
else return 1;
}
int main() { return growdown() ? 0 : 1; }
}end
cat{
#include "FEATURE/mmap"
#if _BLD_INSTRUMENT || cray || _UWIN && _BLD_ast
#undef _map_malloc
#define _std_malloc 1 /* defer to standard malloc */
#endif
#if _mmap_anon
#define _mem_mmap_anon 1
#endif
#if _mmap_devzero
#define _mem_mmap_zero 1
#endif
}end
|