-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new device trait in setup process, custom logging
Forwarding logging/callbacks by saving DeviceContext in vfu_ctx private pointer
- Loading branch information
1 parent
e295369
commit 5a71d64
Showing
2 changed files
with
75 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::ffi::CStr; | ||
use std::os::raw::{c_char, c_int}; | ||
|
||
use libvfio_user_sys::*; | ||
|
||
use crate::{Device, DeviceContext}; | ||
|
||
// Use macro to avoid having to specify a lifetime | ||
macro_rules! device_context_from_vfu_ctx { | ||
($vfu_ctx:ident) => {{ | ||
let private = vfu_get_private($vfu_ctx); | ||
&mut *(private as *mut DeviceContext<T>) | ||
}}; | ||
} | ||
|
||
pub(crate) unsafe extern "C" fn log_callback<T: Device>( | ||
vfu_ctx: *mut vfu_ctx_t, | ||
level: c_int, | ||
msg: *const c_char, | ||
) { | ||
let device_context = device_context_from_vfu_ctx!(vfu_ctx); | ||
let msg = unsafe { CStr::from_ptr(msg) }; | ||
|
||
device_context.device.log(level, msg.to_str().unwrap()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters