-
Notifications
You must be signed in to change notification settings - Fork 59
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
Canvas unsafe code in the wild #146
Comments
I think they're well enough summarized. (see here) referencing pcb |
Another use of unsafe code, this one more type-focused than lifetime-focused: https://github.com/Diggsey/query_interface |
https://github.com/nathan7/libfringe is wildly unsafe. |
This discussion of how coroutines and scoped threads interact seems relevant, probably more as a negative case (i.e., enumerate where the coroutine abstractions goes wrong): https://www.reddit.com/r/rust/comments/508pkb/unleakable_crate_safetysanityrefocus/d72703d |
That is more of a soundness issue than a memory model issue. |
I don't entirely understand what is the criterion for listing pieces of the standard library. Certainly |
The problem with We aren't suggesting removing |
What I am asking is why |
I see, that makes sense. Notice that the trouble I am having with |
What's the trouble again? |
@RalfJung if you see some other aspect of ref-cell that's not documented, please do open another issue... |
I think the long version of this needs a blogpost, and I don't know when I will get around to write it -- and I'm still in the process of figuring out the details. I don't necessarily think it's an "issue" in the sense of something that needs to be fixed, it's more of an observation that I will try a short summary, but beware -- I am thinking in terms of "how to prove the code correct" here, not in terms of a static type system or a memory model. fn foo(x: &mut i32) {
*x = 13;
{ let y = &*x;
{ let z = &*y; }
}
} the sharing of the data pointed to by |
That is the union of the active lifetimes of the guards. This is also the lifetime of the sharing of an |
What exactly do you mean by "active lifetime of the guards"? It's certainly not the lifetime parameter in
I think |
Active lifetime = intersection of data lifetime and lifetimes of all type parameters. Note that |
The Servo-Gecko interface in stylo uses tons of unsafe code (which I'm trying to reduce and refactor). We make some (iffy) assumptions about unsafe code including:
|
@Manishearth I think, eventually, the fourth will be undefined behavior, but the other three seem like correct assumptions. (although ArcInner is not equivalent to #[repr(C)] { *const usize, *const usize, *const T }) |
Oh, we're not casting |
I should clarify that this T @Manishearth is talking about in the casting is the enum FooVoid {}
pub struct Foo(FooVoid); |
(I'm thinking of replacing |
Replace |
Right, that's the plan |
@Manishearth lol, I was just pointing that out :) The |
@ubsan That enum unfortunately is not zero sized, so |
@mystor ... eww. I'd rather do #[repr(C)]
struct Foo {
__: [i8; 0]
} in order to get rid of the chance of conversion to |
@ubsan Yup, that's actually almost exactly what I'm doing. And yes, I agree that it's a hack to get around |
Just stating the obvious : There are going to be many situations where the only unsafe code consists of calls to |
The |
BTW, even if invalid values are ignored, my aliasing memory models could end up with the result of an out-of-range |
I implement
|
@bluss I think this is a good case for |
Another crate:
|
bytecount (used by ripgrep&xi) has one line of unsafe to transmute aligned byte slices to usize/SIMD slices. This pattern might perhaps be factored out into its own crate, or perhaps even find a place in libstd. |
Can't byteorder do that? |
byteorder does not deal with slice conversions. I imagine that's something like split_aligned_for but even that formulation leaves much to be desired, slice iteratorish formulation seems to codegen much better (hence the other experiments there in the same junkyard and in rawslice). |
I'm not sure what this issue is supposed to achieve that downloading and grepping crates.io or searching for "unsafe" in Rust code on Github would not. But here are some bugs in unsafe code found in the wild, w/ short analysis. More of them here: https://rustsec.org/advisories/ Interesting or Rust-specific bugs:
Boring but serious bugs:
|
Discussed in backlog bonanza: Not so sure this issue is providing much value and the discussion here is quite old. Closing |
I think we should organize a kind of "canvas" to find examples of how unsafe code is used in the wild. To start, it'd be great to enumerate a list of interesting places to look.
Here is my start at a list. Further nominations welcome. I'll try to keep the list up to date. Moreover, if you feel you've examined the source, open any relate issues and we can check it off.
rayon
take_mut
abomonation
ndarray
intrusive_collections
by @Amanieu, cited in One glossary should be enough #19rental
Other thoughts for packages? Is this a fruitful thing to examine?
The text was updated successfully, but these errors were encountered: