Can NULL pointer be a valid event?
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?
CreateEvent returns an EFI_STATUS. It expects the OUT parameter, atoggle quoted messageShow quoted text
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@...> wrote:
-Dionna Glaze, PhD (she/her)
Michael D Kinney
Hi Ayush,toggle quoted messageShow quoted text
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.