10

Github Miri: make size/align_of_val work for dangling raw ptrs by RalfJung · Pul...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/80491
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Miri: make size/align_of_val work for dangling raw ptrs #80491

Conversation

Member

RalfJung commented 17 days ago

Contributor

oli-obk commented 17 days ago

Is this testable within this repo or do we need miri for it?

r=me with a test if possible

Member

Author

RalfJung commented 17 days ago

Good point, I added a test.

@bors r=oli-obk

Contributor

bors commented 17 days ago

pushpin Commit f76bae9 has been approved by oli-obk

Is that a guarantee that we will want to make going forward?

I tried to create a *const dyn Debug from a *const DynamicallySized<[usize]> and failed (see playground) as apparently it's not possible to create a pointer to trait from a pointer to DST right now.

It's unclear whether this is a restriction that will stay, or not. If it doesn't, however, then size_of_val_raw may, on certain types, require accessing the data-pointer of the trait.

As such, it seems that if we wish to keep our options open regarding the conversion from DST to trait, then we should enforce that size_of_val_raw require a valid data-pointer.

Member

Author

RalfJung commented 8 days ago

Is that a guarantee that we will want to make going forward?

The guarantee is what is documented for align_of_val_raw_/size_of_val_raw. In particular, for sized types, the pointers may dangle. So what Miri did previously was definitely wrong.

I think Miri also implements the rest of those docs correctly, but if there's a bug, please let me know. Note the last clause in the documentation:

otherwise, it is conservatively not allowed to call this function.

Currently, this is impossible to reach (there are no other kinds of DST), but that is not a stable assumptions -- so if one has no clue what the unsized tail is, one has to use size_of_val still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

No reviews

Assignees

oli-obk

Projects

None yet

Milestone

1.51.0

Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK