/* Returns the stack index and buffer assosicated with the Handle parameter. */
EFI_STATUS GetEBCStack(IN EFI_HANDLE Handle, OUT VOID **StackBuffer, OUT UINTN *BufferIndex)
/* Returns the stack index and buffer assosicated with the Handle parameter. */
EFI_STATUS GetEBCStack(IN EFI_HANDLE Handle, OUT VOID **StackBuffer, OUT UINTN *BufferIndex)
{
  UINTN    Index;
  EFI_TPL  OldTpl;
  OldTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
  for (Index = 0; Index < mStackNum; Index++) {
    if (mStackBufferIndex[Index] == NULL) {
      mStackBufferIndex[Index] = Handle;
      break;
    }
  }
  gBS->RestoreTPL (OldTpl);
  if (Index == mStackNum) {
    return EFI_OUT_OF_RESOURCES;
  }
  *BufferIndex = Index;
  *StackBuffer = mStackBuffer[Index];
  return EFI_SUCCESS;
}