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

Implement additional BootServices functions #550

Merged
merged 4 commits into from
Nov 12, 2022
Merged

Implement additional BootServices functions #550

merged 4 commits into from
Nov 12, 2022

Conversation

timrobertsdev
Copy link
Contributor

@timrobertsdev timrobertsdev commented Nov 6, 2022

This PR implements basic protocol handler services such as (re/un)install_protocol_services and allows a user to be notified when a protocol is installed through the implementation of register_protocol_notify. To support the implementation of register_protocol_notify, a variant was added to SearchType and any functions using it updated. A new type SearchKey was added to abstract over the void pointer given by register_protocol_notify.

There was one enum added to support install_protocol_services that currently has only one variant, 'InterfaceType'. I have chosen to make this enum public to be forwards-compatible, but in the implementation of install_protocol_services I don't include an interface_type parameter yet as InterfaceType and simply pass the only variant. I'm not quite sure if this "middle of the road" solution is ideal and am looking for feedback.

Tests will be coming soon.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@phip1611
Copy link
Contributor

phip1611 commented Nov 7, 2022

Hi @timrobertsdev,
regarding the checklist, because I already saw this in your last PR:

the markup regarding the checkboxes is intended to be used like this:

- [X] like this
- [ X ] and not like this

as this way, checkboxes will be rendered properly, as here

  • check

Copy link
Contributor

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

LGTM. What do @GabrielMajeri and @nicholasbishop think?

@GabrielMajeri
Copy link
Collaborator

The code looks very good, just waiting for some tests to be added and it's good to go.

@timrobertsdev
Copy link
Contributor Author

timrobertsdev commented Nov 7, 2022

@phip1611 Thanks for the heads up, I wasn't aware of the markup formatting.

Tests are in now. Some changes to install_protocol_interface had to be made as well.

src/data_types/mod.rs Outdated Show resolved Hide resolved
src/data_types/mod.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
src/data_types/mod.rs Outdated Show resolved Hide resolved
src/table/boot.rs Outdated Show resolved Hide resolved
src/table/boot.rs Outdated Show resolved Hide resolved
@nicholasbishop
Copy link
Contributor

Please rebase on latest main as well to fix the conflict in the changelog.

@timrobertsdev
Copy link
Contributor Author

I thought that what I just did would rebase onto main and then put my commits over it but I guess I didn't do that quite right. @nicholasbishop would you be able to help out my failing git-fu?

@nicholasbishop
Copy link
Contributor

I think maybe you rebased but your main branch wasn't up to date? Steps to rebase should be something like this:

# Update your local main branch
git checkout main
git pull

# Rebase your branch on main and push
git checkout your-branch
git rebase main
git push -f

Or, equivalently but without updating the local main branch:

git checkout your-branch
git fetch origin  # Assuming "origin" is the name of the rust-osdev/uefi-rs remote
git rebase origin/main  # Where origin is again the remote name
git push -f

@timrobertsdev
Copy link
Contributor Author

timrobertsdev commented Nov 12, 2022

That was it, I had sync'd my fork in github but forgot to actually update my local main. Thanks!

Edit: About to do it again because I didn't notice the last merge to main.

- Implement `BootServices::install_protocol_interface`
- Implement `BootServices::uninstall_protocol_interface`
- Implement `BootServices::reinstall_protocol_interface`
- Implement `BootServices::register_protocol_notify`
- Add `SearchType::ByRegisterNotify` variant.
- Add `SearchType::from_search_key`
- Add `SearchKey` type that abstracts over an opaque pointer given by `BootServices::register_protocol_notify`.
@@ -1,6 +1,7 @@
#![no_std]
#![no_main]
#![feature(abi_efiapi)]
#![feature(negative_impls)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see why this is required. Can you please give some details?

Copy link
Contributor Author

@timrobertsdev timrobertsdev Nov 12, 2022

Choose a reason for hiding this comment

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

Yes, rustc said it was required when I was implementing my dummy protocol with #[derive(Protocol].

Specifically in uefi-test-runner/src/boot/misc.rs:

/// Dummy protocol for tests
#[unsafe_guid("1a972918-3f69-4b5d-8cb4-cece2309c7f5")]
#[derive(Protocol)]
struct TestProtocol {}

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, thanks for the pointer. What does @nicholasbishop say? Is this fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine, just a consequence of the way we implement protocols.

(There's a little bit of commentary on negative_impl in #452; it might be something we want to drop in the future. But for this PR it's fine.)

@@ -112,7 +112,7 @@ fn test_install_protocol_interface(bt: &BootServices) {
.expect("Failed to install protocol interface")
};

let exists = bt
let _ = bt
Copy link
Contributor

@phip1611 phip1611 Nov 12, 2022

Choose a reason for hiding this comment

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

nit: These changes could be squashed with the commit(s) where the changes were introduced.

However, this is not a hard requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to learn git a bit better anyway, so I'll see what I can do about cleaning up the history a bit today.

Copy link
Contributor

@phip1611 phip1611 Nov 12, 2022

Choose a reason for hiding this comment

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

👍 Moving things between existing git commits is kinda hard without experience. In the last months, I've spent some time on improving my skills. The following workflow worked for me. Maybe it helps you as well, hopefully:

  1. git rebase --interactive HEAD~4 (for four commits)
  2. in the editor, mark all commits you want to change with e/edit
  3. run cargo fmt && cargo clippy plus git add all changes
  4. run git rebase --continue
  5. While commits are left, goto 3.

Ideally, git should discard the "code style only commit" if you can pull these changes into earlier commits this way. Let me know what worked for you! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That actually was a really easy way to understand how to split commits apart, thanks! I had no idea that git would detect and let you remove empty commits.

@phip1611
Copy link
Contributor

Thanks for the contribution. I'd wait with the merge until @nicholasbishop addressed the comment above.

Adjust changelog
Rename `SearchKey` to `ProtocolSearchKey` and move to `boot.rs`.
Fixup doclinks.
Adjust signatures of the `[re/un]install_protocol_interface` functions
Copy link
Contributor

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

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

Lgtm, thanks :)

@nicholasbishop nicholasbishop merged commit 8f74777 into rust-osdev:main Nov 12, 2022
@timrobertsdev timrobertsdev deleted the protocol-handler-services branch November 13, 2022 03:45
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.

4 participants