-
Notifications
You must be signed in to change notification settings - Fork 471
Add some missing // SAFETY
comments
#475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,12 @@ use core::fmt; | |
use crate::bindings; | ||
use crate::c_types::{c_char, c_void}; | ||
|
||
// Called from `vsprintf` with format specifier `%pA`. | ||
/// Called from `vsprintf` with format specifier `%pA`. | ||
/// | ||
/// # Safety | ||
/// | ||
/// The region between `buf` and `end` must be valid for writes. | ||
/// `ptr` must point to a valid instance of `fmt::Arguments`. | ||
#[no_mangle] | ||
unsafe fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_void) -> *mut c_char { | ||
use fmt::Write; | ||
|
@@ -33,7 +38,7 @@ unsafe fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_vo | |
// `buf` goes past `end`. | ||
let len_to_copy = cmp::min(buf_new, self.end).saturating_sub(self.buf); | ||
|
||
// SAFETY: In any case, `buf` is non-null and properly aligned. | ||
// SAFETY: The caller guarantees `buf` is non-null and properly aligned. | ||
// If `len_to_copy` is non-zero, then we know `buf` has not past | ||
// `end` yet and so is valid. | ||
unsafe { | ||
|
@@ -53,6 +58,7 @@ unsafe fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_vo | |
buf: buf as _, | ||
end: end as _, | ||
}; | ||
// SAFETY: the caller must guarantee that `ptr` is valid. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documented the safety contract, though I'm not entirely sure it is correct |
||
let _ = w.write_fmt(unsafe { *(ptr as *const fmt::Arguments<'_>) }); | ||
w.buf as _ | ||
} | ||
|
@@ -132,6 +138,7 @@ pub unsafe fn call_printk( | |
args: fmt::Arguments<'_>, | ||
) { | ||
// `_printk` does not seem to fail in any path. | ||
// SAFETY: this is safe by the safety contract. | ||
unsafe { | ||
bindings::_printk( | ||
format_string.as_ptr() as _, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... it is valid for reads because we check
len <= PAGE_SIZE
, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this was redundant with the previous comment
I can repeat it if you prefer however.