@@ -12,15 +12,22 @@ use {core::mem::MaybeUninit, frida_gum_sys as gum_sys};
1212
1313// The following function is not exposed through the `frida-gum.h` header, so we don't have an
1414// auto-generated binding for it. This may change in a future version.
15- #[ cfg( not( target_os = "windows" ) ) ]
1615extern "C" {
1716 // On some platforms `ucontext` contains a u128 which does not have a defined ABI. In this case,
1817 // we disable the error as we assume the behaviour is correct (all other platforms are unaffected).
18+ #[ cfg( target_os = "linux" ) ]
1919 #[ allow( improper_ctypes) ]
2020 fn gum_linux_parse_ucontext (
2121 context : * const libc:: ucontext_t ,
2222 cpu_context : * mut gum_sys:: GumCpuContext ,
2323 ) ;
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+ ) ;
2431}
2532
2633pub struct Backtracer ;
@@ -84,24 +91,36 @@ impl Backtracer {
8491
8592 /// Generate an accurate backtrace as a list of return addresses for the supplied signal
8693 /// context.
87- #[ cfg( not ( target_os = "windows " ) ) ]
94+ #[ cfg( any ( target_os = "linux" , target_os = "freebsd ") ) ]
8895 pub fn accurate_with_signal_context ( context : & libc:: ucontext_t ) -> Vec < usize > {
8996 let mut cpu_context = MaybeUninit :: < gum_sys:: GumCpuContext > :: uninit ( ) ;
9097
9198 unsafe {
99+ #[ cfg( target_os = "linux" ) ]
92100 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+ ) ;
93106 Self :: accurate_with_context ( & cpu_context. assume_init ( ) )
94107 }
95108 }
96109
97110 /// Generate a fuzzy backtrace as a list of return addresses for the supplied signal
98111 /// context.
99- #[ cfg( not ( target_os = "windows " ) ) ]
112+ #[ cfg( any ( target_os = "linux" , target_os = "freebsd ") ) ]
100113 pub fn fuzzy_with_signal_context ( context : & libc:: ucontext_t ) -> Vec < usize > {
101114 let mut cpu_context = MaybeUninit :: < gum_sys:: GumCpuContext > :: uninit ( ) ;
102115
103116 unsafe {
117+ #[ cfg( target_os = "linux" ) ]
104118 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+ ) ;
105124 Self :: fuzzy_with_context ( & cpu_context. assume_init ( ) )
106125 }
107126 }
0 commit comments