Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/core/stack_overflow.c
4150 views
1
// Copyright 2014 The Emscripten Authors. All rights reserved.
2
// Emscripten is available under two separate licenses, the MIT license and the
3
// University of Illinois/NCSA Open Source License. Both these licenses can be
4
// found in the LICENSE file.
5
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <stdint.h>
9
#include <emscripten/emscripten.h>
10
#include <emscripten/stack.h>
11
12
void recurse(unsigned long x);
13
14
void act(volatile unsigned long *a) {
15
printf("act %ld\n", *a);
16
unsigned long b = (long)(intptr_t)(alloca(*a));
17
if (b < *a) *a--;
18
recurse(*a);
19
}
20
21
void recurse(volatile unsigned long x) {
22
printf("recurse %ld sp=%#lx\n", x, emscripten_stack_get_current());
23
volatile unsigned long a = x;
24
volatile char buffer[1000*1000];
25
buffer[x/2] = 0;
26
buffer[(x-1)/2] = 0;
27
EM_ASM({});
28
if (x*x < x) {
29
act(&a);
30
if (a < x) x = a;
31
x--;
32
}
33
x += buffer[x/2];
34
if (x > 0) recurse(x-1);
35
}
36
37
int main() {
38
recurse(1000*1000);
39
}
40
41