Skip to content

Returning FrameAlreadyMapped error when it shouldn't #461

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

Closed
Sxmourai opened this issue Feb 27, 2024 · 10 comments
Closed

Returning FrameAlreadyMapped error when it shouldn't #461

Sxmourai opened this issue Feb 27, 2024 · 10 comments

Comments

@Sxmourai
Copy link
Contributor

The MapToError::FrameAlreadyMapped is returned when we try to map a frame that is already mapped.
From the offset_page_table -> Size4Kib code:

if !p1[page.p1_index()].is_unused() {
      return Err(MapToError::PageAlreadyMapped(frame));
}

We get this error when we try to change the page flags, which isn't right, we should only return this error if the frame address's are different.
Something like:

if !p1[page.p1_index()].is_unused() && p1[page.p1_index()].addr() != frame.start_address() {
     return Err(MapToError::PageAlreadyMapped(frame));
}

Also why do we return the user inputted frame and not the previously mapped frame ?

@Freax13
Copy link
Member

Freax13 commented Feb 27, 2024

We get this error when we try to change the page flags, which isn't right, we should only return this error if the frame address's are different.

Is there a reason why you aren't using Mapper::update_flags if you only want to change the flags and not the frame?

Also why do we return the user inputted frame and not the previously mapped frame ?

See #117 and #118.

@Sxmourai
Copy link
Contributor Author

Sorry, I didn't see this function !
But maybe we should use the update_flags implicitly ?

@Freax13
Copy link
Member

Freax13 commented Feb 27, 2024

I think there are some users of the mapping function that expect it to return an error if the entry is already present even if that entry contains the same frame. Changing this behavior would be a breaking change and a subtle one.

@Sxmourai
Copy link
Contributor Author

Yes I'm okay, but also why do we have Mapper::update_flags but not Mapper::get_flags, I think it would be a cool addition

@Freax13
Copy link
Member

Freax13 commented Feb 28, 2024

Yes I'm okay, but also why do we have Mapper::update_flags but not Mapper::get_flags, I think it would be a cool addition

That sounds reasonable to me. Feel free to open a PR :)

@phil-opp
Copy link
Member

phil-opp commented Mar 4, 2024

Yes I'm okay, but also why do we have Mapper::update_flags but not Mapper::get_flags, I think it would be a cool addition

The Mapper trait is about updating the page tables, i.e. creating or changing some mappings. We have a separate trait called Translate for inspecting the page tables without modification. For example, you can use the Translate::translate to get all the information about a virtual page, including its flags.

@Sxmourai
Copy link
Contributor Author

Sxmourai commented Mar 7, 2024

Okay thanks !
Well I guess my issue is useless... So I can close it...
Although I think it's not really straight forward...

@Sxmourai Sxmourai closed this as completed Mar 7, 2024
@phil-opp
Copy link
Member

phil-opp commented Mar 7, 2024

Although I think it's not really straight forward...

Do you think it's mainly a documentation issue or do you see a way how we could make the API itself simpler?

@Sxmourai
Copy link
Contributor Author

Sxmourai commented Mar 7, 2024

The API should change, because I think the update_flags and get_flags should be on the same object
But we can also just add in comments for the update_flags function:
/// See Translate::get_flags to get the flags on a specific page/frame

@phil-opp
Copy link
Member

phil-opp commented Mar 7, 2024

You can check the docs for a specific page table type to see all supported methods, e.g. https://docs.rs/x86_64/latest/x86_64/structures/paging/mapper/struct.OffsetPageTable.html. Keeping the traits separate allows creating custom read-only or write-only page table types.

But we can also just add in comments for the update_flags function:
/// See Translate::get_flags to get the flags on a specific page/frame

I agree that such a comment would be useful. Could you submit a 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

No branches or pull requests

3 participants