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

Decouple instructions into a separate feature flag. #179

Merged
merged 9 commits into from
Sep 23, 2020

Conversation

h33p
Copy link
Contributor

@h33p h33p commented Sep 12, 2020

This would implement what was proposed in #177.

There is one issue, however - array_init dependency. The crate currently does not compile with no features on. From what I could tell, the dep is only used in PageTable::new, and it very well could be dropped, by replacing PageTable::new with an identical implementation as the const variant, just kept as non-const. However, I did not implement this change, as I didn't know if there was something else at play that needed the function to be the way it is. If this change would be fine, I can go ahead and add it in this PR.

Other than that, if there are any other changes that may need to be implemented, please let me know!

Edit(phil-opp): This is a breaking change.

@h33p
Copy link
Contributor Author

h33p commented Sep 12, 2020

I'm also not sure why the workflows failed

Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

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

Thanks a lot! Looks good to me overall, except for a few minor things (see my inline comments).

The CI failures happened because yesterday's Rust nightly was broken. I just restarted the checks and it seems like it's now working again. There is still a small CI error because one check tries to enable the stable feature, which no longer exists. To fix this, you need to update the check command in .github/workflows/build.yml.

README.md Outdated Show resolved Hide resolved
build.rs Outdated Show resolved Hide resolved
src/instructions/mod.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@phil-opp
Copy link
Member

Regarding the const-ness of PageTable::new() on stable: I think we can make the function non-const for now and drop the array-init dependency. This is going to be a breaking change anyway because of the new feature gate names, so I think that's ok for now.

@h33p
Copy link
Contributor Author

h33p commented Sep 14, 2020

Final nail in the coffin is the addr module, which is dependent on by the OffsetPageTable. Lots of functions are marked for only 64-bit pointer width, and that is very fair - lots of silent trunction errors can lead to the oddest of behaviours.

I am wondering, however, if it wouldn't make sense to allow to work with 64-bit addresses on 32-bit machines? At the last as_ptr step it would be possible to inject a truncation debug assertion, given this brings enough breaking changes as it stands, and if I'm not mistaken adding extra functionality wouldn't be a bad thing.

From what I can tell there are 2 options to go about the issue - either mark OffsetPageTable as a structure that depends on 64-bit pointer width, or making the addresses function on non-64-bit architectures. Of course, there can be a third solution, but I don't see it right now. Please tell me what you think about it. And how should I proceed?

src/structures/paging/page_table.rs Outdated Show resolved Hide resolved
build.rs Show resolved Hide resolved
@phil-opp
Copy link
Member

I am wondering, however, if it wouldn't make sense to allow to work with 64-bit addresses on 32-bit machines? At the last as_ptr step it would be possible to inject a truncation debug assertion, given this brings enough breaking changes as it stands, and if I'm not mistaken adding extra functionality wouldn't be a bad thing.

I don't think that that panicking at runtime is a good idea. People can use the as_u64 method and a manual cast if they want this behavior, but it should not be the default.

From what I can tell there are 2 options to go about the issue - either mark OffsetPageTable as a structure that depends on 64-bit pointer width, or making the addresses function on non-64-bit architectures.

The OffsetPageTable type is already only available on x86_64 in the current implementation:

#![cfg(target_arch = "x86_64")]

So I think this is the way to go. OffsetPageTable is just a thin wrapper around MappedPageTable, which is available on all architectures. Users on non-x86_64 architectures can use MappedPageTable directly with a custom PhysToVirt implementation.

@h33p
Copy link
Contributor Author

h33p commented Sep 15, 2020

Alright, I added a pointer width check. The macos testing seems to have failed due to lld missing (I think we had similar issue a few days back on our CI as well), but overall the code seems to be somewhat ready from my end. If there are any additional changes needed, please let me know!

@phil-opp
Copy link
Member

Thanks a lot, looks very good! I left two more inline comments above, maybe you could look into them? Otherwise I think this should be ready for merging.

The rust-lld failure is caused by rust-lang/rust#76698, I hope that it gets fixed soon.

@h33p
Copy link
Contributor Author

h33p commented Sep 15, 2020

Alright, I added in the requested PageTable change, and clarified the decision made in the build script. I hope it is all fine!

@phil-opp
Copy link
Member

Looks good to me, thanks!

I'll probably wait until the macOS nightly is fixed until merging, to ensure that everything works there as well. I hope that this will happen in the next few days.

@phil-opp phil-opp merged commit 7ea8c94 into rust-osdev:master Sep 23, 2020
phil-opp added a commit that referenced this pull request Sep 23, 2020
@phil-opp
Copy link
Member

Published as v0.12.0.

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