vmalloc revision 1
1N/A#
1N/A# This file defines probes for local features that vmalloc requires.
1N/A# Such probes are interpreted by the "iffe" language interpreter.
1N/A# Results are stored in the FEATURE directory. Some of the
1N/A# {lib,hdr,sys,typ} tests may also be done in the AST features/lib;
1N/A# repeating them here allows for single standalone and AST sources.
1N/A#
1N/A
1N/Aref -D_def_map_ast=1
1N/A
1N/Alib atexit,getpagesize,mallinfo,mallopt,memalign,mstats
1N/Alib onexit,pvalloc,strdup,valloc,vmalloc
1N/Alib _malloc,__malloc,__libc_malloc
1N/Ahdr alloca,malloc,stat,stdlib,unistd
1N/Amem mallinfo.arena,mstats.bytes_total malloc.h
1N/Asys stat
1N/Atyp ssize_t
1N/A
1N/Atst mem_sbrk note{ brk()/sbrk() work as expected }end execute{
1N/A #include <sys/types.h>
1N/A #include <unistd.h>
1N/A #undef uchar
1N/A #define uchar unsigned char
1N/A int main()
1N/A { uchar *brk0, *brk1;
1N/A
1N/A /* allocate a big chunk */
1N/A if(!(brk0 = (uchar*)sbrk(0)) || brk0 == (uchar*)(-1))
1N/A return 1;
1N/A brk0 += 256*1024;
1N/A if(brk(brk0) != 0)
1N/A return 1;
1N/A if((brk1 = (uchar*)sbrk(0)) != brk0)
1N/A return 1;
1N/A
1N/A /* now return half of it */
1N/A brk1 -= 128*1024;
1N/A if(brk(brk1) != 0 )
1N/A return 1;
1N/A if((brk0 = (uchar*)sbrk(0)) != brk1)
1N/A return 1;
1N/A
1N/A return 0;
1N/A }
1N/A}end
1N/A
1N/Atst map_malloc note{ map malloc to _ast_malloc }end noexecute{
1N/A #if __CYGWIN__
1N/A int main() { return 1; }
1N/A #else
1N/A static int user = 0;
1N/A _BEGIN_EXTERNS_
1N/A #if _lib_strdup
1N/A extern char* strdup _ARG_((const char*));
1N/A #define LOCAL() strdup("s")
1N/A #else
1N/A extern void* calloc _ARG_((unsigned int, unsigned int));
1N/A #define LOCAL() calloc(1,1)
1N/A #endif
1N/A #if __CYGWIN__
1N/A #define extern __declspec(dllexport)
1N/A #endif
1N/A #define HT double
1N/A static HT heap[1024 * 4];
1N/A static HT* hp = &heap[1];
1N/A static HT* op;
1N/A #define MALLOC(n) if(user)return&heap[0];op=hp;hp+=(n+sizeof(HT)-1)/sizeof(HT);return(void*)op;
1N/A #define INTERCEPTED(p) (((char*)(p))==((char*)&heap[0]))
1N/A #if _STD_
1N/A extern void free(void* p) { }
1N/A extern void _free(void* p) { }
1N/A extern void __free(void* p) { }
1N/A extern void __libc_free(void* p) { }
1N/A extern void* malloc(unsigned int n) { MALLOC(n); }
1N/A extern void* _malloc(unsigned int n) { MALLOC(n); }
1N/A extern void* __malloc(unsigned int n) { MALLOC(n); }
1N/A extern void* __libc_malloc(unsigned int n) { MALLOC(n); }
1N/A #else
1N/A extern void free(p) char* p; { }
1N/A extern void _free(p) char* p; { }
1N/A extern void __free(p) char* p; { }
1N/A extern void __libc_free(p) char* p; { }
1N/A extern void* malloc(n) unsigned int n; { MALLOC(n); }
1N/A extern void* _malloc(n) unsigned int n; { MALLOC(n); }
1N/A extern void* __malloc(n) unsigned int n; { MALLOC(n); }
1N/A extern void* __libc_malloc(n) unsigned int n; { MALLOC(n); }
1N/A #endif
1N/A _END_EXTERNS_
1N/A int main() { user = 1; return !INTERCEPTED(LOCAL()); }
1N/A #endif
1N/A}end
1N/A
1N/Atst map_malloc note{ map malloc to _ast_malloc -- wimp-o mach? }end noexecute{
1N/A #if _map_malloc
1N/A int main() { return 0; }
1N/A #else
1N/A _BEGIN_EXTERNS_
1N/A #if _STD_
1N/A void* calloc(unsigned n, unsigned m) { exit(1); }
1N/A #else
1N/A void* calloc(n, m) unsigned n, m; { exit(1); }
1N/A #endif
1N/A _END_EXTERNS_
1N/A int main() { return 0; }
1N/A #endif
1N/A}end
1N/A
1N/Alib alloca note{ alloca exists }end link{
1N/A #if _hdr_alloca
1N/A #include <alloca.h>
1N/A #endif
1N/A int
1N/A main()
1N/A { alloca(10);
1N/A }
1N/A}end
1N/A
1N/Atst mal_alloca note{ alloca is based on malloc() }end execute{
1N/A #if __CYGWIN__
1N/A int main() { return 1; }
1N/A #else
1N/A #if _hdr_alloca
1N/A #include <alloca.h>
1N/A #endif
1N/A #if _STD_
1N/A void* malloc(unsigned int size)
1N/A #else
1N/A void* malloc(size) unsigned int size;
1N/A #endif
1N/A { exit(0);
1N/A return 0;
1N/A }
1N/A int main()
1N/A { alloca(10);
1N/A return 1;
1N/A }
1N/A #endif
1N/A}end
1N/A
1N/Atst stk_down note{ stack grows downward }end execute{
1N/A static growdown()
1N/A { static char* addr = 0;
1N/A char array[4];
1N/A if(!addr)
1N/A { addr = &array[0];
1N/A return growdown();
1N/A }
1N/A else if(addr < &array[0])
1N/A return 0;
1N/A else return 1;
1N/A }
1N/A int main() { return growdown() ? 0 : 1; }
1N/A}end
1N/A
1N/Acat{
1N/A #include "FEATURE/mmap"
1N/A #if _BLD_INSTRUMENT || cray || _UWIN && _BLD_ast
1N/A #undef _map_malloc
1N/A #define _std_malloc 1 /* defer to standard malloc */
1N/A #endif
1N/A #if _mmap_anon
1N/A #define _mem_mmap_anon 1
1N/A #endif
1N/A #if _mmap_devzero
1N/A #define _mem_mmap_zero 1
1N/A #endif
1N/A}end