#include <signal.h>
typedef char * ptr_t;
#ifndef bool
typedef int bool;
#endif
#define VOLATILE volatile
# ifndef STACK_GROWS_UP
# define STACK_GROWS_DOWN
# endif
typedef unsigned long word;
#define TRUE 1
#if defined(__alpha) || defined(__alpha__)
extern __start
# define HEURISTIC2_LIMIT ((ptr_t)((word)(&__start) & ~(getpagesize()-1)))
#endif
void GC_noop() {}
# define MIN_PAGE_SIZE 256
# include <setjmp.h>
jmp_buf GC_jmp_buf;
void GC_fault_handler(sig)
int sig;
{
longjmp(GC_jmp_buf, 1);
}
typedef void (*handler)(int);
ptr_t GC_find_limit(p, up)
ptr_t p;
bool up;
{
static VOLATILE ptr_t result;
static handler old_segv_handler, old_bus_handler;
old_segv_handler = signal(SIGSEGV, GC_fault_handler);
# ifdef SIGBUS
old_bus_handler = signal(SIGBUS, GC_fault_handler);
# endif
if (setjmp(GC_jmp_buf) == 0) {
result = (ptr_t)(((word)(p))
& ~(MIN_PAGE_SIZE-1));
for (;;) {
if (up) {
result += MIN_PAGE_SIZE;
} else {
result -= MIN_PAGE_SIZE;
}
GC_noop(*result);
}
}
(void) signal(SIGSEGV, old_segv_handler);
# ifdef SIGBUS
(void) signal(SIGBUS, old_bus_handler);
# endif
if (!up) {
result += MIN_PAGE_SIZE;
}
return(result);
}
ptr_t GC_get_stack_base()
{
word dummy;
static ptr_t result;
if (!result) {
# ifdef STACK_GROWS_DOWN
result = GC_find_limit((ptr_t)(&dummy), TRUE);
# ifdef HEURISTIC2_LIMIT
if (result > HEURISTIC2_LIMIT
&& (ptr_t)(&dummy) < HEURISTIC2_LIMIT) {
result = HEURISTIC2_LIMIT;
}
# endif
# else
result = GC_find_limit((ptr_t)(&dummy), FALSE);
# ifdef HEURISTIC2_LIMIT
if (result < HEURISTIC2_LIMIT
&& (ptr_t)(&dummy) > HEURISTIC2_LIMIT) {
result = HEURISTIC2_LIMIT;
}
# endif
# endif
}
return(result);
}