public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael Brown" <mcb30@ipxe.org>
To: devel@edk2.groups.io, ayushdevel1325@gmail.com,
	Michael Kubacki <mikuback@linux.microsoft.com>,
	michael.d.kinney@intel.com, jabeena.b.gaibusab@intel.com,
	Jiewen Yao <jiewen.yao@intel.com>
Subject: Re: [edk2-devel] Discussing how SystemTable and its Pointers should be treated in Rust
Date: Tue, 21 Jun 2022 08:28:19 +0100	[thread overview]
Message-ID: <89aade8b-5f79-54a6-9807-edafdc422cad@ipxe.org> (raw)
In-Reply-To: <CA+Yfj7tm8-1omF20eXznHG0b43vagw1VgyWAvpsTn4SZQKfZ-w@mail.gmail.com>

On 21/06/2022 07:04, Ayush Singh wrote:
> 1. Initialize the pointers needed for a module to work early on and
> keep them local to the module. This will mean that the allocator
> module will store the `allocate_pool` and `free_pool` pointers in a
> static private to the module which will be initialized by the std
> before the Rust main is run.
> 
> 2. Only have one global pointer to the SystemTable and pass that to
> the functions (like allocate and deallocate) when needed.
> 
> I am leaning more towards the first approach right now since it would
> mean that we will only need to assert that the local pointer is valid.
> However, the 1st approach is a NOGO if it is possible that the
> pointers in SysteTable can be changed by UEFI.
> 
> By change, I mean that for example the `allocate_pool` pointer in
> SystemTable is replaced with a different pointer midway through the
> program. In that case, the pointer in the allocator module will become
> invalid but the SystemTable will contain the pointer to the new
> location of `allocate_pool` and stay valid.

The UEFI shim will modify the LoadImage, StartImage, Exit, and 
ExitBootServices pointers in SystemTable->BootServices:

https://github.com/rhboot/shim/blob/main/replacements.c#L154-L183

In certain debug modes, iPXE will modify pointers within SystemTable in 
order to implement strace-like functionality for loaded EFI binaries:

https://github.com/ipxe/ipxe/blob/master/src/interface/efi/efi_wrap.c#L1243-L1265

so I would strongly suggest retaining only a pointer to SystemTable and 
dereferencing it at each point of use.

Thanks,

Michael

      reply	other threads:[~2022-06-21  7:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  6:04 Discussing how SystemTable and its Pointers should be treated in Rust Ayush Singh
2022-06-21  7:28 ` Michael Brown [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=89aade8b-5f79-54a6-9807-edafdc422cad@ipxe.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox