Skip to content

Use u64, even on 32-bit to support reading elf-64 files. #34

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 1 commit into from
Dec 6, 2017
Merged

Use u64, even on 32-bit to support reading elf-64 files. #34

merged 1 commit into from
Dec 6, 2017

Conversation

ahmedcharles
Copy link
Contributor

@jmi2k @robert-w-gries

The current code mostly assumes that you're reading ELF headers which match the size of your platform, due to the use of usize. That means that the code is always memory safe but potentially truncating data. This proposes always returning u64 and promoting all u32 types to that, which means you always get all of the data.

What do you think?

@robert-w-gries
Copy link
Contributor

Do you have a use case in mind? I'm not sure when this support would be necessary.

@4e554c4c
Copy link

4e554c4c commented Dec 6, 2017

Looks good, not sure why the flags length has to be changed though.

@ahmedcharles
Copy link
Contributor Author

flags is u32 on x86 but u64 on x86_64.

And in the context of running this in a kernel when reading multiboot, I don't think you can ever have a mismatch. But I'd like to have more tests for reading x86 and x86_64 and if you test reading a 64 bit multiboot section on a 32 bit os, you might end up failing.

The other scenario is reading elf data for a 64 bit binary on a 32 bit system. Granted, this code isn't used in that scenario currently but it'd be nice to support it if the code ever allows for it.

The only downside is that 32 bit users of the code end up with 64 bit integers where the top 4 bytes are always 0.

fn addr(&self) -> usize {
self.addr as usize
fn addr(&self) -> u64 {
self.addr.into()// as u64
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Looks like a leftover comment from development

fn size(&self) -> usize {
self.size as usize
fn size(&self) -> u64 {
self.size.into()// as u64
Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover comment from development

@robert-w-gries
Copy link
Contributor

LGTM. I only had a couple minor nitpicks regarding unnecessary comments

@robert-w-gries robert-w-gries merged commit 00cf317 into rust-osdev:master Dec 6, 2017
@ahmedcharles ahmedcharles deleted the elf branch December 6, 2017 05:18
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.

3 participants