]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/Sec/SecMain.c
CorebootPayloadPkg: Add "Down" key to Boot Manager Menu
[mirror_edk2.git] / Nt32Pkg / Sec / SecMain.c
index 0504b959f17a3506005dbd1dce4ca3fd96da21fc..e9f72dfba10e39460e5f0b5115ad10d0705dfd3b 100644 (file)
@@ -1,6 +1,7 @@
 /**@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
@@ -30,7 +31,9 @@ Abstract:
 \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
@@ -42,7 +45,7 @@ EFI_PEI_PROGRESS_CODE_PPI                 mSecStatusCodePpi     = { SecPeiReport
 \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
@@ -107,6 +110,16 @@ SecNt32PeCoffRelocateImage (
   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
@@ -121,11 +134,13 @@ SecPrint (
   \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
@@ -155,6 +170,8 @@ Returns:
 --*/\r
 {\r
   EFI_STATUS            Status;\r
+  HANDLE                Token;\r
+  TOKEN_PRIVILEGES      TokenPrivileges;\r
   EFI_PHYSICAL_ADDRESS  InitialStackMemory;\r
   UINT64                InitialStackMemorySize;\r
   UINTN                 Index;\r
@@ -167,12 +184,40 @@ Returns:
   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
@@ -362,7 +407,7 @@ Returns:
   //\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
@@ -378,7 +423,7 @@ Returns:
   NtMapHandle = CreateFileMapping (\r
                   NtFileHandle,\r
                   NULL,\r
-                  PAGE_READWRITE,\r
+                  PAGE_EXECUTE_READWRITE,\r
                   0,\r
                   MapSize,\r
                   NULL\r
@@ -391,7 +436,7 @@ Returns:
   //\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
@@ -489,6 +534,7 @@ Returns:
   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
@@ -546,6 +592,7 @@ PeiSwitchStacks (
   //\r
   ASSERT (FALSE);  \r
 }\r
+#endif\r
 \r
 VOID\r
 SecLoadFromCore (\r
@@ -763,7 +810,7 @@ Returns:
   // 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