2018-08-23 07:02:52 +02:00
|
|
|
/**@file
|
|
|
|
|
|
|
|
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:03:44 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2018-08-23 07:02:52 +02:00
|
|
|
|
|
|
|
Module Name:
|
|
|
|
|
|
|
|
WinNtThunk.c
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
Since the SEC is the only windows program in our emulation we
|
|
|
|
must use a Tiano mechanism to export Win32 APIs to other modules.
|
|
|
|
This is the role of the EFI_WIN_NT_THUNK_PROTOCOL.
|
|
|
|
|
|
|
|
The mWinNtThunkTable exists so that a change to EFI_WIN_NT_THUNK_PROTOCOL
|
|
|
|
will cause an error in initializing the array if all the member functions
|
|
|
|
are not added. It looks like adding a element to end and not initializing
|
|
|
|
it may cause the table to be initaliized with the members at the end being
|
|
|
|
set to zero. This is bad as jumping to zero will case the NT32 to crash.
|
|
|
|
|
|
|
|
All the member functions in mWinNtThunkTable are Win32
|
|
|
|
API calls, so please reference Microsoft documentation.
|
|
|
|
|
|
|
|
|
|
|
|
gWinNt is a a public exported global that contains the initialized
|
|
|
|
data.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "WinHost.h"
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
SecWriteStdErr (
|
2021-12-05 23:53:57 +01:00
|
|
|
IN UINT8 *Buffer,
|
|
|
|
IN UINTN NumberOfBytes
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
BOOL Success;
|
|
|
|
DWORD CharCount;
|
2018-08-23 07:13:21 +02:00
|
|
|
|
|
|
|
CharCount = (DWORD)NumberOfBytes;
|
2021-12-05 23:53:57 +01:00
|
|
|
Success = WriteFile (
|
|
|
|
GetStdHandle (STD_ERROR_HANDLE),
|
|
|
|
Buffer,
|
|
|
|
CharCount,
|
|
|
|
&CharCount,
|
|
|
|
NULL
|
|
|
|
);
|
2018-08-23 07:13:21 +02:00
|
|
|
|
|
|
|
return Success ? CharCount : 0;
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
SecConfigStdIn (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
BOOL Success;
|
|
|
|
DWORD Mode;
|
2018-08-23 07:13:21 +02:00
|
|
|
|
|
|
|
Success = GetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), &Mode);
|
|
|
|
if (Success) {
|
|
|
|
//
|
|
|
|
// Disable buffer (line input), echo, mouse, window
|
|
|
|
//
|
2018-08-31 10:55:36 +02:00
|
|
|
Mode &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
|
|
|
|
|
2021-12-05 23:53:57 +01:00
|
|
|
#if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION > NTDDI_WIN10_TH2)
|
2018-08-23 07:13:21 +02:00
|
|
|
//
|
2018-08-31 10:55:36 +02:00
|
|
|
// Enable virtual terminal input for Win10 above TH2
|
2018-08-23 07:13:21 +02:00
|
|
|
//
|
2018-08-31 10:55:36 +02:00
|
|
|
Mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
2021-12-05 23:53:57 +01:00
|
|
|
#endif
|
2018-08-31 10:55:36 +02:00
|
|
|
|
|
|
|
Success = SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), Mode);
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:53:57 +01:00
|
|
|
#if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION > NTDDI_WIN10_TH2)
|
2018-08-31 10:55:36 +02:00
|
|
|
//
|
|
|
|
// Enable terminal mode for Win10 above TH2
|
|
|
|
//
|
|
|
|
if (Success) {
|
2018-08-23 07:13:21 +02:00
|
|
|
Success = GetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), &Mode);
|
|
|
|
if (Success) {
|
|
|
|
Success = SetConsoleMode (
|
2021-12-05 23:53:57 +01:00
|
|
|
GetStdHandle (STD_OUTPUT_HANDLE),
|
|
|
|
Mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN
|
|
|
|
);
|
2018-08-23 07:13:21 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 23:53:57 +01:00
|
|
|
|
|
|
|
#endif
|
2018-08-23 07:13:21 +02:00
|
|
|
return Success ? EFI_SUCCESS : EFI_DEVICE_ERROR;
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
SecWriteStdOut (
|
2021-12-05 23:53:57 +01:00
|
|
|
IN UINT8 *Buffer,
|
|
|
|
IN UINTN NumberOfBytes
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
BOOL Success;
|
|
|
|
DWORD CharCount;
|
2018-08-23 07:13:21 +02:00
|
|
|
|
|
|
|
CharCount = (DWORD)NumberOfBytes;
|
2021-12-05 23:53:57 +01:00
|
|
|
Success = WriteFile (
|
|
|
|
GetStdHandle (STD_OUTPUT_HANDLE),
|
|
|
|
Buffer,
|
|
|
|
CharCount,
|
|
|
|
&CharCount,
|
|
|
|
NULL
|
|
|
|
);
|
2018-08-23 07:13:21 +02:00
|
|
|
|
|
|
|
return Success ? CharCount : 0;
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
SecPollStdIn (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
BOOL Success;
|
|
|
|
INPUT_RECORD Record;
|
|
|
|
DWORD RecordNum;
|
2018-08-23 07:13:21 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
Success = GetNumberOfConsoleInputEvents (GetStdHandle (STD_INPUT_HANDLE), &RecordNum);
|
|
|
|
if (!Success || (RecordNum == 0)) {
|
|
|
|
break;
|
|
|
|
}
|
2021-12-05 23:53:57 +01:00
|
|
|
|
2018-08-23 07:13:21 +02:00
|
|
|
Success = PeekConsoleInput (
|
2021-12-05 23:53:57 +01:00
|
|
|
GetStdHandle (STD_INPUT_HANDLE),
|
|
|
|
&Record,
|
|
|
|
1,
|
|
|
|
&RecordNum
|
|
|
|
);
|
2018-08-23 07:13:21 +02:00
|
|
|
if (Success && (RecordNum == 1)) {
|
2021-12-05 23:53:57 +01:00
|
|
|
if ((Record.EventType == KEY_EVENT) && Record.Event.KeyEvent.bKeyDown) {
|
2018-08-23 07:13:21 +02:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Consume the non-key event.
|
|
|
|
//
|
|
|
|
Success = ReadConsoleInput (
|
2021-12-05 23:53:57 +01:00
|
|
|
GetStdHandle (STD_INPUT_HANDLE),
|
|
|
|
&Record,
|
|
|
|
1,
|
|
|
|
&RecordNum
|
|
|
|
);
|
2018-08-23 07:13:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (Success);
|
|
|
|
|
2018-08-23 07:02:52 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
SecReadStdIn (
|
2021-12-05 23:53:57 +01:00
|
|
|
IN UINT8 *Buffer,
|
|
|
|
IN UINTN NumberOfBytes
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
BOOL Success;
|
|
|
|
INPUT_RECORD Record;
|
|
|
|
DWORD RecordNum;
|
|
|
|
UINTN BytesReturn;
|
2018-08-23 07:13:21 +02:00
|
|
|
|
|
|
|
if (!SecPollStdIn ()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-12-05 23:53:57 +01:00
|
|
|
|
2018-08-23 07:13:21 +02:00
|
|
|
Success = ReadConsoleInput (
|
2021-12-05 23:53:57 +01:00
|
|
|
GetStdHandle (STD_INPUT_HANDLE),
|
|
|
|
&Record,
|
|
|
|
1,
|
|
|
|
&RecordNum
|
|
|
|
);
|
2018-08-23 07:13:21 +02:00
|
|
|
ASSERT (Success && (RecordNum == 1) && (Record.EventType == KEY_EVENT) && (Record.Event.KeyEvent.bKeyDown));
|
|
|
|
NumberOfBytes = MIN (Record.Event.KeyEvent.wRepeatCount, NumberOfBytes);
|
|
|
|
BytesReturn = NumberOfBytes;
|
|
|
|
while (NumberOfBytes-- != 0) {
|
|
|
|
Buffer[NumberOfBytes] = Record.Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
}
|
2021-12-05 23:53:57 +01:00
|
|
|
|
2018-08-23 07:13:21 +02:00
|
|
|
return BytesReturn;
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID *
|
|
|
|
SecAlloc (
|
2021-12-05 23:53:57 +01:00
|
|
|
IN UINTN Size
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return malloc ((size_t)Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
SecFree (
|
2021-12-05 23:53:57 +01:00
|
|
|
IN VOID *Ptr
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (EfiSystemMemoryRange (Ptr)) {
|
|
|
|
// If an address range is in the EFI memory map it was alloced via EFI.
|
|
|
|
// So don't free those ranges and let the caller know.
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
free (Ptr);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-08-23 07:36:14 +02:00
|
|
|
//
|
|
|
|
// Define a global that we can use to shut down the NT timer thread when
|
|
|
|
// the timer is canceled.
|
|
|
|
//
|
2021-12-05 23:53:57 +01:00
|
|
|
BOOLEAN mCancelTimerThread = FALSE;
|
2018-08-23 07:36:14 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// The notification function to call on every timer interrupt
|
|
|
|
//
|
|
|
|
EMU_SET_TIMER_CALLBACK *mTimerNotifyFunction = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// The thread handle for this driver
|
|
|
|
//
|
2021-12-05 23:53:57 +01:00
|
|
|
HANDLE mNtMainThreadHandle;
|
2018-08-23 07:36:14 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// The timer value from the last timer interrupt
|
|
|
|
//
|
2021-12-05 23:53:57 +01:00
|
|
|
UINT32 mNtLastTick;
|
2018-08-23 07:36:14 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Critical section used to update varibles shared between the main thread and
|
|
|
|
// the timer interrupt thread.
|
|
|
|
//
|
2021-12-05 23:53:57 +01:00
|
|
|
CRITICAL_SECTION mNtCriticalSection;
|
2018-08-23 07:36:14 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Worker Functions
|
|
|
|
//
|
2021-12-05 23:53:57 +01:00
|
|
|
UINT mMMTimerThreadID = 0;
|
2018-08-23 07:36:14 +02:00
|
|
|
|
2021-12-05 23:53:57 +01:00
|
|
|
volatile BOOLEAN mInterruptEnabled = FALSE;
|
2018-08-23 07:36:14 +02:00
|
|
|
|
|
|
|
VOID
|
|
|
|
CALLBACK
|
|
|
|
MMTimerThread (
|
2021-12-05 23:53:57 +01:00
|
|
|
UINT wTimerID,
|
|
|
|
UINT msg,
|
|
|
|
DWORD dwUser,
|
|
|
|
DWORD dw1,
|
|
|
|
DWORD dw2
|
|
|
|
)
|
2018-08-23 07:36:14 +02:00
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
UINT32 CurrentTick;
|
|
|
|
UINT32 Delta;
|
2018-08-23 07:36:14 +02:00
|
|
|
|
|
|
|
if (!mCancelTimerThread) {
|
|
|
|
//
|
|
|
|
// Suspend the main thread until we are done.
|
|
|
|
// Enter the critical section before suspending
|
|
|
|
// and leave the critical section after resuming
|
|
|
|
// to avoid deadlock between main and timer thread.
|
|
|
|
//
|
|
|
|
EnterCriticalSection (&mNtCriticalSection);
|
|
|
|
SuspendThread (mNtMainThreadHandle);
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the timer thread is being canceled, then bail immediately.
|
|
|
|
// We check again here because there's a small window of time from when
|
|
|
|
// this thread was kicked off and when we suspended the main thread above.
|
|
|
|
//
|
|
|
|
if (mCancelTimerThread) {
|
|
|
|
ResumeThread (mNtMainThreadHandle);
|
|
|
|
LeaveCriticalSection (&mNtCriticalSection);
|
|
|
|
timeKillEvent (wTimerID);
|
|
|
|
mMMTimerThreadID = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!mInterruptEnabled) {
|
|
|
|
//
|
|
|
|
// Resume the main thread
|
|
|
|
//
|
|
|
|
ResumeThread (mNtMainThreadHandle);
|
|
|
|
LeaveCriticalSection (&mNtCriticalSection);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Wait for interrupts to be enabled.
|
|
|
|
//
|
|
|
|
while (!mInterruptEnabled) {
|
|
|
|
Sleep (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Suspend the main thread until we are done
|
|
|
|
//
|
|
|
|
EnterCriticalSection (&mNtCriticalSection);
|
|
|
|
SuspendThread (mNtMainThreadHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the current system tick
|
|
|
|
//
|
|
|
|
CurrentTick = GetTickCount ();
|
2021-12-05 23:53:57 +01:00
|
|
|
Delta = CurrentTick - mNtLastTick;
|
2018-08-23 07:36:14 +02:00
|
|
|
mNtLastTick = CurrentTick;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If delay was more then 1 second, ignore it (probably debugging case)
|
|
|
|
//
|
|
|
|
if (Delta < 1000) {
|
|
|
|
//
|
|
|
|
// Only invoke the callback function if a Non-NULL handler has been
|
|
|
|
// registered. Assume all other handlers are legal.
|
|
|
|
//
|
|
|
|
if (mTimerNotifyFunction != NULL) {
|
|
|
|
mTimerNotifyFunction (Delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Resume the main thread
|
|
|
|
//
|
|
|
|
ResumeThread (mNtMainThreadHandle);
|
|
|
|
LeaveCriticalSection (&mNtCriticalSection);
|
|
|
|
} else {
|
|
|
|
timeKillEvent (wTimerID);
|
|
|
|
mMMTimerThreadID = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 07:02:52 +02:00
|
|
|
VOID
|
|
|
|
SecSetTimer (
|
|
|
|
IN UINT64 TimerPeriod,
|
|
|
|
IN EMU_SET_TIMER_CALLBACK Callback
|
2021-12-05 23:53:57 +01:00
|
|
|
)
|
2018-08-23 07:02:52 +02:00
|
|
|
{
|
2018-08-23 07:36:14 +02:00
|
|
|
//
|
2021-12-05 23:53:57 +01:00
|
|
|
// If TimerPeriod is 0, then the timer thread should be canceled
|
|
|
|
//
|
2018-08-23 07:36:14 +02:00
|
|
|
if (TimerPeriod == 0) {
|
|
|
|
//
|
|
|
|
// Cancel the timer thread
|
|
|
|
//
|
|
|
|
EnterCriticalSection (&mNtCriticalSection);
|
|
|
|
|
|
|
|
mCancelTimerThread = TRUE;
|
|
|
|
|
|
|
|
LeaveCriticalSection (&mNtCriticalSection);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Wait for the timer thread to exit
|
|
|
|
//
|
|
|
|
|
|
|
|
if (mMMTimerThreadID != 0) {
|
|
|
|
timeKillEvent (mMMTimerThreadID);
|
|
|
|
mMMTimerThreadID = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// If the TimerPeriod is valid, then create and/or adjust the period of the timer thread
|
|
|
|
//
|
|
|
|
EnterCriticalSection (&mNtCriticalSection);
|
|
|
|
|
|
|
|
mCancelTimerThread = FALSE;
|
|
|
|
|
|
|
|
LeaveCriticalSection (&mNtCriticalSection);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the starting tick location if we are just starting the timer thread
|
|
|
|
//
|
|
|
|
mNtLastTick = GetTickCount ();
|
|
|
|
|
|
|
|
if (mMMTimerThreadID) {
|
|
|
|
timeKillEvent (mMMTimerThreadID);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetThreadPriority (
|
|
|
|
GetCurrentThread (),
|
|
|
|
THREAD_PRIORITY_HIGHEST
|
2021-12-05 23:53:57 +01:00
|
|
|
);
|
2018-08-23 07:36:14 +02:00
|
|
|
|
|
|
|
mMMTimerThreadID = timeSetEvent (
|
2021-12-05 23:53:57 +01:00
|
|
|
(UINT)TimerPeriod,
|
|
|
|
0,
|
|
|
|
MMTimerThread,
|
|
|
|
(DWORD_PTR)NULL,
|
|
|
|
TIME_PERIODIC | TIME_KILL_SYNCHRONOUS | TIME_CALLBACK_FUNCTION
|
|
|
|
);
|
2018-08-23 07:36:14 +02:00
|
|
|
}
|
2021-12-05 23:53:57 +01:00
|
|
|
|
2018-08-23 07:36:14 +02:00
|
|
|
mTimerNotifyFunction = Callback;
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
SecInitializeThunk (
|
|
|
|
VOID
|
2021-12-05 23:53:57 +01:00
|
|
|
)
|
2018-08-23 07:02:52 +02:00
|
|
|
{
|
2018-08-23 07:36:14 +02:00
|
|
|
InitializeCriticalSection (&mNtCriticalSection);
|
|
|
|
|
|
|
|
DuplicateHandle (
|
|
|
|
GetCurrentProcess (),
|
|
|
|
GetCurrentThread (),
|
|
|
|
GetCurrentProcess (),
|
|
|
|
&mNtMainThreadHandle,
|
|
|
|
0,
|
|
|
|
FALSE,
|
|
|
|
DUPLICATE_SAME_ACCESS
|
2021-12-05 23:53:57 +01:00
|
|
|
);
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
SecEnableInterrupt (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2018-08-23 07:36:14 +02:00
|
|
|
mInterruptEnabled = TRUE;
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
SecDisableInterrupt (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2018-08-23 07:36:14 +02:00
|
|
|
mInterruptEnabled = FALSE;
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT64
|
|
|
|
SecQueryPerformanceFrequency (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Hard code to nanoseconds
|
|
|
|
return 1000000000ULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT64
|
|
|
|
SecQueryPerformanceCounter (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
SecSleep (
|
2021-12-05 23:53:57 +01:00
|
|
|
IN UINT64 Nanoseconds
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
Sleep ((DWORD)DivU64x32 (Nanoseconds, 1000000));
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
SecCpuSleep (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Sleep (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
SecExit (
|
2021-12-05 23:53:57 +01:00
|
|
|
UINTN Status
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
exit ((int)Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
SecGetTime (
|
2021-12-05 23:53:57 +01:00
|
|
|
OUT EFI_TIME *Time,
|
|
|
|
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
|
2018-08-23 07:02:52 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
SYSTEMTIME SystemTime;
|
|
|
|
TIME_ZONE_INFORMATION TimeZone;
|
2018-08-23 07:37:37 +02:00
|
|
|
|
|
|
|
GetLocalTime (&SystemTime);
|
|
|
|
GetTimeZoneInformation (&TimeZone);
|
|
|
|
|
2021-12-05 23:53:57 +01:00
|
|
|
Time->Year = (UINT16)SystemTime.wYear;
|
|
|
|
Time->Month = (UINT8)SystemTime.wMonth;
|
|
|
|
Time->Day = (UINT8)SystemTime.wDay;
|
|
|
|
Time->Hour = (UINT8)SystemTime.wHour;
|
|
|
|
Time->Minute = (UINT8)SystemTime.wMinute;
|
|
|
|
Time->Second = (UINT8)SystemTime.wSecond;
|
2018-08-23 07:37:37 +02:00
|
|
|
Time->Nanosecond = (UINT32)(SystemTime.wMilliseconds * 1000000);
|
2021-12-05 23:53:57 +01:00
|
|
|
Time->TimeZone = (INT16)TimeZone.Bias;
|
2018-08-23 07:37:37 +02:00
|
|
|
|
|
|
|
if (Capabilities != NULL) {
|
|
|
|
Capabilities->Resolution = 1;
|
2021-12-05 23:53:57 +01:00
|
|
|
Capabilities->Accuracy = 50000000;
|
2018-08-23 07:37:37 +02:00
|
|
|
Capabilities->SetsToZero = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Time->Daylight = 0;
|
|
|
|
if (TimeZone.StandardDate.wMonth) {
|
|
|
|
Time->Daylight = (UINT8)TimeZone.StandardDate.wMonth;
|
|
|
|
}
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
SecSetTime (
|
2021-12-05 23:53:57 +01:00
|
|
|
IN EFI_TIME *Time
|
2018-08-23 07:37:37 +02:00
|
|
|
)
|
2018-08-23 07:02:52 +02:00
|
|
|
{
|
2021-12-05 23:53:57 +01:00
|
|
|
TIME_ZONE_INFORMATION TimeZone;
|
|
|
|
SYSTEMTIME SystemTime;
|
|
|
|
BOOL Flag;
|
2018-08-23 07:37:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Set Daylight savings time information and Time Zone
|
|
|
|
//
|
|
|
|
GetTimeZoneInformation (&TimeZone);
|
|
|
|
TimeZone.StandardDate.wMonth = Time->Daylight;
|
2021-12-05 23:53:57 +01:00
|
|
|
TimeZone.Bias = Time->TimeZone;
|
|
|
|
Flag = SetTimeZoneInformation (&TimeZone);
|
2018-08-23 07:37:37 +02:00
|
|
|
if (!Flag) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:53:57 +01:00
|
|
|
SystemTime.wYear = Time->Year;
|
|
|
|
SystemTime.wMonth = Time->Month;
|
|
|
|
SystemTime.wDay = Time->Day;
|
|
|
|
SystemTime.wHour = Time->Hour;
|
|
|
|
SystemTime.wMinute = Time->Minute;
|
|
|
|
SystemTime.wSecond = Time->Second;
|
2018-08-23 07:37:37 +02:00
|
|
|
SystemTime.wMilliseconds = (INT16)(Time->Nanosecond / 1000000);
|
|
|
|
|
|
|
|
Flag = SetLocalTime (&SystemTime);
|
|
|
|
|
|
|
|
if (!Flag) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
} else {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2018-08-23 07:02:52 +02:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:53:57 +01:00
|
|
|
EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
|
2018-08-23 07:02:52 +02:00
|
|
|
SecWriteStdErr,
|
|
|
|
SecConfigStdIn,
|
|
|
|
SecWriteStdOut,
|
|
|
|
SecReadStdIn,
|
|
|
|
SecPollStdIn,
|
|
|
|
SecAlloc,
|
|
|
|
NULL,
|
|
|
|
SecFree,
|
|
|
|
SecPeCoffGetEntryPoint,
|
|
|
|
PeCoffLoaderRelocateImageExtraAction,
|
|
|
|
PeCoffLoaderUnloadImageExtraAction,
|
|
|
|
SecEnableInterrupt,
|
|
|
|
SecDisableInterrupt,
|
|
|
|
SecQueryPerformanceFrequency,
|
|
|
|
SecQueryPerformanceCounter,
|
|
|
|
SecSleep,
|
|
|
|
SecCpuSleep,
|
|
|
|
SecExit,
|
|
|
|
SecGetTime,
|
|
|
|
SecSetTime,
|
|
|
|
SecSetTimer,
|
|
|
|
GetNextThunkProtocol
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma warning(default : 4996)
|
|
|
|
#pragma warning(default : 4232)
|