6 /* This is the same as wrap5.c, except that the recursion depth is 16.
7 This is intended to check that on ppc64-linux, which uses a
8 16-entry per-thread stack, the resulting stack overflow is caught.
9 (Undetected overflows in redirection stacks are very bad news; they
10 cause guest code to fail in all sorts of strange ways.)
12 Hence this test has two expected outcomes:
13 - on ppc64-linux, a stack overflow is caught, and V aborts.
14 - on everything else, it runs successfully to completion.
15 Note, pre() and post() used so as to avoid printf, which messes
16 up the call stacks on ppc64-linux due to intercept of mempcpy.
27 void addMoreLard ( void )
32 p
= malloc(sizeof(Lard
));
37 static void post ( char* s
, int n
, int r
);
38 static void pre ( char* s
, int n
);
39 static int fact1 ( int n
);
40 static int fact2 ( int n
);
42 /* This is needed to stop gcc4 turning 'fact' into a loop */
43 __attribute__((noinline
))
44 int mul ( int x
, int y
) { return x
* y
; }
49 if (n
== 0) return 1; else return mul(n
, fact2(n
-1));
54 if (n
== 0) return 1; else return mul(n
, fact1(n
-1));
58 int I_WRAP_SONAME_FNNAME_ZU(NONE
,fact1
) ( int n
)
62 VALGRIND_GET_ORIG_FN(fn
);
65 CALL_FN_W_W(r
, fn
, n
);
67 post("wrapper1", n
, r
);
68 if (n
>= 3) r
+= fact2(2);
72 int I_WRAP_SONAME_FNNAME_ZU(NONE
,fact2
) ( int n
)
76 VALGRIND_GET_ORIG_FN(fn
);
79 CALL_FN_W_W(r
, fn
, n
);
81 post("wrapper2", n
, r
);
89 int r
, n
= 15; /* 14 succeeds on ppc64-linux, >= 15 fails */
91 printf("computing fact1(%d)\n", n
); fflush(stdout
);
93 printf("fact1(%d) = %d\n", n
, r
); fflush(stdout
);
95 printf("allocated %d Lards\n", ctr
); fflush(stdout
);
96 for (p
= lard
; p
; p
= p_next
) {
104 static void send ( char* s
)
112 static void pre ( char* s
, int n
)
116 sprintf(buf
,"%d", n
);
125 static void post ( char* s
, int n
, int r
)
129 sprintf(buf
,"%d", n
);
132 send("-post: fact(");
135 sprintf(buf
,"%d", r
);