Skip to content

Safety requirement documentation of FrameBuffer::as_mut_ptr and GOP guarantees #1991

Description

@mbrla0

The current documentation for uefi::proto::console::gop::FrameBuffer::as_mut_ptr states:

To use this pointer safely and correctly, you must…
[...]

  • Make sure that the pointer does not outlive the FrameBuffer

On some implementations this framebuffer pointer can be used after exiting boot services, but that is not guaranteed by the UEFI Specification.

I believe the safety requirement may be misleading, and the point being made about the UEFI Specification is incorrect.

For the safety requirement, I believe the documentation does not make it clear whether "FrameBuffer" means the instance of the FrameBuffer struct the pointer was taken from, or the UEFI framebuffer itself. If the former interpretation is true, then the assertion that "On some implementations this framebuffer pointer can be used after exiting boot services" seems to imply a scenario in which one must keep the original GraphicsOutput structure alive even after having exited boot services in order for it to be safe to use the pointer, which seems to me to not make much sense, as far as UEFI goes.

And as for the lack of guarantees in the specification, while I realize that the spec is rather obtuse, it does seem to give a tacit guarantee that direct framebuffer access is allowed even after exiting boot services:

Graphics output is important in the pre-boot space to support modern firmware features. These features include the display of logos, the localization of output to any language, and setup and configuration screens.

Graphics output may also be required as part of the startup of an operating system. There are potentially times in modern operating systems prior to the loading of a high performance OS graphics driver where access to graphics output device is required. The Graphics Output Protocol supports this capability by providing the EFI OS loader access to a hardware frame buffer and enough information to allow the OS to draw directly to the graphics output device.

Note how the specification explicitly paints the protocol as being useful to providing graphics output to an operating system before high-performance graphics are loaded, and how it distinguishes the "EFI OS loader" from the operating system itself in the rest of the paragraph.

Additionally, Linux's efifb driver directly writes to the physical framebuffer address acquired in the stub loader through GOP by taking the value of frame_buffer_base, which is also the value that is ultimately returned by as_mut_ptr. While this doesn't means it's a de jure gurantee, the fact that Linux seems confident enough to do this seems to indicate that it is a de facto guarantee, at the very least.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions