/**@file\r
\r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
#include "SecMain.h"\r
\r
-\r
+#ifndef SE_TIME_ZONE_NAME\r
+#define SE_TIME_ZONE_NAME TEXT("SeTimeZonePrivilege")\r
+#endif\r
\r
NT_PEI_LOAD_FILE_PPI mSecNtLoadFilePpi = { SecWinNtPeiLoadFile };\r
\r
\r
NT_FWH_PPI mSecFwhInformationPpi = { SecWinNtFdAddress };\r
\r
-TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};\r
+EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};\r
\r
EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {\r
{\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
);\r
\r
+VOID\r
+EFIAPI\r
+PeiSwitchStacks (\r
+ IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
+ IN VOID *Context1, OPTIONAL\r
+ IN VOID *Context2, OPTIONAL\r
+ IN VOID *Context3, OPTIONAL\r
+ IN VOID *NewStack\r
+ );\r
+\r
VOID\r
SecPrint (\r
CHAR8 *Format,\r
\r
_vsnprintf (Buffer, sizeof (Buffer), Format, Marker);\r
\r
+ va_end (Marker);\r
+\r
CharCount = strlen (Buffer);\r
WriteFile (\r
GetStdHandle (STD_OUTPUT_HANDLE), \r
Buffer,\r
- CharCount,\r
+ (DWORD)CharCount,\r
(LPDWORD)&CharCount,\r
NULL\r
);\r
--*/\r
{\r
EFI_STATUS Status;\r
+ HANDLE Token;\r
+ TOKEN_PRIVILEGES TokenPrivileges;\r
EFI_PHYSICAL_ADDRESS InitialStackMemory;\r
UINT64 InitialStackMemorySize;\r
UINTN Index;\r
CHAR16 *MemorySizeStr;\r
CHAR16 *FirmwareVolumesStr;\r
UINTN *StackPointer;\r
+ UINT32 ProcessAffinityMask;\r
+ UINT32 SystemAffinityMask;\r
+ INT32 LowBit;\r
+\r
+\r
+ //\r
+ // Enable the privilege so that RTC driver can successfully run SetTime()\r
+ //\r
+ OpenProcessToken (GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &Token);\r
+ if (LookupPrivilegeValue(NULL, SE_TIME_ZONE_NAME, &TokenPrivileges.Privileges[0].Luid)) {\r
+ TokenPrivileges.PrivilegeCount = 1;\r
+ TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\r
+ AdjustTokenPrivileges(Token, FALSE, &TokenPrivileges, 0, (PTOKEN_PRIVILEGES) NULL, 0);\r
+ }\r
\r
MemorySizeStr = (CHAR16 *) PcdGetPtr (PcdWinNtMemorySizeForSecMain);\r
FirmwareVolumesStr = (CHAR16 *) PcdGetPtr (PcdWinNtFirmwareVolume);\r
\r
SecPrint ("\nEDK II SEC Main NT Emulation Environment from www.TianoCore.org\n");\r
\r
+ //\r
+ // Determine the first thread available to this process.\r
+ //\r
+ if (GetProcessAffinityMask (GetCurrentProcess (), &ProcessAffinityMask, &SystemAffinityMask)) {\r
+ LowBit = (INT32)LowBitSet32 (ProcessAffinityMask);\r
+ if (LowBit != -1) {\r
+ //\r
+ // Force the system to bind the process to a single thread to work\r
+ // around odd semaphore type crashes.\r
+ //\r
+ SetProcessAffinityMask (GetCurrentProcess (), (INTN)(BIT0 << LowBit));\r
+ }\r
+ }\r
+\r
//\r
// Make some Windows calls to Set the process to the highest priority in the\r
// idle class. We need this to have good performance.\r
//\r
NtFileHandle = CreateFile (\r
FileName,\r
- GENERIC_READ | GENERIC_WRITE,\r
+ GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE,\r
FILE_SHARE_READ,\r
NULL,\r
CreationDisposition,\r
NtMapHandle = CreateFileMapping (\r
NtFileHandle,\r
NULL,\r
- PAGE_READWRITE,\r
+ PAGE_EXECUTE_READWRITE,\r
0,\r
MapSize,\r
NULL\r
//\r
VirtualAddress = MapViewOfFileEx (\r
NtMapHandle,\r
- FILE_MAP_ALL_ACCESS,\r
+ FILE_MAP_EXECUTE | FILE_MAP_ALL_ACCESS,\r
0,\r
0,\r
MapSize,\r
return EFI_SUCCESS;\r
}\r
\r
+#if defined (MDE_CPU_IA32)\r
/**\r
Transfers control to a function starting with a new stack.\r
\r
//\r
ASSERT (FALSE); \r
}\r
+#endif\r
\r
VOID\r
SecLoadFromCore (\r
// Align buffer on section boundry\r
//\r
ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;\r
- ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);\r
+ ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);\r
\r
Status = PeCoffLoaderLoadImage (&ImageContext);\r
if (EFI_ERROR (Status)) {\r