// SPDX-License-Identifier: GPL-3.0-or-later #include // The runtime must report the exact assembler label after each LBSR. Subtracting // an assumed instruction width gives the pre-0.1.101 address and fails this test. static void *expectedNullReturn; static void *observedNullReturn; static void *expectedStackReturn; static void *expectedStackRegister; static void nullHandler(void *addressPastFailedCheck) { observedNullReturn = addressPastFailedCheck; } asm void nullProbe(void) { asm { import check_null_ptr_x leax null_probe_after,pcr stx :expectedNullReturn ldx #0 lbsr check_null_ptr_x null_probe_after: } } static void stackHandler(void *addressPastFailedCheck, void *stackRegister) { printf("HANDLERS N%u S%u P%u END\n", observedNullReturn == expectedNullReturn, addressPastFailedCheck == expectedStackReturn, stackRegister == expectedStackRegister); exit(0); // The stack handler contract forbids returning. } asm void stackProbe(void) { asm { import check_stack_overflow import end_of_sbrk_mem leax stack_probe_after,pcr stx :expectedStackReturn tfr s,d std :expectedStackRegister // Trigger the lower-bound check without corrupting or exhausting the // actual stack. This is a disposable guest and no allocation follows. ldd #$ffff std end_of_sbrk_mem,pcr lbsr check_stack_overflow stack_probe_after: } } int main(void) { set_null_ptr_handler(nullHandler); nullProbe(); set_stack_overflow_handler(stackHandler); stackProbe(); printf("FAIL STACK CHECK RETURNED\n"); return 1; }