1
1
use backtrace:: Frame ;
2
+ use core:: ffi:: c_void;
2
3
use std:: ptr;
3
4
use std:: thread;
4
5
5
- fn get_actual_fn_pointer ( fp : usize ) -> usize {
6
+ fn get_actual_fn_pointer ( fp : * mut c_void ) -> * mut c_void {
6
7
// On AIX, the function name references a function descriptor.
7
8
// A function descriptor consists of (See https://reviews.llvm.org/D62532)
8
9
// * The address of the entry point of the function.
@@ -15,17 +16,18 @@ fn get_actual_fn_pointer(fp: usize) -> usize {
15
16
// https://www.ibm.com/docs/en/aix/7.2?topic=program-understanding-programming-toc
16
17
if cfg ! ( target_os = "aix" ) {
17
18
unsafe {
18
- let actual_fn_entry = * ( fp as * const usize ) ;
19
+ let actual_fn_entry = * ( fp as * const * mut c_void ) ;
19
20
actual_fn_entry
20
21
}
21
22
} else {
22
- fp
23
+ fp as * mut c_void
23
24
}
24
25
}
25
26
26
27
#[ test]
27
28
// FIXME: shouldn't ignore this test on i686-msvc, unsure why it's failing
28
29
#[ cfg_attr( all( target_arch = "x86" , target_env = "msvc" ) , ignore) ]
30
+ #[ inline( never) ]
29
31
#[ rustfmt:: skip] // we care about line numbers here
30
32
fn smoke_test_frames ( ) {
31
33
frame_1 ( line ! ( ) ) ;
@@ -42,10 +44,10 @@ fn smoke_test_frames() {
42
44
// Various platforms have various bits of weirdness about their
43
45
// backtraces. To find a good starting spot let's search through the
44
46
// frames
45
- let target = get_actual_fn_pointer ( frame_4 as usize ) ;
47
+ let target = get_actual_fn_pointer ( frame_4 as * mut c_void ) ;
46
48
let offset = v
47
49
. iter ( )
48
- . map ( |frame| frame. symbol_address ( ) as usize )
50
+ . map ( |frame| frame. symbol_address ( ) )
49
51
. enumerate ( )
50
52
. filter_map ( |( i, sym) | {
51
53
if sym >= target {
@@ -61,39 +63,39 @@ fn smoke_test_frames() {
61
63
62
64
assert_frame (
63
65
frames. next ( ) . unwrap ( ) ,
64
- get_actual_fn_pointer ( frame_4 as usize ) ,
66
+ get_actual_fn_pointer ( frame_4 as * mut c_void ) as usize ,
65
67
"frame_4" ,
66
68
"tests/smoke.rs" ,
67
69
start_line + 6 ,
68
70
9 ,
69
71
) ;
70
72
assert_frame (
71
73
frames. next ( ) . unwrap ( ) ,
72
- get_actual_fn_pointer ( frame_3 as usize ) ,
74
+ get_actual_fn_pointer ( frame_3 as * mut c_void ) as usize ,
73
75
"frame_3" ,
74
76
"tests/smoke.rs" ,
75
77
start_line + 3 ,
76
78
52 ,
77
79
) ;
78
80
assert_frame (
79
81
frames. next ( ) . unwrap ( ) ,
80
- get_actual_fn_pointer ( frame_2 as usize ) ,
82
+ get_actual_fn_pointer ( frame_2 as * mut c_void ) as usize ,
81
83
"frame_2" ,
82
84
"tests/smoke.rs" ,
83
85
start_line + 2 ,
84
86
52 ,
85
87
) ;
86
88
assert_frame (
87
89
frames. next ( ) . unwrap ( ) ,
88
- get_actual_fn_pointer ( frame_1 as usize ) ,
90
+ get_actual_fn_pointer ( frame_1 as * mut c_void ) as usize ,
89
91
"frame_1" ,
90
92
"tests/smoke.rs" ,
91
93
start_line + 1 ,
92
94
52 ,
93
95
) ;
94
96
assert_frame (
95
97
frames. next ( ) . unwrap ( ) ,
96
- get_actual_fn_pointer ( smoke_test_frames as usize ) ,
98
+ get_actual_fn_pointer ( smoke_test_frames as * mut c_void ) as usize ,
97
99
"smoke_test_frames" ,
98
100
"" ,
99
101
0 ,
@@ -249,11 +251,11 @@ fn sp_smoke_test() {
249
251
return ;
250
252
251
253
#[ inline( never) ]
252
- fn recursive_stack_references ( refs : & mut Vec < usize > ) {
254
+ fn recursive_stack_references ( refs : & mut Vec < * mut c_void > ) {
253
255
assert ! ( refs. len( ) < 5 ) ;
254
256
255
- let x = refs. len ( ) ;
256
- refs. push ( ptr:: addr_of !( x) as usize ) ;
257
+ let mut x = refs. len ( ) ;
258
+ refs. push ( ptr:: addr_of_mut !( x) . cast ( ) ) ;
257
259
258
260
if refs. len ( ) < 5 {
259
261
recursive_stack_references ( refs) ;
@@ -271,7 +273,7 @@ fn sp_smoke_test() {
271
273
// mangled names.
272
274
273
275
fn make_trace_closure < ' a > (
274
- refs : & ' a mut Vec < usize > ,
276
+ refs : & ' a mut Vec < * mut c_void > ,
275
277
) -> impl FnMut ( & backtrace:: Frame ) -> bool + ' a {
276
278
let mut child_sp = None ;
277
279
let mut child_ref = None ;
@@ -289,9 +291,9 @@ fn sp_smoke_test() {
289
291
} )
290
292
} ) ;
291
293
292
- let sp = frame. sp ( ) as usize ;
293
- eprintln ! ( "sp = {:p}" , sp as * const u8 ) ;
294
- if sp == 0 {
294
+ let sp = frame. sp ( ) ;
295
+ eprintln ! ( "sp = {sp :p}" ) ;
296
+ if sp as usize == 0 {
295
297
// If the SP is null, then we don't have an implementation for
296
298
// getting the SP on this target. Just keep walking the stack,
297
299
// but don't make our assertions about the on-stack pointers and
@@ -306,8 +308,8 @@ fn sp_smoke_test() {
306
308
307
309
if is_recursive_stack_references {
308
310
let r = refs. pop ( ) . unwrap ( ) ;
309
- eprintln ! ( "ref = {:p}" , r as * const u8 ) ;
310
- if sp != 0 {
311
+ eprintln ! ( "ref = {:p}" , r) ;
312
+ if sp as usize != 0 {
311
313
assert ! ( r > sp) ;
312
314
if let Some ( child_ref) = child_ref {
313
315
assert ! ( sp >= child_ref) ;
0 commit comments