blob: 8ff32f9737b2183def046dede9e78030f4abc5a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "ruby.h"
#include "internal/string.h"
static VALUE
stack_alloca_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, "alloca_overflow", stack_alloca_overflow, 0);
rb_define_singleton_method(rb_cThread, "asan?", asan_p, 0);
}
|