/* Create thunks for an EBC image entry point, or an EBC protocol service. */
EFI_STATUS EbcCreateThunks(IN EFI_HANDLE ImageHandle, IN VOID *EbcEntryPoint, OUT VOID **Thunk, IN UINT32 Flags)
/* Create thunks for an EBC image entry point, or an EBC protocol service. */
EFI_STATUS EbcCreateThunks(IN EFI_HANDLE ImageHandle, IN VOID *EbcEntryPoint, OUT VOID **Thunk, IN UINT32 Flags)
{
  EBC_INSTRUCTION_BUFFER  *InstructionBuffer;
  if ((UINT32)(UINTN)EbcEntryPoint & 0x01) {
    return EFI_INVALID_PARAMETER;
  }
  InstructionBuffer = EbcAllocatePoolForThunk (sizeof (EBC_INSTRUCTION_BUFFER));
  if (InstructionBuffer == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
  *Thunk = InstructionBuffer;
  CopyMem (
    InstructionBuffer,
    &mEbcInstructionBufferTemplate,
    sizeof (EBC_INSTRUCTION_BUFFER)
    );
  InstructionBuffer->EbcEntryPoint = (UINT64)EbcEntryPoint;
  if ((Flags & FLAG_THUNK_ENTRY_POINT) != 0) {
    InstructionBuffer->EbcLlEntryPoint = (UINT64)EbcLLExecuteEbcImageEntryPoint;
  } else {
    InstructionBuffer->EbcLlEntryPoint = (UINT64)EbcLLEbcInterpret;
  }
  EbcAddImageThunk (
    ImageHandle,
    InstructionBuffer,
    sizeof (EBC_INSTRUCTION_BUFFER)
    );
  return EFI_SUCCESS;
}