Skip to content

Conversation

iankronquist
Copy link
Contributor

In boot.rs we see there is an unsafe function named memset. This function has a signature different than memset(3), but has a name different than that in the edk2 sources. This is confusing and will lead to bugs in a very unsafe function when people mix up the order of the value and the size.

We should name the function set_mem and give it the signature from EFI_SET_MEM.

uefi-rs/src/table/boot.rs

Line 529 in 948464c

 pub unsafe fn memset(&self, buffer: *mut u8, size: usize, value: u8) { 

See #232

In boot.rs we see there is an unsafe function named memset. This function has a signature different than memset(3), but has a name different than that in the edk2 sources. This is confusing and will lead to bugs in a very unsafe function when people mix up the order of the value and the size.

We should either name the function memset and give it the libc-style signature memset(&self, buffer: *mut u8, value: u8, size: usize), or name the function set_mem and give it the signature from EFI_SET_MEM.

uefi-rs/src/table/boot.rs

Line 529 in 948464c

 pub unsafe fn memset(&self, buffer: *mut u8, size: usize, value: u8) { 

See rust-osdev#232
@iankronquist
Copy link
Contributor Author

Note that I made this PR entirely through the web UI to see how useful that workflow is, and have not run the tests locally. I am relying on travis CI to catch bugs.

@iankronquist
Copy link
Contributor Author

iankronquist commented Jun 6, 2021

Also, I have elected to rename the function set_mem. It's possible to hardcode two integers in both the value and size arguments of the old memset which would be wrong but still valid. I.e.

memset(ptr, size: 1, val: 2) -> memset(ptr, val: 1, size: 2) 

If we rename the function this silent breakage can't happen.

@GabrielMajeri
Copy link
Collaborator

@iankronquist I think some tests failed since they have to be updated to the function's new API.

@iankronquist
Copy link
Contributor Author

I think I fixed it but Travis doesn't seem to be checking in with GitHub. This new GitHub checks feature seems more brittle than it was a few years ago?

@GabrielMajeri
Copy link
Collaborator

I think I fixed it but Travis doesn't seem to be checking in with GitHub.

Yeah, it's a minor security change GitHub made 😅 the CI doesn't run automatically for first time contributors of a project, I have to manually approve running the flows after you make some changes.

@GabrielMajeri GabrielMajeri changed the title Rename boot services' memset to set_mem Rename boot services' memset to set_mem Jun 7, 2021
@GabrielMajeri GabrielMajeri merged commit 1c7752f into rust-osdev:master Jun 7, 2021
@GabrielMajeri
Copy link
Collaborator

Thanks for contributing. I've pulled the latest changes from master and merged the PR.

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