1
-
1
+ #include <unistd.h>
2
2
#include <stdio.h>
3
3
#include <malloc.h>
4
4
#include <stdlib.h>
13
13
Hence this test has two expected outcomes:
14
14
- on ppc64-linux, a stack overflow is caught, and V aborts.
15
15
- on everything else, it runs successfully to completion.
16
+ Note, pre() and post() used so as to avoid printf, which messes
17
+ up the call stacks on ppc64-linux due to intercept of mempcpy.
16
18
*/
17
-
18
19
typedef
19
20
struct _Lard {
20
21
struct _Lard * next ;
21
22
char stuff [999 ];
22
23
}
23
24
Lard ;
24
-
25
25
Lard * lard = NULL ;
26
26
static int ctr = 0 ;
27
27
@@ -35,8 +35,8 @@ void addMoreLard ( void )
35
35
lard = p ;
36
36
}
37
37
}
38
-
39
-
38
+ static void post ( char * s , int n , int r );
39
+ static void pre ( char * s , int n );
40
40
static int fact1 ( int n );
41
41
static int fact2 ( int n );
42
42
@@ -61,11 +61,11 @@ int I_WRAP_SONAME_FNNAME_ZU(NONE,fact1) ( int n )
61
61
int r ;
62
62
OrigFn fn ;
63
63
VALGRIND_GET_ORIG_FN (fn );
64
- printf ( "in wrapper1-pre: fact(%d)\n " , n ); fflush ( stdout );
64
+ pre ( " wrapper1" , n );
65
65
addMoreLard ();
66
66
CALL_FN_W_W (r , fn , n );
67
67
addMoreLard ();
68
- printf ( "in wrapper1-post: fact(%d) = %d\n " , n , r ); fflush ( stdout );
68
+ post ( " wrapper1" , n , r );
69
69
if (n >= 3 ) r += fact2 (2 );
70
70
return r ;
71
71
}
@@ -75,11 +75,11 @@ int I_WRAP_SONAME_FNNAME_ZU(NONE,fact2) ( int n )
75
75
int r ;
76
76
OrigFn fn ;
77
77
VALGRIND_GET_ORIG_FN (fn );
78
- printf ( "in wrapper2-pre: fact(%d)\n " , n ); fflush ( stdout );
78
+ pre ( " wrapper2" , n );
79
79
addMoreLard ();
80
80
CALL_FN_W_W (r , fn , n );
81
81
addMoreLard ();
82
- printf ( "in wrapper2-post: fact(%d) = %d\n " , n , r ); fflush ( stdout );
82
+ post ( " wrapper2" , n , r );
83
83
return r ;
84
84
}
85
85
@@ -101,3 +101,40 @@ int main ( void )
101
101
102
102
return 0 ;
103
103
}
104
+
105
+ static void send ( char * s )
106
+ {
107
+ while (* s ) {
108
+ write (1 , s , 1 );
109
+ s ++ ;
110
+ }
111
+ }
112
+
113
+ static void pre ( char * s , int n )
114
+ {
115
+ char buf [50 ];
116
+ fflush (stdout );
117
+ sprintf (buf ,"%d" , n );
118
+ send ("in " );
119
+ send (s );
120
+ send ("-pre: fact(" );
121
+ send (buf );
122
+ send (")\n" );
123
+ fflush (stdout );
124
+ }
125
+
126
+ static void post ( char * s , int n , int r )
127
+ {
128
+ char buf [50 ];
129
+ fflush (stdout );
130
+ sprintf (buf ,"%d" , n );
131
+ send ("in " );
132
+ send (s );
133
+ send ("-post: fact(" );
134
+ send (buf );
135
+ send (") = " );
136
+ sprintf (buf ,"%d" , r );
137
+ send (buf );
138
+ send ("\n" );
139
+ fflush (stdout );
140
+ }
0 commit comments