/* Add a new entry to the Event Log. */
EFI_STATUS TpmCommLogEvent(IN OUT UINT8 **EventLogPtr, IN OUT UINTN *LogSize, IN UINTN MaxSize, IN TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
/* Add a new entry to the Event Log. */
EFI_STATUS TpmCommLogEvent(IN OUT UINT8 **EventLogPtr, IN OUT UINTN *LogSize, IN UINTN MaxSize, IN TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
{
  UINTN  NewLogSize;
  if ((UINTN)NewEventHdr->EventSize > MAX_UINTN - sizeof (*NewEventHdr)) {
    return EFI_OUT_OF_RESOURCES;
  }
  NewLogSize = sizeof (*NewEventHdr) + NewEventHdr->EventSize;
  if (NewLogSize > MaxSize - *LogSize) {
    return EFI_OUT_OF_RESOURCES;
  }
  *EventLogPtr += *LogSize;
  *LogSize     += NewLogSize;
  CopyMem (*EventLogPtr, NewEventHdr, sizeof (*NewEventHdr));
  CopyMem (
    *EventLogPtr + sizeof (*NewEventHdr),
    NewEventData,
    NewEventHdr->EventSize
    );
  return EFI_SUCCESS;
}