Are all referents contiguous?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
Hướng nghiên cứu
Start with the as_bytes example and its safety comment. Investigate whether Rust's reference model guarantees contiguous referents, including the non-contiguous case described and its implications for unsafe code. Done means a resolved, documented answer to the question, rather than an isolated code change.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Consider the following code:
use zerocopy::{Immutable, IntoBytes};
fn as_bytes<T: ?Sized + IntoBytes + Immutable>(t: &T) -> &[u8] {
let len = size_of_val(t);
let ptr: *const T = t;
// SAFETY:
// - By `T: IntoBytes`, all of the bytes in `*t` are initialized to valid `u8`s
// - By `T: Immutable`, `T` does not permit interior mutation, and neither does `[u8]`
// - The constructed pointer's referent has the same bytes as `*t`. By invariant on `&T`,
// this means that the referent is either zero-sized or lives in a single allocation which
// lives for at least as long as the lifetime of the input/output references to this function.
unsafe { core::ptr::slice_from_raw_parts(ptr.cast::<u8>(), len) }
}
This safety comment implicitly assumes that *t is contiguous. If it isn't (e.g., if it contains bytes at addresses 1 and 3 but not 2), then the safety comment is wrong, and the code is unsound since the returned reference refers to bytes which may not be allocated, may not be initialized, may be subject to interior mutation, etc.
This makes me think that we basically need to guarantee that all pointers refer to contiguous sets of bytes, or else tons of unsafe code is unsound, and it would be very difficult to write sound unsafe code. Every time you did a transmute, you'd need to reason about whether the referents of the source and destination types had the same "holes".
Should we just bite the bullet and guarantee that all referents are contiguous in memory? Have we already guaranteed this somewhere that I'm not aware of?
cc @jswrenn
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 760
- Fork
- 68
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/unsafe-code-guidelines
-
I-opsem-nominated
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
rust-lang/unsafe-code-guidelines#634 · 5 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
rust-lang/unsafe-code-guidelines#632 · 8 bình luận · 1 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
rust-lang/unsafe-code-guidelines#631 · 7 bình luận ·
-
I-opsem-nominated
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
rust-lang/unsafe-code-guidelines#630 · 1 reaction ·
Tất cả issue của rust-lang/unsafe-code-guidelines
Issue tương tự
-
bug core-lang
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentenceĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mw00/project-maya#1368 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
foundry-rs/foundry#18828 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày