/* Language Independent Library Copyright 2006-2012 Green Hills Software,Inc. * This program is the property of Green Hills Software, Inc, * its contents are proprietary information and no part of it * is to be disclosed to anyone except employees of Green Hills * Software, Inc., or as agreed in writing signed by the President * of Green Hills Software, Inc. */ /* This module is meant to perform stack checking using the -stack_check * option. */ /* Get __get_stack_pointer() on appropriate targets */ #include #include "ind_io.h" /* write() */ #include /* exit() */ #include /* strlen() */ #include #pragma ghs startnoinline /* CAFE MOD */ static void emit_stack_error(const char *tname) { static const char err[] = "Stack overflow error in \""; (void)write(1, err, sizeof(err)-1); (void)write(1, tname, strlen(tname)); (void)write(1, "\"\n", 2); OSDebug(); /* exit is already pulled in by ind_crt1.c, so use it */ exit(1); } void __stkchk(void) { static int did_error = 0; #ifdef __GHS_TARGET_IMPLEMENTS_ALLOCA void *sp = __get_stack_pointer(); #else char loc; void *sp = (void *)&loc; #endif /* __GHS_TARGET_IMPLEMENTS_ALLOCA */ OSThread* thread; if (!did_error) { thread = OSGetCurrentThread(); if(sp <= (void *)thread->stackEnd) { did_error = 1; emit_stack_error(thread->name); } } }