ProcessStackCheckImpl.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) October 9, 1992 1:28 pm PDT
Michael Plass, January 29, 1993 11:31 am PST
StackPushTestInline:
PROC [bytes:
INT]
RETURNS [
BOOL] =
TRUSTED
MACHINE
CODE {
Returns TRUE if it appears to be OK to push an additional number of bytes on the stack (pop if bytes < 0). Returns FALSE if the stack is exceeded in either direction.
"+#include <xr/Threads.h>\n";
"static bool StackPushTestHelper(bytes) int bytes; {\n";
" int here = 0;\n";
" XR←Thread t = XR𡤌urrThread;\n";
" XR←Pointer sp = (XR←Pointer) &here;\n";
" if (t->t←stack.stack←warmLimit < t->t←stack.stack←physInitial) {\n";
" /* stack grows down */\n";
" sp = sp - bytes;\n";
" if (sp <= t->t←stack.stack←warmLimit) return (0);\n";
" if (sp >= t->t←stack.stack←physInitial) return (0);\n";
" return (1);\n";
" };\n";
" /* stack grows up */\n";
" sp = sp + bytes;\n";
" if (sp <= t->t←stack.stack←physInitial) return (0);\n";
" if (sp >= t->t←stack.stack←warmLimit) return (0);\n";
" return (1);\n";
"}\n";
".StackPushTestHelper";
};