Skip to content

Align up the Hole initialization address #18

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

Merged
merged 2 commits into from
Jan 14, 2020

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Jan 13, 2020

ptr::write requires the address to be properly aligned. This PR makes sure that this is the case.

@tomaka tomaka mentioned this pull request Jan 13, 2020
@phil-opp
Copy link
Member

Thanks a lot for the pull request!

Just to ensure that I understand everything correctly: As far as I know, the HoleList::new function is only called once with the heap bounds when the allocator is initialized. So this issue should only occur when heap_bottom is not properly aligned. I just had a short look at your kernel to find out why heap_bottom could be misaligned in your case. I think the reason is that you're directly using the free address ranges reported by multiboot in combination with identity mapping. Is that right?

Assuming my understanding is correct, this seems like a use case where rounding up the address and leaving the first few bytes of the heap unused is indeed the best solution.

Could you add a short sentence about this to the documentation of HoleList::new? We should specify that the caller does not need to ensure any alignment of hole_addr since the function performs the required alignment itself. Otherwise the changes look good to me!

@tomaka
Copy link
Contributor Author

tomaka commented Jan 14, 2020

I think the reason is that you're directly using the free address ranges reported by multiboot in combination with identity mapping. Is that right?

Indeed!

Could you add a short sentence about this to the documentation of HoleList::new? We should specify that the caller does not need to ensure any alignment of hole_addr since the function performs the required alignment itself. Otherwise the changes look good to me!

I added a small line. I must admit that I don't really know what to say in the comment.

@phil-opp
Copy link
Member

Thanks! The comment is fine. To me, hole_addr sounds like something that needs to be capable of storing a Hole, including correct alignment. The function, however, now performs the alignment itself, so this isn't required anymore. I think it's worth documenting such facts to ensure that no confusion occurs.

@phil-opp phil-opp merged commit c9c7f45 into rust-osdev:master Jan 14, 2020
phil-opp added a commit that referenced this pull request Jan 14, 2020
@phil-opp
Copy link
Member

Published as version 0.6.5

@tomaka tomaka deleted the align-up-hole-init branch January 14, 2020 11:02
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.

2 participants