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

Box retags on drop causing Miri to report problem in custom allocator #402

Closed
zakarumych opened this issue May 22, 2023 · 3 comments
Closed

Comments

@zakarumych
Copy link

zakarumych commented May 22, 2023

I'm implementing custom allocator that stores allocation metadata in first bytes few of the allocated block and offsets pointer before returning it from Allocator::allocate.
It goes in reverse in Allocator::deallocate and reads metadata from before the passed pointer.

It works until I try to use Box::new_in or similar.
When Box is dropped, pointer passed to A::deallocate has different tag than one that returned from A::allocate.
And Miri emits error saying that tag does not encompass first bytes of the block and I can't read them.

Here's playground link

Same error happens if pointer from Allocator::allocate is converted to reference and then back to pointer.
That's, I guess, can be expected. But Box should not retag pointer on drop as I understand it.
Or this is something strictly prohibited by Rust.

@RalfJung
Copy link
Member

RalfJung commented May 22, 2023 via email

@zakarumych
Copy link
Author

Yes, that's the same issue.
With -Zmiri-tree-borrows Miri is happy.

@RalfJung
Copy link
Member

Thanks for checking! Closing as a duplicate then.

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

No branches or pull requests

2 participants