Merge "Add safety comments." into main
This commit is contained in:
commit
406d43397c
2 changed files with 7 additions and 2 deletions
|
|
@ -111,7 +111,9 @@ lazy_static! {
|
||||||
static ref COOKIES: Mutex<HashMap<i32, fn() -> StatsPullResult>> = Mutex::new(HashMap::new());
|
static ref COOKIES: Mutex<HashMap<i32, fn() -> StatsPullResult>> = Mutex::new(HashMap::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Safety: We store our callbacks in the global so they are valid.
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// `data` must be a valid pointer with no aliases.
|
||||||
unsafe extern "C" fn callback_wrapper(
|
unsafe extern "C" fn callback_wrapper(
|
||||||
atom_tag: i32,
|
atom_tag: i32,
|
||||||
data: *mut AStatsEventList,
|
data: *mut AStatsEventList,
|
||||||
|
|
@ -126,7 +128,8 @@ unsafe extern "C" fn callback_wrapper(
|
||||||
let stats = cb();
|
let stats = cb();
|
||||||
let result = stats
|
let result = stats
|
||||||
.iter()
|
.iter()
|
||||||
.map(|stat| stat.add_astats_event(&mut *data))
|
// Safety: The caller promises that `data` is valid and unaliased.
|
||||||
|
.map(|stat| stat.add_astats_event(unsafe { &mut *data }))
|
||||||
.collect::<Result<Vec<()>, StatsError>>();
|
.collect::<Result<Vec<()>, StatsError>>();
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,8 @@ impl TipcChannel {
|
||||||
let file = File::options().read(true).write(true).open(device)?;
|
let file = File::options().read(true).write(true).open(device)?;
|
||||||
|
|
||||||
let srv_name = CString::new(service).expect("Service name contained null bytes");
|
let srv_name = CString::new(service).expect("Service name contained null bytes");
|
||||||
|
// SAFETY: The file descriptor is valid because it came from a `File`, and the name is a
|
||||||
|
// valid C string because it came from a `CString`.
|
||||||
unsafe {
|
unsafe {
|
||||||
tipc_connect(file.as_raw_fd(), srv_name.as_ptr())?;
|
tipc_connect(file.as_raw_fd(), srv_name.as_ptr())?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue