Debian Codegraph @

rpython/translator/c/src/stack.c

raw symbols SCIP
1 /* Stack operation */
2 #include "common_header.h"
3 #include "structdef.h" /* for struct pypy_threadlocal_s */
4 #include <src/stack.h>
5 #include <src/threadlocal.h>
6 #include <stdio.h>
7
8
9 /* the current stack is in the interval [end-length:end]. We assume a
10 stack that grows downward here. */
11
12 /* (stored in a struct to ensure that stack_end and stack_length are
13 close together; used e.g. by the ppc jit backend) */
14 rpy_stacktoobig_t rpy_stacktoobig = {
15 NULL, /* stack_end */
16 MAX_STACK_SIZE, /* stack_length */
17 1 /* report_error */
18 };
19
20 void LL_stack_set_length_fraction(double fraction)
21 {
22 rpy_stacktoobig.stack_length = (Signed)(MAX_STACK_SIZE * fraction);
23 }
24
25 char LL_stack_too_big_slowpath(Signed current)
26 {
27 Signed diff, max_stack_size;
28 char *baseptr, *curptr = (char*)current;
29 char *tl;
30 struct pypy_threadlocal_s *tl1;
31
32 /* The stack_end variable is updated to match the current value
33 if it is still 0 or if we later find a 'curptr' position
34 that is above it. The real stack_end pointer is stored in
35 thread-local storage, but we try to minimize its overhead by
36 keeping a local copy in rpy_stacktoobig.stack_end. */
37
38 OP_THREADLOCALREF_ADDR(tl);
39 tl1 = (struct pypy_threadlocal_s *)tl;
40 baseptr = tl1->stack_end;
41 max_stack_size = rpy_stacktoobig.stack_length;
42 if (baseptr == NULL) {
43 /* first time we see this thread */
44 }
45 else {
46 diff = baseptr - curptr;
47 if (((Unsigned)diff) <= (Unsigned)max_stack_size) {
48 /* within bounds, probably just had a thread switch */
49 rpy_stacktoobig.stack_end = baseptr;
50 return 0;
51 }
52 if (((Unsigned)-diff) <= (Unsigned)max_stack_size) {
53 /* stack underflowed: the initial estimation of
54 the stack base must be revised */
55 }
56 else { /* stack overflow (probably) */
57 return rpy_stacktoobig.report_error;
58 }
59 }
60
61 /* update the stack base pointer to the current value */
62 baseptr = curptr;
63 tl1->stack_end = baseptr;
64 rpy_stacktoobig.stack_end = baseptr;
65 return 0;
66 }