Skip to content
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

only allow 0-offset on integer pointers #470

Merged
merged 3 commits into from
Oct 10, 2018

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Oct 8, 2018

Triggered by rust-lang/rust#54857

@RalfJung RalfJung requested a review from oli-obk October 10, 2018 08:03
@oli-obk
Copy link
Contributor

oli-obk commented Oct 10, 2018

Integer pointers to non-zsts are normal on embedded. This would make most embedded code UB

@RalfJung
Copy link
Member Author

That's platform-specific. On embedded, it might also be okay to do (0x400usize as *mut u32) = 14, and yet miri will always flag that as UB.

Currently we can only say whether your code is okay on all platforms (of the given target). We cannot test code that makes specific extra assumptions about e.g. allocations existing at fixed locations.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite agree, since offsetting integer pointers

  1. is something you can easily replicate by casting to an int, adding and casting back
  2. something that you can do without emulating the hardware (writing/reading to/from integer addresses needs such emulation)

That said, there's probably many things that go wrong when looking at embedded. I'll rather address this once I have a basic emulation setup and a bunch of tests

@RalfJung
Copy link
Member Author

is something you can easily replicate by casting to an int, adding and casting back

Supporting that is tracked in #224.

something that you can do without emulating the hardware (writing/reading to/from integer addresses needs such emulation)

We are not talking about hardware though, but about an abstract machine where whether an allocation exists somewhere makes a difference. In that abstract machine, the offset can not be emulated without further knowledge.

@RalfJung
Copy link
Member Author

That said, there's probably many things that go wrong when looking at embedded. I'll rather address this once I have a basic emulation setup and a bunch of tests

Wow, you have plans there?
But yes, an emulation setup that can fake the presence of non-ZST allocations at fixed addresses (including read/write accesses) should fix this properly.

@RalfJung RalfJung merged commit 15a0004 into rust-lang:master Oct 10, 2018
@RalfJung RalfJung deleted the ptr-offset branch October 12, 2018 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants