summaryrefslogtreecommitdiff
path: root/ext/-test-/stack/stack.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2025-04-17 22:21:51 +0900
committerGitHub <noreply@github.com>2025-04-17 13:21:51 +0000
commitc4ae6cb5005cfa53be0af466a5619e7455c15744 (patch)
treee7ef4d21cab0c9bb4253ca9f00c19c5d73b86e2e /ext/-test-/stack/stack.c
parent6062c904ae2c4d6a9fafb1a0e22841da85892eea (diff)
Prefer `th->ec` for stack base/size. (#13101)
Notes
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'ext/-test-/stack/stack.c')
-rw-r--r--ext/-test-/stack/stack.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/-test-/stack/stack.c b/ext/-test-/stack/stack.c
new file mode 100644
index 0000000000..d69ca4da84
--- /dev/null
+++ b/ext/-test-/stack/stack.c
@@ -0,0 +1,24 @@
+#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;
+}
+
+void
+Init_stack(VALUE klass)
+{
+ rb_define_singleton_method(rb_cThread, "alloca_overflow", stack_alloca_overflow, 0);
+}