While there is no officially supported way to do this. Is there a way (on modern systems), to detect if a pointer is from the stack (stack of the caller for example).
Even if this is not going to work as part of actual code logic, it could help avoid errors in for the configurations that can detect it, eg:
void my_function(void *arg) {
/* Only some configurations can do this (depending on compiler & arch). */
#if THE_MOONS_ALIGN
assert(not_stack_memory(arg));
#endif
/* ... actual logic ... */
}
int main(void) {int firstVar; char* ptrToFirstVar = (char *)&firstVar; /* Now you have brief beginning of stack */ char *endOfStack = ptrToFirstVar - yourSTACKSIZE;
Then check if your variable is between start of stack and stack size. – MallardNtCurrentTeb()
– Skivvy