On Nov 29, 2006, at 2:51 PM, Scott Long wrote: >> Is it possible to check how deep the stack is and avoid using a stack >> buffer if too deep? >> -- >> John Birrell > > I don't know how to do it in a platform-independent way. For i386, > I'd check %esp and see if it's getting close to a 2x page boundary. You should be able to take the address of an automatic variable which gets allocated on the stack...? #include <stdio.h> int main(int argc, char *argv[]) { volatile int stack_location; printf("stack is at: %0p\n", &stack_location); } On a few platforms [1], they have a set of registers dedicated as temps which might be used instead of the stack, although taking the address of the variable should be enough to prevent the compiler from allocating it in a register. But using "volatile" will keep the compiler from doing anything fancy with it. -- -Chuck [1]: The HP/PA and SPARC's register windows, for example. But quick testing suggests that the above finds the stack on x86, SPARC, and PPC hardware, although I'm obviously testing userland code rather than running it inside a kernel module. :-)Received on Wed Nov 29 2006 - 22:24:12 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:03 UTC