uefignu-efi

GNU-EFI: How to do callbacks properly (calling convention incompatibilities)?


I'm using GNU-EFI and calling UEFI functions works like a charm, thanks to the uefi_call_wrapper() macro, which ensures that differences in calling conventions won't be an issue.

But: What to do in the reverse case, when I want the system firmware to call my functions? This is relevant for example in case of callback functions (registered via BS->CreateEvent()).

Registering a callback function works fine, and it's executed successfully, but the parameters handed to such a callback function are garbage, e.g., the VOID * Context pointer that can be handed over. I couldn't find any documentation regarding this (or any GNU-EFI documentation in general whatsoever).

Is there a GNU-EFI macro, stub, or anything else for this case?


Solution

  • I didn't find any macro for this, but what you can do is define your callback functions with the correct (ms) calling convention.

    __attribute__((ms_abi)) EFI_STATUS callback(Void * Context) {...}