ruby/ext/-test-/stack/stack.c
Nobuyoshi Nakada c794a97940 Rename alloca_overflow to stack_overflow
`alloca` is an implementation detail to raise a stack overflow.
2026-01-09 20:02:54 +09:00

36 lines
671 B
C

#include "ruby.h"
#include "internal/string.h"
static VALUE
stack_overflow(VALUE self)
{
size_t i = 0;
while (1) {
// Allocate and touch memory to force actual stack usage:
volatile char *stack = alloca(1024);
stack[0] = (char)i;
stack[1023] = (char)i;
i++;
}
return Qnil;
}
static VALUE
asan_p(VALUE klass)
{
#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
return Qtrue;
#else
return Qfalse;
#endif
}
void
Init_stack(VALUE klass)
{
rb_define_singleton_method(rb_cThread, "stack_overflow", stack_overflow, 0);
rb_define_singleton_method(rb_cThread, "asan?", asan_p, 0);
}