xref: /onnv-gate/usr/src/lib/libast/common/features/vmalloc (revision 10898:1883b621b3ea)
14887Schin#
24887Schin# This file defines probes for local features that vmalloc requires.
34887Schin# Such probes are interpreted by the "iffe" language interpreter.
44887Schin# Results are stored in the FEATURE directory. Some of the
54887Schin# {lib,hdr,sys,typ} tests may also be done in the AST features/lib;
64887Schin# repeating them here allows for single standalone and AST sources.
74887Schin#
84887Schin
94887Schinref	-D_def_map_ast=1
104887Schin
114887Schinlib	atexit,getpagesize,mallinfo,mallopt,memalign,mstats
124887Schinlib	onexit,pvalloc,strdup,valloc,vmalloc
134887Schinlib	_malloc,__malloc,__libc_malloc
144887Schinhdr	alloca,malloc,stat,stdlib,unistd
154887Schinmem	mallinfo.arena,mstats.bytes_total malloc.h
164887Schinsys	stat
174887Schintyp	ssize_t
184887Schin
194887Schintst	mem_sbrk note{ brk()/sbrk() work as expected }end execute{
204887Schin	#include        <sys/types.h>
214887Schin	#include        <unistd.h>
224887Schin	#undef	uchar
234887Schin	#define	uchar	unsigned char
244887Schin	int main()
254887Schin	{	uchar	*brk0, *brk1;
264887Schin
274887Schin		/* allocate a big chunk */
284887Schin		if(!(brk0 = (uchar*)sbrk(0)) || brk0 == (uchar*)(-1))
294887Schin			return 1;
304887Schin		brk0 += 256*1024;
314887Schin		if(brk(brk0) != 0)
324887Schin			return 1;
334887Schin		if((brk1 = (uchar*)sbrk(0)) != brk0)
344887Schin			return 1;
354887Schin
364887Schin		/* now return half of it */
374887Schin		brk1 -= 128*1024;
384887Schin		if(brk(brk1) != 0 )
394887Schin			return 1;
404887Schin		if((brk0 = (uchar*)sbrk(0)) != brk1)
414887Schin			return 1;
424887Schin
434887Schin		return 0;
444887Schin	}
454887Schin}end
464887Schin
474887Schintst	map_malloc note{ map malloc to _ast_malloc }end noexecute{
484887Schin	#if __CYGWIN__
494887Schin	int main() { return 1; }
504887Schin	#else
514887Schin	static int user = 0;
524887Schin	_BEGIN_EXTERNS_
534887Schin	#if _lib_strdup
544887Schin	extern char* strdup _ARG_((const char*));
554887Schin	#define LOCAL()	strdup("s")
564887Schin	#else
574887Schin	extern void* calloc _ARG_((unsigned int, unsigned int));
584887Schin	#define LOCAL()	calloc(1,1)
594887Schin	#endif
604887Schin	#if __CYGWIN__
614887Schin	#define extern __declspec(dllexport)
624887Schin	#endif
634887Schin	#define HT double
644887Schin	static HT heap[1024 * 4];
654887Schin	static HT* hp = &heap[1];
664887Schin	static HT* op;
674887Schin	#define MALLOC(n) if(user)return&heap[0];op=hp;hp+=(n+sizeof(HT)-1)/sizeof(HT);return(void*)op;
684887Schin	#define INTERCEPTED(p) (((char*)(p))==((char*)&heap[0]))
694887Schin	#if _STD_
704887Schin	extern void free(void* p) { }
714887Schin	extern void _free(void* p) { }
724887Schin	extern void __free(void* p) { }
734887Schin	extern void __libc_free(void* p) { }
744887Schin	extern void* malloc(unsigned int n) { MALLOC(n); }
754887Schin	extern void* _malloc(unsigned int n) { MALLOC(n); }
764887Schin	extern void* __malloc(unsigned int n) { MALLOC(n); }
774887Schin	extern void* __libc_malloc(unsigned int n) { MALLOC(n); }
784887Schin	#else
794887Schin	extern void free(p) char* p; { }
804887Schin	extern void _free(p) char* p; { }
814887Schin	extern void __free(p) char* p; { }
824887Schin	extern void __libc_free(p) char* p; { }
834887Schin	extern void* malloc(n) unsigned int n; { MALLOC(n); }
844887Schin	extern void* _malloc(n) unsigned int n; { MALLOC(n); }
854887Schin	extern void* __malloc(n) unsigned int n; { MALLOC(n); }
864887Schin	extern void* __libc_malloc(n) unsigned int n; { MALLOC(n); }
874887Schin	#endif
884887Schin	_END_EXTERNS_
894887Schin	int main() { user = 1; return !INTERCEPTED(LOCAL()); }
904887Schin	#endif
914887Schin}end
924887Schin
934887Schintst	map_malloc note{ map malloc to _ast_malloc -- wimp-o mach? }end noexecute{
944887Schin	#if _map_malloc
954887Schin	int main() { return 0; }
964887Schin	#else
974887Schin	_BEGIN_EXTERNS_
984887Schin	#if _STD_
994887Schin	void* calloc(unsigned n, unsigned m) { exit(1); }
1004887Schin	#else
1014887Schin	void* calloc(n, m) unsigned n, m; { exit(1); }
1024887Schin	#endif
1034887Schin	_END_EXTERNS_
1044887Schin	int main() { return 0; }
1054887Schin	#endif
1064887Schin}end
1074887Schin
1084887Schinlib	alloca note{ alloca exists }end link{
1094887Schin	#if _hdr_alloca
1104887Schin	#include	<alloca.h>
1114887Schin	#endif
1124887Schin	int
1134887Schin	main()
1144887Schin	{	alloca(10);
1154887Schin	}
1164887Schin}end
1174887Schin
1184887Schintst	mal_alloca note{ alloca is based on malloc() }end execute{
119*10898Sroland.mainz@nrubsig.org	#if __CYGWIN__
120*10898Sroland.mainz@nrubsig.org	int main() { return 1; }
121*10898Sroland.mainz@nrubsig.org	#else
1224887Schin	#if _hdr_alloca
1234887Schin	#include	<alloca.h>
1244887Schin	#endif
1254887Schin	#if _STD_
1264887Schin	void* malloc(unsigned int size)
1274887Schin	#else
1284887Schin	void* malloc(size) unsigned int size;
1294887Schin	#endif
1304887Schin	{	exit(0);
1314887Schin		return 0;
1324887Schin	}
1334887Schin	int main()
1344887Schin	{	alloca(10);
1354887Schin		return 1;
1364887Schin	}
137*10898Sroland.mainz@nrubsig.org	#endif
1384887Schin}end
1394887Schin
1404887Schintst	stk_down note{ stack grows downward }end execute{
1414887Schin	static growdown()
1424887Schin	{	static char*	addr = 0;
1434887Schin		char		array[4];
1444887Schin		if(!addr)
1454887Schin		{	addr = &array[0];
1464887Schin			return growdown();
1474887Schin		}
1484887Schin		else if(addr < &array[0])
1494887Schin			return 0;
1504887Schin		else	return 1;
1514887Schin	}
1524887Schin	int main() { return growdown() ? 0 : 1; }
1534887Schin}end
1544887Schin
1554887Schincat{
1564887Schin	#include "FEATURE/mmap"
1574887Schin	#if _BLD_INSTRUMENT || cray || _UWIN && _BLD_ast
1584887Schin	#undef	_map_malloc
1594887Schin	#define _std_malloc	1	/* defer to standard malloc */
1604887Schin	#endif
1614887Schin	#if _mmap_anon
1624887Schin	#define _mem_mmap_anon	1
1634887Schin	#endif
1644887Schin	#if _mmap_devzero
1654887Schin	#define _mem_mmap_zero	1
1664887Schin	#endif
1674887Schin}end
168