mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
36 lines
671 B
C
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);
|
|
}
|