OpenDevicePartnership / OpenDevicePartnership/patina

[Feature]: config_tables: Use the zerocopy crate to Reduce Unsafe Code Blocks

Open
#893 6 comments 0 reactions 1 assignee View on GitHub

@VivekYadav7272 is already working on this.

Since Oct 29, 2025.

  • #1062 by @VivekYadav7272 — closed without merging
state:needs-maintainer-feedback state:needs-triage type:feature-request urgency:medium
Dominant language
Rust
Stars
544
Forks
54
Avg merge
1d 8h
Merged PRs (30d)
30

Description

Feature Overview

The zerocopy crate provides safe (wrapped unsafe) memory manipulations. This offers the ability to remove a lot of unsafe blocks in Patina and rely on zerocopy to convert to and from bytes, etc.

Solution Overview

Use zerocopy in config_tables module to remove unsafe usage (I'm assuming the ones that pertains to pointer-object casting?)

Alternatives Considered

No response

Urgency

Medium

Are you going to implement the feature request?

I will implement the feature

Do you need maintainer feedback?

Maintainer feedback requested

Anything else?

It'd be nice to get more clarification on exactly the kind of unsafe usage we want prevented. To be specific, for example:

In config_tables/memory_attributes_table.rs:

match core_allocate_pool(efi::BOOT_SERVICES_DATA, size_of::<efi::MemoryAttributesTable>()) {
            Ok(empty_ptr) => {
                if let Some(empty_mat) = unsafe { (empty_ptr as *mut efi::MemoryAttributesTable).as_mut() } {
...
  1. Now this sort of unsafe usage seems like a good candidate for using zerocopy. However, regardless, it will still require a cast to a byte slice, which would be an unsafe operation. That could probably also be eliminated if we have a Box-like allocation API -- is that something that's in-scope for this feature or should we let the unsafe needed to cast into a byte slice remain?
  2. Also, looks like zerocopy is primarily driven by derive macros and you can't provide custom implementations for those traits. But that means we have a recursive dependency for all children members to also have it implemented. In this case specifically, pub struct MemoryAttributesTable(*mut efi::MemoryAttributesTable); can't implement it until efi::MemoryAttributesTable does, which is an external dependency. Do I duplicate the struct? Is there some other way to implement these traits that I'm missing? Sorry if that's a stupid question.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.