-
Notifications
You must be signed in to change notification settings - Fork 18
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
Contracts and harnesses for dangling
, from_raw_parts
, slice_from_raw_parts
, to_raw_parts
in NonNull
#127
base: main
Are you sure you want to change the base?
Contracts and harnesses for dangling
, from_raw_parts
, slice_from_raw_parts
, to_raw_parts
in NonNull
#127
Conversation
…/danielhumanmod/verify-rust-std into olivia/pointer_creation_and_init
#[kani::proof_for_contract(NonNull::from_raw_parts)] | ||
pub fn non_null_check_from_raw_parts() { | ||
|
||
const arr_len: usize = 100; |
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.
The names of consts should be upper case (see https://doc.rust-lang.org/1.0.0/style/style/naming/README.html).
#[kani::proof_for_contract(NonNull::slice_from_raw_parts)] | ||
#[kani::unwind(11)] | ||
pub fn non_null_check_slice_from_raw_parts() { | ||
const arr_len: usize = 10; |
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.
Same here
#[stable(feature = "nonnull_slice_from_raw_parts", since = "1.70.0")] | ||
#[rustc_const_stable(feature = "const_slice_from_raw_parts_mut", since = "1.83.0")] | ||
#[must_use] | ||
#[inline] | ||
#[requires(data.pointer.is_aligned() | ||
&& len as isize * core::mem::size_of::<T>() as isize <= isize::MAX |
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.
Isn't this subsumed by the next conjunct?
&& len as isize * core::mem::size_of::<T>() as isize <= isize::MAX | ||
&& (len as isize).checked_mul(core::mem::size_of::<T>() as isize).is_some() | ||
&& (data.pointer as isize).checked_add(len as isize * core::mem::size_of::<T>() as isize).is_some() // adding len must not “wrap around” the address space | ||
&& unsafe { kani::mem::same_allocation(data.pointer, data.pointer.add(len)) })] |
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.
Another safety requirement is that data
must be valid for reads. This can be specified using can_dereference
.
Towards #53
Contracts and harnesses for
dangling
,from_raw_parts
,slice_from_raw_parts
,to_raw_parts
in NonNullDiscussion
NonNull::slice_from_raw_parts
: requested new Kani API to compare byte by byteNonNull::to_raw_parts
: unstable vtable comparison 'Eq'Verification Result
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.