Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mem: introduce traits MemoryMap and MemoryMapMut#1234

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicholasbishop merged 7 commits intorust-osdev:mainfromphip1611:mem
Jul 15, 2024

Conversation

phip1611
Copy link
Member

@phip1611phip1611 commentedJul 8, 2024
edited
Loading

In#1175 we lost the flexibility to use the memory map on any buffer. However, if you write a kernel and get the raw memory map from your bootloader, one has to parse the memory map from this raw memory. To solve this (leveraging theuefi crate), I introduced:

  • the traitsMemoryMap andMemoryMapMut, whereMemoryMapMut extendsMemoryMap
  • the typesMemoryMapRef,MemoryMapRefMut, andMemoryMapOwned, where the latter two implementMemoryMapMut

This helps to have a common API for all these use-cases. However, there are the
following open questions:

  • There is still code repetition. Especially for the implementations ofIndex andIndexMut which I have to provide 3 times. Any idea for improvement? Just use a macro?
  • I didn't manage to make the traits directly dependent onIndex andIndexMut - I gave up after many compiler warnings.
  • What do you think about this in general?

Checklist

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

@phip1611phip1611force-pushed themem branch 3 times, most recently from4eb4b7f to1197782CompareJuly 8, 2024 12:54
@nicholasbishop
Copy link
Member

However, if you write a kernel and get the raw memory map from your bootloader, one has to parse the memory map from this raw memory.

Could the kernel take ownership of this memory and use the existingstruct MemoryMap instead of a reference type?

@phip1611
Copy link
MemberAuthor

phip1611 commentedJul 8, 2024
edited
Loading

Don't think so (from a library standpoint) . Most abstraction for boot loader information provide you only&[u8] access, including but not limited to Limine (w/ Limine boot protocol) and multiboot2

@nicholasbishop
Copy link
Member

Only&[u8], or&mut [u8] too? (Wondering aboutMemoryMapRefMut)

@phip1611
Copy link
MemberAuthor

phip1611 commentedJul 9, 2024
edited
Loading

Only&[u8], or&mut [u8] too? (Wondering aboutMemoryMapRefMut)

Yes, there were actually requests to be able to modify structures, such as the memory map. For example in themultiboot2 repository. Limine's boot protocol, or to be more specific, the limine crate, also provides you witha slice/a buffer - this is however not mutable yet - but it could be extended in the future.

Note that we need mutable access so that one can call the.sort() function.

I'm not sure if the proposed solution is 100% perfect - but it enables all use cases users will have - giving developers maximum freedom.

What do you think about this? What about the other questions mentioned above?

@nicholasbishop
Copy link
Member

Makes sense. I haven't looked through the details of the PR yet (doing so now), I just wanted to make sure I understood how it would be used at a high level first.

@nicholasbishop
Copy link
Member

I didn't manage to make the traits directly dependent on Index and IndexMut - I gave up after many compiler warnings.

This seems to work:

pubtraitMemoryMap:Debug +Index<usize,Output =MemoryDescriptor>{

(At least, it compiles, I didn't test it thoroughly.)

@nicholasbishop
Copy link
Member

There is still code repetition. Especially for the implementations of Index and IndexMut which I have to provide 3 times. Any idea for improvement? Just use a macro?

I think it's OK as-is, there is some code repetition but it's not too bad.

This provides API users all the flexibility they need. The main motivation forthe addition is that one can use a chunk of memory in a kernel (provided by abootloader) and parse it as EFI memory map. The main motivation for the specificimplementation (via traits) is code reduction.
@phip1611phip1611 mentioned this pull requestJul 14, 2024
3 tasks
@phip1611
Copy link
MemberAuthor

phip1611 commentedJul 14, 2024
edited
Loading

I didn't manage to make the traits directly dependent on Index and IndexMut - I gave up after many compiler warnings.

This seems to work:

pubtraitMemoryMap:Debug +Index<usize,Output =MemoryDescriptor>{

(At least, it compiles, I didn't test it thoroughly.)

I'll do/try this in a follow-up (#1240 ).

So,@nicholasbishop , what do you think? I know, I did a major overhaul of the MemoryType API in the past weeks. But I think it is worth it and that we now reached it a point where it is mature and sustainable. However, I'm also biased 😁 What do you think?

@nicholasbishop
Copy link
Member

I know, I did a major overhaul of the MemoryType API in the past weeks. But I think it is worth it and that we now reached it a point where it is mature and sustainable. However, I'm also biased 😁 What do you think?

I think it's a reasonable change, looks good to me. FWIW I don't think there's anything wrong with making more API changes after a recent API change if we realize that more improvements are needed. For me the important thing is that it's easy for users of the API to update their code when updating to a new version of uefi-rs. And certainly for these changes I don't think there's any problem there, it's very straightforward to changeMemoryMap toMemoryMapOwned, and then potentially use the other new traits as needed.

@nicholasbishopnicholasbishop added this pull request to themerge queueJul 15, 2024
Merged via the queue intorust-osdev:main with commit380f98fJul 15, 2024
12 checks passed
@phip1611phip1611 deleted the mem branchJuly 15, 2024 05:35
@phip1611phip1611 mentioned this pull requestDec 16, 2024
1 task
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicholasbishopnicholasbishopnicholasbishop approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@phip1611@nicholasbishop

[8]ページ先頭

©2009-2025 Movatter.jp