Oh and for querying stack pointers, there should be an OS function somewhere to give you the base stack pointer address and available stack size, though I don't know the names of functions off the top of my head.