Hello, I am making a function call from Rust code to C code. The C code is a binary blob and not compiler by me. All I know about this binary blob is the entry point of a particular function.
Here is the function declaration in C:
typedef EFI_STATUS (EFIAPI *FSP_MEMORY_INIT) (VOID* FspmUpdDataPtr, VOID **HobListPtr);
When I run bindgen on this function declaration, I get:
pub type FSP_MEMORY_INIT = ::core::option::Option<unsafe extern "win64" fn(FspmUpdDataPtr: *mut ::core::ffi::c_void, HobListPtr: *mut *mut ::core::ffi::c_void) -> EFI_STATUS>;
Supposing I have an address stored in a usize
variable called fsp_base
, how do I convert this address to this function pointer type?
What has stumped me in doing the conversion is the Option
type. If I write out the same function typedef without the Option
, I can easily transmute:
type FspMemoryInit = unsafe extern "win64" fn(
FspmUpdDataPtr: *mut core::ffi::c_void,
HobListPtr: *mut *mut core::ffi::c_void,
) -> efi::EFI_STATUS;
let fspm = core::mem::transmute::<usize, FspMemoryInit>(fsp_base);
My goal is to use bindgen. How can I accomplish this same conversion with the function type generated by bindgen?