[edk2-devel] Can NULL pointer be a valid event?

Michael D Kinney michael.d.kinney at intel.com
Mon Oct 3 17:54:37 UTC 2022


Hi Ayush,

Quick answer is that the UEFI Spec may not explicitly disallow NULLL, but in practice,
it will never return NULL.

===================================

EFI_EVENT is same as VOID*.

    typedef VOID *EFI_EVENT

CreateEvent() returns a pointer to an Event, so it is really a double pointer.
CreateEvent() returns EFI_INVALID_PARAMETER if Event (pointer to EFI_EVENT structure) is NULL.

But CreateEvent/Ex() do not explicitly state that the pointer to the EFI_EVENT structure
returned cannot be address 0.

Internally to the EDK II, EFI_EVENT is a structure so it must be a valid pointer.  Though I 
would point out that even this is an implementation choice.  An implementation could treat the
pointer to the EFI_EVENT as a handle number and could internally convert a handle number to a
structure pointer to further hide details of the event structure and prevent the reuse of the
same pointer value for different events across allocates/frees.  The EDK II implementation
choice to use pointers instead of handles is for the smallest/fastest implementation.

It is possible to have a pointer to a structure at address 0.  However, the EDK II implementations
of the UEFI services do not allow the use of memory at 0 for normal memory allocations.  I am aware
of one use case of memory at 0 for an x86 IDT structure for 16-bit code.  So it is not possible
for the EDK II implementation of an UEFI service that returns pointers to structures to return a
pointer value of 0.  In fact, there are guard page features in EDK II that check if there is any
access to the first page of memory in the address range 0x0..0xFFF.  So the real restriction EDK II
imposes is to never allocate a data structure in the first page of memory (0x0..0xFFF). 

Given it would be possible to implement many UEFI services using handle numbers instead of
pointers.  I would recommend those implementations do not use a handle value of 0. And instead
start at a handle value of at least 1.

Best regards,

Mike




> -----Original Message-----
> From: devel at edk2.groups.io <devel at edk2.groups.io> On Behalf Of Dionna Glaze via groups.io
> Sent: Monday, October 3, 2022 10:16 AM
> To: devel at edk2.groups.io; ayushdevel1325 at gmail.com
> Subject: Re: [edk2-devel] Can NULL pointer be a valid event?
> 
> CreateEvent returns an EFI_STATUS. It expects the OUT parameter, a
> pointer to an EFI_EVENT, to be non-NULL. A null pointer results in
> EFI_INVALID_PARAMETER. If the CreateEvent is successful, then `event`
> points to the newly created event. It's the caller's responsibility to
> pass a pointer to valid writable memory.
> 
> On Mon, Oct 3, 2022 at 8:08 AM Ayush Singh <ayushdevel1325 at gmail.com> wrote:
> >
> > Hello everyone,
> >
> > I wanted to ask if a NULL pointer can be returned as a valid event from `EFI_BOOT_SERVICES.CreateEvent()` or
> `EFI_BOOT_SERVICES.CreateEventEx()`? Or does the specification state that a valid event pointer has to be non-NULL?
> >
> > Yours Sincerely,
> > Ayush Singh
> >
> 
> 
> 
> --
> -Dionna Glaze, PhD (she/her)
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#94678): https://edk2.groups.io/g/devel/message/94678
Mute This Topic: https://groups.io/mt/94092613/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list