Stack overflow

To maximize function call performance, XPLINK replaces the explicit inline check for overflow with a storage protect mechanism that detects stores past the end of the stack segment.

The stack floor is the lowest usable address of the current stack segment. Toward lower addresses, it is preceded by a store-protected guard page used to detect stack overflows.

Availability of space for a stack frame is ensured in the function prolog usually by storing into the start of the called function's frame. In case of overflow, this triggers an exception which in turn causes a discontiguous extension of the stack by Language Environment. Functions with a DSA larger than the guard page use the stack floor address in the CAA to verify space availability. Allocation and deallocation of extensions is transparent to the application.

To make the stack appear contiguous to the application, a small stack frame containing all fields up to and including the Argument area will be allocated in the new stack segment for use by the called function, and the contents of the caller's stack, up to the end of the argument area, is copied into the new stack segment. The length of the argument list expected is available in the called function's PPA1 except for vararg functions, where the entire argument area in the calling function must be copied.

Stores into the guard page done outside the prolog done outside alloca() built-in processing should be treated as invalid and cause the application to be terminated.

Stack overflow is detected by the STM instruction that is used to save registers in this save area.

Initial stack segment size and the stack segment increment size are controlled by the STACK runtime option (see z/OS Language Environment Programming Reference).