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