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

investigate Box::new_in issue with custom allocator #7

Closed
Tracked by #6
hannahfluch opened this issue Feb 7, 2025 · 6 comments
Closed
Tracked by #6

investigate Box::new_in issue with custom allocator #7

hannahfluch opened this issue Feb 7, 2025 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@hannahfluch
Copy link
Member

Creating a new box on the heap with a reference to the global allocator panics with the following error message:

unsafe precondition(s) violated: ptr::read requires that the pointer argument is aligned and non-null

_ = Box::new_in(0, &Global);

Passing the global allocator directly makes the allocation work smoothly:
_ = Box::new_in(0, Global);

The problem may be related to this or this issue. Although, they have seemingly been resolved.

Testing with this heap allocator does not solve the problem.

@hannahfluch hannahfluch added the bug Something isn't working label Feb 7, 2025
@hannahfluch hannahfluch mentioned this issue Feb 7, 2025
3 tasks
@hannahfluch
Copy link
Member Author

Using this heap allocator does not fix the problem either. The issue does not exist in a different no-std environment.

@hannahfluch
Copy link
Member Author

hannahfluch commented Feb 7, 2025

The panic occurs during the Box::assume_init() call. While calling Box::into_raw_with_allocator() .

@hannahfluch
Copy link
Member Author

hannahfluch commented Feb 7, 2025

minimal reproduction:

fn test_alloc<A: Allocator>(myalloc: A) -> A {
    unsafe { core::ptr::read(&myalloc) }
}

successful:

 _ = test_alloc(Global);

panic:

_ = test_alloc(&Global);

@hannahfluch hannahfluch pinned this issue Feb 7, 2025
@hannahfluch
Copy link
Member Author

The issue is a misaligned kernel stack.

@hannahfluch
Copy link
Member Author

This will be fixed as part of #5

@hannahfluch
Copy link
Member Author

d0de740 resolves this and will be merged into main.

@hannahfluch hannahfluch self-assigned this Feb 8, 2025
@hannahfluch hannahfluch unpinned this issue Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant