Should we keep 'EFI_KEY_DATA' argument after 'RegisterKeyNotify()' function call?


Konstantin Aladyshev
 

Hello!

According to the UEFI specification
`EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.RegisterKeyNotify()` function
registers a notification function for a particular keystroke for the
input device.

Its prototype is:
```
typedef
EFI_STATUS
(EFIAPI *EFI_REGISTER_KEYSTROKE_NOTIFY) (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_DATA *KeyData,
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
OUT VOID **NotifyHandle
);
```

I want to use this function in my driver. My question is about the
`KeyData` argument. Do I need to keep it in memory after a
`RegisterKeyNotify` function call? For example, use allocate services
for `KeyData` memory, or simply declare it as a global variable. Or we
can create `KeyData` as a local function variable on stack?

The `KeyData` argument is passed by reference and it is unclear to me
whether it should be kept in memory or not.

Best regards,
Konstantin Aladyshev


Andrew Fish
 

On Jul 13, 2021, at 10:13 AM, Konstantin Aladyshev <aladyshev22@gmail.com> wrote:

Hello!

According to the UEFI specification
`EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.RegisterKeyNotify()` function
registers a notification function for a particular keystroke for the
input device.

Its prototype is:
```
typedef
EFI_STATUS
(EFIAPI *EFI_REGISTER_KEYSTROKE_NOTIFY) (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_DATA *KeyData,
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
OUT VOID **NotifyHandle
);
```

I want to use this function in my driver. My question is about the
`KeyData` argument. Do I need to keep it in memory after a
`RegisterKeyNotify` function call? For example, use allocate services
for `KeyData` memory, or simply declare it as a global variable. Or we
can create `KeyData` as a local function variable on stack?

The `KeyData` argument is passed by reference and it is unclear to me
whether it should be kept in memory or not.
I’d say it needs to be valid until you EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.UnregisterKeyNotify() and unhook your function.

Thanks,

Andrew Fish

Best regards,
Konstantin Aladyshev