55//! 
66//! This module provides C-compatible FFI bindings for registering runtime-specific 
77//! crash callbacks that can provide stack traces for dynamic languages. 
8+ #[ cfg( unix) ]  
89use  datadog_crashtracker:: { 
910    get_registered_callback_type_ptr,  is_runtime_callback_registered, 
10-     register_runtime_stack_callback,  CallbackError ,  CallbackType ,  RuntimeStackCallback , 
11+     register_runtime_frame_callback,  register_runtime_stacktrace_string_callback,  CallbackError , 
12+     RuntimeFrameCallback ,  RuntimeStacktraceStringCallback , 
1113} ; 
1214
13- // Re-export the enums for C/C++ consumers 
14- pub  use  datadog_crashtracker:: CallbackType  as  ddog_CallbackType; 
15- 
1615pub  use  datadog_crashtracker:: RuntimeStackFrame  as  ddog_RuntimeStackFrame; 
1716
1817/// Result type for runtime callback registration 
@@ -65,19 +64,43 @@ impl From<CallbackError> for CallbackResult {
6564/// } 
6665/// 
6766/// 
68- /// ddog_CallbackResult result = ddog_crasht_register_runtime_stack_callback( 
69- ///     my_runtime_callback, 
70- ///     CallbackType::Frame, 
67+ /// ddog_CallbackResult result = ddog_crasht_register_runtime_frame_callback( 
68+ ///     my_runtime_callback 
7169/// ); 
7270/// ``` 
73- /// Register a runtime stack collection callback using type-safe enums 
71+ /// Register a runtime frame collection callback 
72+ /// 
73+ /// This function allows language runtimes to register a callback that will be invoked 
74+ /// during crash handling to collect runtime-specific stack frames. 
75+ /// 
76+ /// # Arguments 
77+ /// - `callback`: The callback function to invoke during crashes 
78+ /// 
79+ /// # Returns 
80+ /// - `CallbackResult::Ok` if registration succeeds (replaces any existing callback) 
81+ /// - `CallbackResult::Error` if registration fails 
82+ /// 
83+ /// # Safety 
84+ /// - The callback must be signal-safe 
85+ /// - Only one callback can be registered at a time (this replaces any existing one) 
86+ #[ cfg( unix) ]  
87+ #[ no_mangle]  
88+ pub  unsafe  extern  "C"  fn  ddog_crasht_register_runtime_frame_callback ( 
89+     callback :  RuntimeFrameCallback , 
90+ )  -> CallbackResult  { 
91+     match  register_runtime_frame_callback ( callback)  { 
92+         Ok ( ( ) )  => CallbackResult :: Ok , 
93+         Err ( e)  => e. into ( ) , 
94+     } 
95+ } 
96+ 
97+ /// Register a runtime stacktrace string collection callback 
7498/// 
75- /// This function provides compile-time safety by using enums instead of strings  
76- /// for runtime and callback types . 
99+ /// This function allows language runtimes to register a callback that will be invoked  
100+ /// during crash handling to collect runtime-specific stacktrace strings . 
77101/// 
78102/// # Arguments 
79103/// - `callback`: The callback function to invoke during crashes 
80- /// - `callback_type`: Callback type enum (Frame, StacktraceString) 
81104/// 
82105/// # Returns 
83106/// - `CallbackResult::Ok` if registration succeeds (replaces any existing callback) 
@@ -86,12 +109,12 @@ impl From<CallbackError> for CallbackResult {
86109/// # Safety 
87110/// - The callback must be signal-safe 
88111/// - Only one callback can be registered at a time (this replaces any existing one) 
112+ #[ cfg( unix) ]  
89113#[ no_mangle]  
90- pub  unsafe  extern  "C"  fn  ddog_crasht_register_runtime_stack_callback ( 
91-     callback :  RuntimeStackCallback , 
92-     callback_type :  CallbackType , 
114+ pub  unsafe  extern  "C"  fn  ddog_crasht_register_runtime_stacktrace_string_callback ( 
115+     callback :  RuntimeStacktraceStringCallback , 
93116)  -> CallbackResult  { 
94-     match  register_runtime_stack_callback ( callback,  callback_type )  { 
117+     match  register_runtime_stacktrace_string_callback ( callback)  { 
95118        Ok ( ( ) )  => CallbackResult :: Ok , 
96119        Err ( e)  => e. into ( ) , 
97120    } 
@@ -103,6 +126,7 @@ pub unsafe extern "C" fn ddog_crasht_register_runtime_stack_callback(
103126/// 
104127/// # Safety 
105128/// This function is safe to call at any time 
129+ #[ cfg( unix) ]  
106130#[ no_mangle]  
107131pub  extern  "C"  fn  ddog_crasht_is_runtime_callback_registered ( )  -> bool  { 
108132    is_runtime_callback_registered ( ) 
@@ -117,6 +141,7 @@ pub extern "C" fn ddog_crasht_is_runtime_callback_registered() -> bool {
117141/// - The returned pointer is valid only while the callback remains registered 
118142/// - The caller should not free the returned pointer 
119143/// - The returned string should be copied if it needs to persist beyond callback lifetime 
144+ #[ cfg( unix) ]  
120145#[ no_mangle]  
121146pub  unsafe  extern  "C"  fn  ddog_crasht_get_registered_callback_type ( )  -> * const  std:: ffi:: c_char  { 
122147    get_registered_callback_type_ptr ( ) 
@@ -134,9 +159,8 @@ mod tests {
134159    // with the global static variable 
135160    static  TEST_MUTEX :  Mutex < ( ) >  = Mutex :: new ( ( ) ) ; 
136161
137-     unsafe  extern  "C"  fn  test_runtime_callback ( 
162+     unsafe  extern  "C"  fn  test_frame_callback ( 
138163        emit_frame :  unsafe  extern  "C"  fn ( * const  RuntimeStackFrame ) , 
139-         _emit_stacktrace_string :  unsafe  extern  "C"  fn ( * const  c_char ) , 
140164    )  { 
141165        let  function_name = "TestModule.TestClass.test_function" ; 
142166        let  file_name = "test.rb" ; 
@@ -151,6 +175,13 @@ mod tests {
151175        emit_frame ( & frame) ; 
152176    } 
153177
178+     unsafe  extern  "C"  fn  test_stacktrace_string_callback ( 
179+         emit_stacktrace_string :  unsafe  extern  "C"  fn ( * const  c_char ) , 
180+     )  { 
181+         let  stacktrace_string = "test_stacktrace_string\0 " ; 
182+         emit_stacktrace_string ( stacktrace_string. as_ptr ( )  as  * const  c_char ) ; 
183+     } 
184+ 
154185    #[ test]  
155186    fn  test_callback_registration ( )  { 
156187        let  _guard = TEST_MUTEX . lock ( ) . unwrap ( ) ; 
@@ -159,9 +190,8 @@ mod tests {
159190
160191            assert ! ( !ddog_crasht_is_runtime_callback_registered( ) ) ; 
161192
162-             let  result = ddog_crasht_register_runtime_stack_callback ( 
163-                 test_runtime_callback, 
164-                 CallbackType :: StacktraceString , 
193+             let  result = ddog_crasht_register_runtime_stacktrace_string_callback ( 
194+                 test_stacktrace_string_callback, 
165195            ) ; 
166196
167197            assert_eq ! ( result,  CallbackResult :: Ok ) ; 
@@ -174,10 +204,7 @@ mod tests {
174204                . unwrap ( ) ; 
175205            assert_eq ! ( callback_type_str,  "stacktrace_string" ) ; 
176206
177-             let  result = ddog_crasht_register_runtime_stack_callback ( 
178-                 test_runtime_callback, 
179-                 CallbackType :: Frame , 
180-             ) ; 
207+             let  result = ddog_crasht_register_runtime_frame_callback ( test_frame_callback) ; 
181208
182209            assert_eq ! ( result,  CallbackResult :: Ok ) ; 
183210
0 commit comments