MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / register_calling_convention

Function register_calling_convention

rust/src/calling_convention.rs:58–430  ·  view source on GitHub ↗
(arch: &A, name: N, cc: C)

Source from the content-addressed store, hash-verified

56}
57
58pub fn register_calling_convention<A, N, C>(arch: &A, name: N, cc: C) -> Ref<CoreCallingConvention>
59where
60 A: Architecture,
61 N: BnStrCompatible,
62 C: 'static + CallingConvention,
63{
64 struct CustomCallingConventionContext<C>
65 where
66 C: CallingConvention,
67 {
68 raw_handle: *mut BNCallingConvention,
69 cc: C,
70 }
71
72 // TODO: It would be nice if these callbacks were moved out to the bottom of this file (maybe in another mod)
73 extern "C" fn cb_free<C>(ctxt: *mut c_void)
74 where
75 C: CallingConvention,
76 {
77 ffi_wrap!("CallingConvention::free", unsafe {
78 let _ctxt = Box::from_raw(ctxt as *mut CustomCallingConventionContext<C>);
79 })
80 }
81
82 extern "C" fn cb_free_register_list(_ctxt: *mut c_void, regs: *mut u32, count: usize) {
83 ffi_wrap!("CallingConvention::free_register_list", unsafe {
84 if regs.is_null() {
85 return;
86 }
87
88 let regs_ptr = std::ptr::slice_from_raw_parts_mut(regs, count);
89 let _regs = Box::from_raw(regs_ptr);
90 })
91 }
92
93 extern "C" fn cb_caller_saved<C>(ctxt: *mut c_void, count: *mut usize) -> *mut u32
94 where
95 C: CallingConvention,
96 {
97 ffi_wrap!("CallingConvention::caller_saved_registers", unsafe {
98 let ctxt = &*(ctxt as *mut CustomCallingConventionContext<C>);
99 let mut regs: Vec<_> = ctxt
100 .cc
101 .caller_saved_registers()
102 .iter()
103 .map(|r| r.0)
104 .collect();
105
106 // SAFETY: `count` is an out parameter
107 *count = regs.len();
108 let regs_ptr = regs.as_mut_ptr();
109 std::mem::forget(regs);
110 regs_ptr
111 })
112 }
113
114 extern "C" fn cb_callee_saved<C>(ctxt: *mut c_void, count: *mut usize) -> *mut u32
115 where

Callers 2

CorePluginInitFunction · 0.85
registerMethod · 0.85

Calls 3

into_bytes_with_nulMethod · 0.80
as_refMethod · 0.45
handleMethod · 0.45

Tested by

no test coverage detected