@@ -12,15 +12,22 @@ use {core::mem::MaybeUninit, frida_gum_sys as gum_sys};
12
12
13
13
// The following function is not exposed through the `frida-gum.h` header, so we don't have an
14
14
// auto-generated binding for it. This may change in a future version.
15
- #[ cfg( not( target_os = "windows" ) ) ]
16
15
extern "C" {
17
16
// On some platforms `ucontext` contains a u128 which does not have a defined ABI. In this case,
18
17
// we disable the error as we assume the behaviour is correct (all other platforms are unaffected).
18
+ #[ cfg( target_os = "linux" ) ]
19
19
#[ allow( improper_ctypes) ]
20
20
fn gum_linux_parse_ucontext (
21
21
context : * const libc:: ucontext_t ,
22
22
cpu_context : * mut gum_sys:: GumCpuContext ,
23
23
) ;
24
+
25
+ #[ cfg( target_os = "freebsd" ) ]
26
+ #[ allow( improper_ctypes) ]
27
+ fn gum_freebsd_parse_ucontext (
28
+ context : * const libc:: ucontext_t ,
29
+ cpu_context : * mut gum_sys:: GumCpuContext ,
30
+ ) ;
24
31
}
25
32
26
33
pub struct Backtracer ;
@@ -84,24 +91,36 @@ impl Backtracer {
84
91
85
92
/// Generate an accurate backtrace as a list of return addresses for the supplied signal
86
93
/// context.
87
- #[ cfg( not ( target_os = "windows " ) ) ]
94
+ #[ cfg( any ( target_os = "linux" , target_os = "freebsd ") ) ]
88
95
pub fn accurate_with_signal_context ( context : & libc:: ucontext_t ) -> Vec < usize > {
89
96
let mut cpu_context = MaybeUninit :: < gum_sys:: GumCpuContext > :: uninit ( ) ;
90
97
91
98
unsafe {
99
+ #[ cfg( target_os = "linux" ) ]
92
100
gum_linux_parse_ucontext ( context as * const libc:: ucontext_t , cpu_context. as_mut_ptr ( ) ) ;
101
+ #[ cfg( target_os = "freebsd" ) ]
102
+ gum_freebsd_parse_ucontext (
103
+ context as * const libc:: ucontext_t ,
104
+ cpu_context. as_mut_ptr ( ) ,
105
+ ) ;
93
106
Self :: accurate_with_context ( & cpu_context. assume_init ( ) )
94
107
}
95
108
}
96
109
97
110
/// Generate a fuzzy backtrace as a list of return addresses for the supplied signal
98
111
/// context.
99
- #[ cfg( not ( target_os = "windows " ) ) ]
112
+ #[ cfg( any ( target_os = "linux" , target_os = "freebsd ") ) ]
100
113
pub fn fuzzy_with_signal_context ( context : & libc:: ucontext_t ) -> Vec < usize > {
101
114
let mut cpu_context = MaybeUninit :: < gum_sys:: GumCpuContext > :: uninit ( ) ;
102
115
103
116
unsafe {
117
+ #[ cfg( target_os = "linux" ) ]
104
118
gum_linux_parse_ucontext ( context as * const libc:: ucontext_t , cpu_context. as_mut_ptr ( ) ) ;
119
+ #[ cfg( target_os = "freebsd" ) ]
120
+ gum_freebsd_parse_ucontext (
121
+ context as * const libc:: ucontext_t ,
122
+ cpu_context. as_mut_ptr ( ) ,
123
+ ) ;
105
124
Self :: fuzzy_with_context ( & cpu_context. assume_init ( ) )
106
125
}
107
126
}
0 commit comments