Bug Summary

File:home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeSmiVmcallHandler.c
Warning:line 511, column 3
Value stored to 'Write' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name PeSmiVmcallHandler.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-jump-tables -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/build/StmPkg/Core/Runtime -resource-dir /opt/xgcc/lib/clang/17 -include PcdData.h -D COREBOOT32 -D RELEASE -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EDKII/BaseTools/Source/C/Include/X64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EdkII/MdePkg/Include -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EdkII/MdePkg/Include/X64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Include -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Include/x64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/../Init -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/. -internal-isystem /opt/xgcc/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -source-date-epoch 1714465709 -Os -fdebug-compilation-dir=/home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/build/StmPkg/Core/Runtime -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-max-loop 10 -analyzer-output=plist-html -faddrsig -o /cb-build/coreboot_scanbuild.0/PURISM_LIBREM15_V4_STM-scanbuildtmp/2024-05-02-081243-2232343-1/report-YGcPeO.plist -x c /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeSmiVmcallHandler.c
1#include "StmRuntime.h"
2#include "PeStm.h"
3#include "PeLoadVm.h"
4
5extern PE_VM_DATA PeVmData[4];
6extern PE_SMI_CONTROL PeSmiControl;
7
8extern INT32 PeEptInit (EPT_POINTER *EptPointer);
9extern void print_region_list(UINT32 PeType, UINT32 CpuIndex);
10extern UINT32 SetupProtExecVm(UINT32 CpuIndex, UINT32 VM_Configuration, UINT32 mode, UINT32 PeType);
11extern void LaunchPeVm(UINT32 PeType, UINT32 CpuIndex);
12extern VOIDvoid EptDumpPageTable (IN EPT_POINTER *EptPointer );
13static UINT32 setupModulepages(UINT32 PeType, UINT32 CpuIndex);
14
15STM_STATUS AddPeVm(UINT32 CpuIndex, PE_MODULE_INFO * callerDataStructure, UINT32 PeType, UINT32 RunVm)
16{
17 // assume that the caller has aready moved the module_info data structure
18 // into SMRAM and made sure that the MLE has not done something funny
19
20 UINTN *sourceBuffer = (UINTN *)NULL((void *) 0);
21 UINTN *destBuffer = (UINTN *) NULL((void *) 0);
22
23 STM_STATUS rc;
24 RETURN_STATUS rc1, rc2, rc3; // used for return code
25 UINT32 pageAlignedSize;
26 UINT32 numModulePages;
27 UINT_128 Data128;
28
29 DEBUG((EFI_D_INFO,"%ld AddPeVm - entered, PeType: %d\n", CpuIndex, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040,"%ld AddPeVm - entered, PeType: %d\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
;
30
31 /* Check to see if there is an active PeVm or if the feature has been turned off */
32
33 if((PeVmData[PeType].PeVmState == PE_VM_OPT_OUT3) ||
34 (PeVmData[PeType].PeVmState == PE_VM_OPT_OUT_PERM6))
35 {
36 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ERROR - Perm PE/VM has been opted out\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ERROR - Perm PE/VM has been opted out\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
37 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ERROR - Perm PE/VM has been opted out\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
38 return(PE_VM_PERM_OPT_OUT0x8004001D);
39 }
40
41 if((PeVmData[PeType].PeVmState == PE_VM_OPT_OUT3) ||
42 (PeVmData[PeType].PeVmState == PE_VM_OPT_OUT_TEMP7))
43 {
44 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ERROR - Temp PE/VM has been opted out\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ERROR - Temp PE/VM has been opted out\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
45 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ERROR - Temp PE/VM has been opted out\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
46 return(PE_VM_TEMP_OPT_OUT0x80040021);
47 }
48
49 if(PeVmData[PeType].PeVmState != PE_VM_AVAIL0)
50 {
51 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ERROR PE/VM already active\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ERROR PE/VM already active\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
52 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ERROR PE/VM already active\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
53 if(PeType == PE_PERM1)
54 return(PE_VM_PERM_ALREADY_ESTABLISHED0x8004001E);
55 else
56 return(PE_VM_TEMP_ACTIVE0x8004001F);
57 }
58
59 PeVmData[PeType].PeVmState = PE_VM_ACTIVE1; // indicate we are here
60
61 DEBUG((EFI_D_INFO, "%ld AddPeVm - callerDataStructure location: 0x%08lx 0x%08lx\n", CpuIndex, (UINT64) (((UINT64)callerDataStructure) >> 32), (UINT64)(callerDataStructure)))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld AddPeVm - callerDataStructure location: 0x%08lx 0x%08lx\n"
, CpuIndex, (UINT64) (((UINT64)callerDataStructure) >> 32
), (UINT64)(callerDataStructure)); } } while (((BOOLEAN)(0==1
)))
;
62
63 // pull information from the modules data structure
64
65 PeVmData[PeType].UserModule.ModuleLoadAddress = callerDataStructure->ModuleLoadAddress;
66 PeVmData[PeType].UserModule.ModuleSize = callerDataStructure->ModuleSize;
67 PeVmData[PeType].UserModule.ModuleEntryPoint = callerDataStructure->ModuleEntryPoint;
68 PeVmData[PeType].UserModule.AddressSpaceStart = callerDataStructure->AddressSpaceStart;
69 PeVmData[PeType].UserModule.AddressSpaceSize = callerDataStructure->AddressSpaceSize;
70
71 PeVmData[PeType].UserModule.VmConfig = callerDataStructure->VmConfig;
72 PeVmData[PeType].UserModule.Cr3Load = callerDataStructure->Cr3Load;
73 PeVmData[PeType].UserModule.SharedPage = callerDataStructure->SharedPage;
74 PeVmData[PeType].UserModule.SharedPageSize = callerDataStructure->SharedPageSize;
75 PeVmData[PeType].UserModule.Segment = callerDataStructure->Segment;
76 PeVmData[PeType].UserModule.ModuleAddress = callerDataStructure->ModuleAddress;
77 PeVmData[PeType].UserModule.ModuleDataSection = callerDataStructure->ModuleDataSection;
78 PeVmData[PeType].UserModule.DoNotClearSize = callerDataStructure->DoNotClearSize;
79 PeVmData[PeType].UserModule.RunCount = 0;
80
81#if defined (MDE_CPU_X64)
82 sourceBuffer = (UINTN *)((PeVmData[PeType].UserModule.ModuleAddress));
83#else
84 sourceBuffer = (UINTN *) ((UINT32) (PeVmData[PeType].UserModule.ModuleAddress) & 0x0FFFFFFFF);
85 // note need to check for corner case where user passed 64 bit address to STM
86#endif
87
88 if (!IsGuestAddressValid ((UINTN)sourceBuffer, PeVmData[PeType].UserModule.ModuleSize, TRUE((BOOLEAN)(1==1))))
89 {
90 DEBUG((EFI_D_ERROR, "%ld AddPeVm - module_address: bad physical address %p\n", CpuIndex,(void *) sourceBuffer))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - module_address: bad physical address %p\n"
, CpuIndex,(void *) sourceBuffer); } } while (((BOOLEAN)(0==1
)))
;
91
92 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
93 return(PE_VM_BAD_PHYSICAL_ADDRESS0x8004001A);
94 }
95
96 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ModuleSize: %ld (0x%08lx)\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ModuleSize: %ld (0x%08lx)\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleSize, (UINT64)PeVmData
[PeType].UserModule.ModuleSize); } } while (((BOOLEAN)(0==1))
)
97 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ModuleSize: %ld (0x%08lx)\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleSize, (UINT64)PeVmData
[PeType].UserModule.ModuleSize); } } while (((BOOLEAN)(0==1))
)
98 PeVmData[PeType].UserModule.ModuleSize,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ModuleSize: %ld (0x%08lx)\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleSize, (UINT64)PeVmData
[PeType].UserModule.ModuleSize); } } while (((BOOLEAN)(0==1))
)
99 (UINT64)PeVmData[PeType].UserModule.ModuleSize))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ModuleSize: %ld (0x%08lx)\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleSize, (UINT64)PeVmData
[PeType].UserModule.ModuleSize); } } while (((BOOLEAN)(0==1))
)
;
100 DEBUG((EFI_D_ERROR, "%ld AddPeVm - module_entry_point: 0x%p\n", CpuIndex, (UINT64)PeVmData[PeType].UserModule.ModuleEntryPoint))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - module_entry_point: 0x%p\n"
, CpuIndex, (UINT64)PeVmData[PeType].UserModule.ModuleEntryPoint
); } } while (((BOOLEAN)(0==1)))
;
101 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ModuleLoadAddress: 0x%p\n", CpuIndex, (UINT64)PeVmData[PeType].UserModule.ModuleLoadAddress))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ModuleLoadAddress: 0x%p\n"
, CpuIndex, (UINT64)PeVmData[PeType].UserModule.ModuleLoadAddress
); } } while (((BOOLEAN)(0==1)))
;
102 DEBUG((EFI_D_ERROR, "%ld AddPeVm - AddressSpaceStart: 0x%p\n", CpuIndex, (UINT64)PeVmData[PeType].UserModule.AddressSpaceStart))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - AddressSpaceStart: 0x%p\n"
, CpuIndex, (UINT64)PeVmData[PeType].UserModule.AddressSpaceStart
); } } while (((BOOLEAN)(0==1)))
;
103 DEBUG((EFI_D_ERROR, "%ld AddPeVm - AddressSpaceSize: 0x%p\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.AddressSpaceSize))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - AddressSpaceSize: 0x%p\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.AddressSpaceSize
); } } while (((BOOLEAN)(0==1)))
;
104 DEBUG((EFI_D_ERROR, "%ld AddPeVm - DoNotClearSize: 0x%08lx\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.DoNotClearSize))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - DoNotClearSize: 0x%08lx\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.DoNotClearSize
); } } while (((BOOLEAN)(0==1)))
;
105
106 DEBUG((EFI_D_ERROR, "%ld AddPeVm - CR3_LOAD: 0x%p\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.Cr3Load))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - CR3_LOAD: 0x%p\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.Cr3Load); } }
while (((BOOLEAN)(0==1)))
;
107 DEBUG((EFI_D_ERROR, "%ld AddPeVm - VmConfig: 0x%08lx\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.VmConfig))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - VmConfig: 0x%08lx\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.VmConfig); }
} while (((BOOLEAN)(0==1)))
;
108 DEBUG((EFI_D_ERROR, "%ld AddPeVm - shared page 0x%p\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.SharedPage))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - shared page 0x%p\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.SharedPage);
} } while (((BOOLEAN)(0==1)))
;
109
110 DEBUG((EFI_D_ERROR, "%ld AddPeVm - shared page size 0x%llx\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.SharedPageSize))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - shared page size 0x%llx\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.SharedPageSize
); } } while (((BOOLEAN)(0==1)))
;
111 DEBUG((EFI_D_ERROR, "%ld stmApaAddVM - segment page 0x%p\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.Segment))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld stmApaAddVM - segment page 0x%p\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.Segment); } }
while (((BOOLEAN)(0==1)))
;
112 DEBUG((EFI_D_ERROR, "%ld AddPeVm - module_address 0x%p\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.ModuleAddress))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - module_address 0x%p\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.ModuleAddress
); } } while (((BOOLEAN)(0==1)))
;
113 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ModuleDataSection 0x%p\n", CpuIndex, (UINT64) PeVmData[PeType].UserModule.ModuleDataSection))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ModuleDataSection 0x%p\n"
, CpuIndex, (UINT64) PeVmData[PeType].UserModule.ModuleDataSection
); } } while (((BOOLEAN)(0==1)))
;
114 if(PeVmData[PeType].UserModule.SharedPage != 0) //NULL not used because of 32bit/64bit diff
115 {
116 if (!IsGuestAddressValid ((UINTN)PeVmData[PeType].UserModule.SharedPage,
117 (UINTN)PeVmData[PeType].UserModule.SharedPageSize,TRUE((BOOLEAN)(1==1))))
118 {
119 DEBUG((EFI_D_ERROR, "%ld AddPeVm - module_address: bad physical address %llx\n", CpuIndex,(void *) sourceBuffer))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - module_address: bad physical address %llx\n"
, CpuIndex,(void *) sourceBuffer); } } while (((BOOLEAN)(0==1
)))
;
120
121 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
122 return(PE_VM_BAD_PHYSICAL_ADDRESS0x8004001A);
123 }
124 }
125
126 // determine how large the module is
127 // go to the module and determine its size from the header block
128
129 // allocate the space needed for the requested space
130
131 numModulePages = (PeVmData[PeType].UserModule.AddressSpaceSize + (PAGE_SIZE4096 - 1)) >> 12; // calculate the number of pages in the module
132
133 // allocate the space for the PE VM based upon the guest Address Space Size
134 PeVmData[PeType].SmmBuffer = (UINTN *) AllocatePages(numModulePages);
135 PeVmData[PeType].SmmBufferSize = numModulePages; // AllocatePages does not retain size
136
137 DEBUG((EFI_D_ERROR, "%ld AddPeVm - SmmBuffer at: %llx PeType: %d\n", CpuIndex, PeVmData[PeType].SmmBuffer, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - SmmBuffer at: %llx PeType: %d\n"
, CpuIndex, PeVmData[PeType].SmmBuffer, PeType); } } while ((
(BOOLEAN)(0==1)))
;
138
139 if(PeVmData[PeType].SmmBuffer == NULL((void *) 0))
140 {
141 DEBUG((EFI_D_ERROR, "%ld AddPeVm - failed to allocate module destination buffer\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - failed to allocate module destination buffer\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
142 FreePE_DataStructures(PeType);
143 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
144 return(PE_SPACE_TOO_LARGE0x80040001);
145 }
146 // move the module into the space
147
148 // since we are allowing the user to have a larger memory than the module itself
149 // we need to calculate where within SmmBuffer the module will be placed.
150 // things to check for self protection (will return an error to the user)
151 // ModuleLoadAddress < AddressSpaceStart
152 // ModuleLoadAddress + ModuleSize > AddressSpaceStart + AddressSpaceSize
153
154 {
155 if(PeVmData[PeType].UserModule.ModuleLoadAddress < PeVmData[PeType].UserModule.AddressSpaceStart)
156 {
157 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Error: ModuleLoadAddress is lower than Address_Space_Start\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Error: ModuleLoadAddress is lower than Address_Space_Start\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
158 FreePE_DataStructures(PeType);
159 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
160 return(PE_MODULE_ADDRESS_TOO_LOW0x80040002);
161 }
162
163 // calculate the location within the allocated space to place the module
164 destBuffer = PeVmData[PeType].SmmBuffer + PeVmData[PeType].UserModule.AddressSpaceStart -
165 PeVmData[PeType].UserModule.ModuleLoadAddress;
166 }
167
168 // make sure that the size of the module will fit into the allocated space
169
170 pageAlignedSize = numModulePages << 12;
171 {
172 UINT64 Avail_Space = pageAlignedSize - (PeVmData[PeType].UserModule.ModuleLoadAddress - PeVmData[PeType].UserModule.AddressSpaceStart);
173 if(Avail_Space < PeVmData[PeType].UserModule.ModuleSize)
174 {
175 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Error: ModuleSize is too large to fit in the address space\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Error: ModuleSize is too large to fit in the address space\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
176 FreePE_DataStructures(PeType);
177 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
178 return(PE_MODULE_TOO_LARGE0x80040003);
179 }
180 }
181
182 DEBUG((EFI_D_ERROR, "%ld AddPeVm - destBuffer: %llx sourceBuffer: %llx PeType %d\n", CpuIndex, (UINT64)destBuffer, (UINT64)sourceBuffer, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: %llx sourceBuffer: %llx PeType %d\n"
, CpuIndex, (UINT64)destBuffer, (UINT64)sourceBuffer, PeType)
; } } while (((BOOLEAN)(0==1)))
;
183 {
184 CopyMem (destBuffer, sourceBuffer, PeVmData[PeType].UserModule.ModuleSize);
185
186 DEBUG((EFI_D_ERROR, "%ld AddPeVm - **loaded Module SMRAM location: 0x%016llx ModuleSize: 0x%08x contents: 0x%016llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - **loaded Module SMRAM location: 0x%016llx ModuleSize: 0x%08x contents: 0x%016llx\n"
, CpuIndex, destBuffer, PeVmData[PeType].UserModule.ModuleSize
, *destBuffer); } } while (((BOOLEAN)(0==1)))
187 CpuIndex, destBuffer, PeVmData[PeType].UserModule.ModuleSize, *destBuffer))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - **loaded Module SMRAM location: 0x%016llx ModuleSize: 0x%08x contents: 0x%016llx\n"
, CpuIndex, destBuffer, PeVmData[PeType].UserModule.ModuleSize
, *destBuffer); } } while (((BOOLEAN)(0==1)))
;
188 }
189
190 DEBUG((EFI_D_ERROR, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
191 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
192 *destBuffer,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
193 *(destBuffer + sizeof(UINT64)),do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
194 *(destBuffer + 2*sizeof(UINT64)),do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
195 *(destBuffer + 3*sizeof(UINT64)),do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
196 *(destBuffer + 4*sizeof(UINT64))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
197 ))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - destBuffer: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n"
, CpuIndex, *destBuffer, *(destBuffer + sizeof(UINT64)), *(destBuffer
+ 2*sizeof(UINT64)), *(destBuffer + 3*sizeof(UINT64)), *(destBuffer
+ 4*sizeof(UINT64)) ); } } while (((BOOLEAN)(0==1)))
;
198
199 /// create the EPT tables for the PE VM
200 /// need to create this for Intel Ref c
201
202 rc = PeEptInit(&mGuestContextCommonSmm[PeType].EptPointer);
203
204 if (rc != STM_SUCCESS0x00000000) {
205 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Unable to setup PE page tables\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Unable to setup PE page tables\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
206 FreePE_DataStructures(PeType);
207 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
208 return(PE_NO_PT_SPACE0x80040004);
209 }
210
211 // setup the permission for the shared page
212 // map in our pages
213
214 // setup the user module pages and address space
215
216 rc1 = setupModulepages(PeType, CpuIndex);
217
218 if(rc1 != STM_SUCCESS0x00000000)
219 {
220 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Unable to setup Module pages \n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Unable to setup Module pages \n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
221 FreePE_DataStructures(PeType);
222 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
223 return(PE_MODULE_MAP_FAILURE0x80040008);
224 }
225
226 DEBUG((EFI_D_ERROR, "%ld AddPeVm - module pages sucessfully setup\n now setting up shared page\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - module pages sucessfully setup\n now setting up shared page\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
227 rc2 = EPTSetPageAttributeRange(
228 mGuestContextCommonSmm[PeType].EptPointer.Uint64,
229 (UINTN) PeVmData[PeType].UserModule.SharedPage,
230 (UINTN) PeVmData[PeType].UserModule.SharedPageSize,
231 (UINTN) PeVmData[PeType].UserModule.SharedPage,
232 TRUE((BOOLEAN)(1==1)), /*read*/
233 TRUE((BOOLEAN)(1==1)), /*write*/
234 FALSE((BOOLEAN)(0==1)), /*execute*/
235 EptPageAttributeSet,
236 -1);
237
238 if(rc2 != STM_SUCCESS0x00000000) {
239 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Unable to map shared page into Prot Exec VM\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Unable to map shared page into Prot Exec VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
240 FreePE_DataStructures(PeType);
241 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
242 return(PE_SHARED_MAP_FAILURE0x80040009);
243 }
244 DEBUG((EFI_D_ERROR, "%ld AddPeVm - shared page sucessfully mapped - PeType: %d\n", CpuIndex, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - shared page sucessfully mapped - PeType: %d\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
;
245
246 // set the permission and the PTEs for the r/o regions
247
248 // setup the permission for the region list itself
249 if(PeVmData[PeType].UserModule.Segment != NULL((void *) 0))
250 {
251 int counter;
252 PE_REGION_LIST * rlist;
253
254 if(!IsGuestAddressValid ((UINTN)PeVmData[PeType].UserModule.Segment,
255 4096,TRUE((BOOLEAN)(1==1))))
256 {
257 DEBUG((EFI_D_ERROR, "%ld AddPeVm - region list: bad physical address: %p Size: %x\n", CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - region list: bad physical address: %p Size: %x\n"
, CpuIndex, PeVmData[PeType].UserModule.SharedPage, PeVmData[
PeType].UserModule.SharedPageSize ); } } while (((BOOLEAN)(0==
1)))
258 PeVmData[PeType].UserModule.SharedPage, PeVmData[PeType].UserModule.SharedPageSize ))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - region list: bad physical address: %p Size: %x\n"
, CpuIndex, PeVmData[PeType].UserModule.SharedPage, PeVmData[
PeType].UserModule.SharedPageSize ); } } while (((BOOLEAN)(0==
1)))
;
259 FreePE_DataStructures(PeType);
260
261 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
262 return(PE_VM_BAD_PHYSICAL_ADDRESS0x8004001A);
263 }
264
265 // link the list into the PE VM's space
266 DEBUG((EFI_D_ERROR, "%ld AddPeVm - mapping region list into PE VM Space - PeType %d\n", CpuIndex, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - mapping region list into PE VM Space - PeType %d\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
;
267
268 rc3 = EPTSetPageAttributeRange(
269 mGuestContextCommonSmm[PeType].EptPointer.Uint64,
270 (UINTN)PeVmData[PeType].UserModule.Segment,
271 4096,
272 (UINTN)PeVmData[PeType].UserModule.Segment, /* identity mapped */
273 TRUE((BOOLEAN)(1==1)), /* READ */
274 FALSE((BOOLEAN)(0==1)), /* write */
275 FALSE((BOOLEAN)(0==1)), /* Execute */
276 EptPageAttributeSet,
277 -1);
278
279 if (rc3 != STM_SUCCESS0x00000000)
280 {
281 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Couldn't Setup region list access\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Couldn't Setup region list access\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
282 FreePE_DataStructures(PeType);
283 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
284 return(PE_REGION_LIST_SETUP_ERROR0x80040018);
285 }
286
287 // now process the region list
288
289 rlist = (PE_REGION_LIST *)PeVmData[PeType].UserModule.Segment; // start the list
290
291 // need to work in corner cases
292
293 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Setting up region list - PeType: %d\n", CpuIndex, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Setting up region list - PeType: %d\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
;
294 for(counter = 0; counter < (4096/sizeof(PE_REGION_LIST)); counter++)
295 {
296 //!!! - Need to check to ensure the region is valid
297
298 if((UINTN)rlist[counter].Address == 0)
299 break; // all done
300
301 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Setting up region %p size %016lx PeType: %d\n", CpuIndex, (UINTN) rlist[counter].Address, (UINTN) rlist[counter].Size, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Setting up region %p size %016lx PeType: %d\n"
, CpuIndex, (UINTN) rlist[counter].Address, (UINTN) rlist[counter
].Size, PeType); } } while (((BOOLEAN)(0==1)))
;
302 if(!IsGuestAddressValid((UINTN)rlist[counter].Address,(UINTN)rlist[counter].Size,TRUE((BOOLEAN)(1==1))))
303 {
304 DEBUG((EFI_D_ERROR, "%ld AddPeVm - region: bad physical address %p size %016lx\n", CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - region: bad physical address %p size %016lx\n"
, CpuIndex, (UINTN)rlist[counter].Address,(UINTN)rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
305 (UINTN)rlist[counter].Address,(UINTN)rlist[counter].Size))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - region: bad physical address %p size %016lx\n"
, CpuIndex, (UINTN)rlist[counter].Address,(UINTN)rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
;
306#ifdef PRODUCTION
307 FreePE_DataStructures(PeType);
308 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
309 return(PE_VM_BAD_PHYSICAL_ADDRESS0x8004001A);
310#endif
311 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ***Warning*** bad region data - ignoring region entry in debug system\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ***Warning*** bad region data - ignoring region entry in debug system\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
312 }
313 else
314 {
315 // now link it into the page table
316 rc3 = EPTSetPageAttributeRange(
317 mGuestContextCommonSmm[PeType].EptPointer.Uint64,
318 (UINTN)rlist[counter].Address,
319 (UINTN)rlist[counter].Size,
320 (UINTN)rlist[counter].Address, /* identity map */
321 TRUE((BOOLEAN)(1==1)), /* READ */
322 FALSE((BOOLEAN)(0==1)), /* write */
323 FALSE((BOOLEAN)(0==1)), /* Execute */
324 EptPageAttributeSet,
325 -1);
326
327 if (rc3 != STM_SUCCESS0x00000000)
328 {
329 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Couldn't Setup region list\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Couldn't Setup region list\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
330 FreePE_DataStructures(PeType);
331 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
332 return(PE_REGION_LIST_SETUP_ERROR0x80040018);
333 }
334 }
335 }
336 print_region_list(PeType, CpuIndex);
337 }
338 else
339 {
340 DEBUG((EFI_D_ERROR, "%ld AddPeVm - No caller region requested\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - No caller region requested\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
341 }
342
343 // allocate a page to be shared between the STM and the module
344
345 // figure out a location in the guest physical address space for the page
346 //
347 // locate the shared STM/module page at the end of the guest physical address space
348
349 PeVmData[PeType].UserModule.SharedStmPage = PeVmData[PeType].UserModule.AddressSpaceStart + PeVmData[PeType].UserModule.AddressSpaceSize;
350 PeVmData[PeType].SharedPageStm = (UINTN *) AllocatePages(1); // one page for now
351
352 DEBUG((EFI_D_ERROR, "%ld AddPeVm - ShareModuleStm at: %p\n", CpuIndex, PeVmData[PeType].SharedPageStm))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - ShareModuleStm at: %p\n"
, CpuIndex, PeVmData[PeType].SharedPageStm); } } while (((BOOLEAN
)(0==1)))
;
353
354 if(PeVmData[PeType].SharedPageStm == NULL((void *) 0))
355 {
356 DEBUG((EFI_D_ERROR,"%ld AddPeVm - failed to allocate module - STM shared page\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000,"%ld AddPeVm - failed to allocate module - STM shared page\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
357 FreePE_DataStructures(PeType);
358 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
359 return(PE_VM_PE_SETUP_ERROR0x80040023);
360 }
361 // move the
362
363 rc1 = EPTSetPageAttributeRange(
364 mGuestContextCommonSmm[PeType].EptPointer.Uint64,
365 (UINTN)PeVmData[PeType].UserModule.SharedStmPage,
366 4096,
367 (UINTN) PeVmData[PeType].SharedPageStm,
368 TRUE((BOOLEAN)(1==1)), /* read */
369 FALSE((BOOLEAN)(0==1)), /* write */
370 FALSE((BOOLEAN)(0==1)), /* execute */
371 EptPageAttributeSet,
372 -1);
373
374 if(rc1 != STM_SUCCESS0x00000000)
375 {
376 DEBUG((EFI_D_ERROR, "%d AddPeVm: could not setup module-stm shared page\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d AddPeVm: could not setup module-stm shared page\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
377 }
378 DEBUG((EFI_D_ERROR, "%d AddPeVm: module-stm shared page setup\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d AddPeVm: module-stm shared page setup\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
379 //EptDumpPageTable (&mGuestContextCommonSmm[PeType].EptPointer);
380 ///link the PT with the allocated space
381
382 /// somehow have the STM's PT mark these as R/O or invisable... (TODO)
383
384 // check the hash, etc of the module (TBD stuff)
385
386 Data128.Lo = mGuestContextCommonSmm[PeType].EptPointer.Uint64;
387 Data128.Hi = 0;
388 AsmInvEpt (INVEPT_TYPE_SINGLE_CONTEXT_INVALIDATION1, &Data128);
389
390 // (for now) start the VM...
391 PeVmData[PeType].StartMode = PEVM_START_VMCALL1;
392
393 rc = SetupProtExecVm(CpuIndex, PeVmData[PeType].UserModule.VmConfig, NEW_VM1, PeType);
394
395 if(rc != PE_SUCCESS0) // did we have a problem
396 {
397 DEBUG((EFI_D_ERROR, "%ld AddPeVm - Error in configuring PE VM\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - Error in configuring PE VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
398 FreePE_DataStructures(PeType);
399 //setPEerrorCode(rc, StmVmm); // tell the caller of the problem
400 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
401 // StmVmm->NonSmiHandler = 0; // no longer an PE VM
402 AsmVmPtrLoad(&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Vmcs);
403
404 /// at this point we should return to the MLE as per the Intel method...
405
406 AsmVmClear(&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Vmcs);
407 mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType = SMI_HANDLER0;
408 return(rc);
409 }
410 DEBUG((EFI_D_ERROR, "%ld AddPeVm - sucessfully completed - PeApicId: 0x%llx PeType: %d\n", CpuIndex, PeSmiControl.PeApicId, PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - sucessfully completed - PeApicId: 0x%llx PeType: %d\n"
, CpuIndex, PeSmiControl.PeApicId, PeType); } } while (((BOOLEAN
)(0==1)))
;
411
412 if(RunVm == 1)
413 {
414 PeVmData[PeType].StartMode = PEVM_START_VMCALL1;
415 LaunchPeVm(PeType, CpuIndex); // launch the PE/VM
416
417 // if we get to this point the PeVm has failed to launch so we need clean up the mess
418 // and return the error to the caller
419 FreePE_DataStructures(PeType);
420 DEBUG((EFI_D_ERROR, "%ld AddPeVm - VM/PE Launch Failure\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - VM/PE Launch Failure\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
421 rc = PE_VMLAUNCH_ERROR0x8004000B;
422 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
423 }
424 else
425 {
426 DEBUG((EFI_D_ERROR, "%ld AddPeVm - VM not run per option\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld AddPeVm - VM not run per option\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
427 rc = STM_SUCCESS0x00000000;
428 PeVmData[PeType].PeVmState = PE_VM_IDLE2; // waiting for action
429 PeSmiControl.PeExec = 0; // make sure
430 }
431 //setPEerrorCode(PE_VM_BAD_PHYSICAL_ADDRESS, StmVmm);
432
433 AsmVmPtrLoad(&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Vmcs);
434
435 /// at this point we should return to the MLE as per the Intel method...
436
437 AsmVmClear(&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Vmcs);
438
439 mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType = SMI_HANDLER0;
440 //PeSmiControl.PeExec = 1; // when 1 PE_APIC_ID is executing a
441 return rc;
442}
443
444STM_STATUS setupModulepages(UINT32 PeType, UINT32 CpuIndex)
445{
446 RETURN_STATUS rc1 = STM_SUCCESS0x00000000;
447 UINTN module_end, Address_end;
448 BOOLEAN Write = FALSE((BOOLEAN)(0==1)); // default for text region
449 BOOLEAN ExecuteHeap = FALSE((BOOLEAN)(0==1));
450 UINTN module_address = PeVmData[PeType].UserModule.ModuleLoadAddress & ~OFFSET_BITMASK_IA32_4K0x00000FFF;
451 UINTN ModuleSize; //= (PeVmData[PeType].UserModule.ModuleSize +(module_address - PeVmData[PeType].UserModule.ModuleLoadAddress)+ PAGE_SIZE_4K - 1) & ~OFFSET_BITMASK_IA32E_4K;
452
453 UINTN AddressSpaceStart = (UINTN) (PeVmData[PeType].UserModule.AddressSpaceStart & 0xFFFFFFFF);
454 UINTN AddressSpaceSize = (PeVmData[PeType].UserModule.AddressSpaceSize + PAGE_SIZE_4K4096ULL - 1) & ~OFFSET_BITMASK_IA32E_4K0x0000000000000FFF;
455 UINTN StartEndBlock;
456
457 PeVmData[PeType].UserModule.ModuleDataSection &= ~OFFSET_BITMASK_IA32_4K0x00000FFF;
458
459 if(PeVmData[PeType].UserModule.ModuleDataSection == 0)
460 {
461 ModuleSize = (PeVmData[PeType].UserModule.ModuleSize + (module_address - PeVmData[PeType].UserModule.ModuleLoadAddress)+ PAGE_SIZE_4K4096ULL - 1) & ~OFFSET_BITMASK_IA32E_4K0x0000000000000FFF;
462 }
463 else
464 {
465 ModuleSize = (UINTN)(PeVmData[PeType].UserModule.ModuleDataSection & 0xFFFFFFFF) - module_address;
466 }
467
468 DEBUG((EFI_D_ERROR, "%ld setModulepages - entered AddressSpaceStart: %x AddressSpaceSize: %x\n", CpuIndex, AddressSpaceStart, AddressSpaceSize))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - entered AddressSpaceStart: %x AddressSpaceSize: %x\n"
, CpuIndex, AddressSpaceStart, AddressSpaceSize); } } while (
((BOOLEAN)(0==1)))
;
469 if(module_address > AddressSpaceStart)
470 {
471 // we have some space between the start of the address space and the module
472
473 PeVmData[PeType].UserModule.FrontDataRegionSize = module_address - AddressSpaceStart;
474
475 DEBUG((EFI_D_ERROR, "%ld setModulepages - setting up address space before the PE module (AddressSpaceStart): %x\n", CpuIndex, AddressSpaceStart))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - setting up address space before the PE module (AddressSpaceStart): %x\n"
, CpuIndex, AddressSpaceStart); } } while (((BOOLEAN)(0==1)))
;
476
477 rc1 = EPTSetPageAttributeRange(
478 mGuestContextCommonSmm[PeType].EptPointer.Uint64,
479 AddressSpaceStart,
480 PeVmData[PeType].UserModule.FrontDataRegionSize,
481 (UINTN) PeVmData[PeType].SmmBuffer,
482 TRUE((BOOLEAN)(1==1)), /* read */
483 TRUE((BOOLEAN)(1==1)), /* write */
484 FALSE((BOOLEAN)(0==1)), /* execute */
485 EptPageAttributeSet,
486 -1);
487
488 if(rc1 != RETURN_SUCCESS0)
489 {
490 DEBUG((EFI_D_ERROR, "%ld setModulepages - failed to setup area in front of module\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - failed to setup area in front of module\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
491 return 0xFFFFFFFF; // generic stm error
492 }
493 }
494 else
495 {
496 DEBUG((EFI_D_ERROR, "%ld setModulepages - no data space in front of module\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - no data space in front of module\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
497 PeVmData[PeType].UserModule.FrontDataRegionSize = 0;
498 if(module_address < AddressSpaceStart)
499 {
500 DEBUG((EFI_D_ERROR, "%ld setModulepages: Module starts before address space starts\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages: Module starts before address space starts\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
501 return ERROR_STM_UNSPECIFIED0x8001FFFF; // universal error for now
502 }
503 }
504
505 // stuff in the middle
506
507 DEBUG((EFI_D_ERROR, "%ld setModulepages: Setting up area in the middle (module_address): %x\n", CpuIndex, module_address))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages: Setting up area in the middle (module_address): %x\n"
, CpuIndex, module_address); } } while (((BOOLEAN)(0==1)))
;
508
509 if((PeVmData[PeType].UserModule.VmConfig & PERM_VM_SET_TEXT_RW(1<<24)) == PERM_VM_SET_TEXT_RW(1<<24))
510 {
511 Write = TRUE((BOOLEAN)(1==1));
Value stored to 'Write' is never read
512 }
513
514 rc1 = EPTSetPageAttributeRange(
515 mGuestContextCommonSmm[PeType].EptPointer.Uint64,
516 module_address,
517 ModuleSize,
518 (UINTN)((UINTN)PeVmData[PeType].SmmBuffer + (UINTN)PeVmData[PeType].UserModule.FrontDataRegionSize),
519 TRUE((BOOLEAN)(1==1)), /* READ */
520 TRUE((BOOLEAN)(1==1)), /* write */
521 TRUE((BOOLEAN)(1==1)), /* Execute */
522 EptPageAttributeSet,
523 -1);
524
525 if(rc1 != RETURN_SUCCESS0)
526 {
527 DEBUG((EFI_D_ERROR, "%d setModulepages - could not setup module area within address space\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d setModulepages - could not setup module area within address space\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
528 return ERROR_STM_UNSPECIFIED0x8001FFFF; // generic stm error
529 }
530 // stuff at the end
531
532 module_end = module_address + ModuleSize;
533 Address_end = AddressSpaceStart + AddressSpaceSize;
534
535 if(PeVmData[PeType].UserModule.ModuleDataSection == 0)
536 {
537 DEBUG((EFI_D_ERROR, "%ld setModulepages - ModuleDataSection is NULL, calculating data section\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - ModuleDataSection is NULL, calculating data section\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
538
539 // user did not provide a data section - so we calculate it
540
541 PeVmData[PeType].UserModule.ModuleDataSection = module_end;
542 }
543
544 if(PeVmData[PeType].UserModule.ModuleDataSection < Address_end)
545 {
546 PeVmData[PeType].UserModule.DataRegionSize = Address_end - module_end;
547 StartEndBlock = (UINTN) (((UINTN) PeVmData[PeType].SmmBuffer) + (PeVmData[PeType].UserModule.ModuleDataSection - PeVmData[PeType].UserModule.AddressSpaceStart));
548 DEBUG((EFI_D_ERROR, "%ld setModulepages - Setting up area at the end (module_end): %x\n", CpuIndex, module_end))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - Setting up area at the end (module_end): %x\n"
, CpuIndex, module_end); } } while (((BOOLEAN)(0==1)))
;
549 DEBUG((EFI_D_ERROR, "%ld setModulepages - module_end: %llx DataRegionSize: %llx DataRegionStart: %llx SmmBuffer: %llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - module_end: %llx DataRegionSize: %llx DataRegionStart: %llx SmmBuffer: %llx\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleDataSection, PeVmData
[PeType].UserModule.DataRegionSize, PeVmData[PeType].UserModule
.ModuleDataSection, PeVmData[PeType].SmmBuffer); } } while ((
(BOOLEAN)(0==1)))
550 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - module_end: %llx DataRegionSize: %llx DataRegionStart: %llx SmmBuffer: %llx\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleDataSection, PeVmData
[PeType].UserModule.DataRegionSize, PeVmData[PeType].UserModule
.ModuleDataSection, PeVmData[PeType].SmmBuffer); } } while ((
(BOOLEAN)(0==1)))
551 PeVmData[PeType].UserModule.ModuleDataSection,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - module_end: %llx DataRegionSize: %llx DataRegionStart: %llx SmmBuffer: %llx\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleDataSection, PeVmData
[PeType].UserModule.DataRegionSize, PeVmData[PeType].UserModule
.ModuleDataSection, PeVmData[PeType].SmmBuffer); } } while ((
(BOOLEAN)(0==1)))
552 PeVmData[PeType].UserModule.DataRegionSize,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - module_end: %llx DataRegionSize: %llx DataRegionStart: %llx SmmBuffer: %llx\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleDataSection, PeVmData
[PeType].UserModule.DataRegionSize, PeVmData[PeType].UserModule
.ModuleDataSection, PeVmData[PeType].SmmBuffer); } } while ((
(BOOLEAN)(0==1)))
553 PeVmData[PeType].UserModule.ModuleDataSection,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - module_end: %llx DataRegionSize: %llx DataRegionStart: %llx SmmBuffer: %llx\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleDataSection, PeVmData
[PeType].UserModule.DataRegionSize, PeVmData[PeType].UserModule
.ModuleDataSection, PeVmData[PeType].SmmBuffer); } } while ((
(BOOLEAN)(0==1)))
554 PeVmData[PeType].SmmBuffer))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - module_end: %llx DataRegionSize: %llx DataRegionStart: %llx SmmBuffer: %llx\n"
, CpuIndex, PeVmData[PeType].UserModule.ModuleDataSection, PeVmData
[PeType].UserModule.DataRegionSize, PeVmData[PeType].UserModule
.ModuleDataSection, PeVmData[PeType].SmmBuffer); } } while ((
(BOOLEAN)(0==1)))
;
555
556 PeVmData[PeType].UserModule.DataRegionSmmLoc = StartEndBlock;
557
558 DEBUG((EFI_D_ERROR, "%ld setModulepages - StartEndBlock: %llx\n", CpuIndex, StartEndBlock))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld setModulepages - StartEndBlock: %llx\n"
, CpuIndex, StartEndBlock); } } while (((BOOLEAN)(0==1)))
;
559
560 if((PeVmData[PeType].UserModule.VmConfig & PERM_VM_EXEC_HEAP(1<<25)) == PERM_VM_EXEC_HEAP(1<<25))
561 {
562 ExecuteHeap = TRUE((BOOLEAN)(1==1));
563 DEBUG((EFI_D_ERROR, "%d setModulepages - Execute Heap set to TRUE\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d setModulepages - Execute Heap set to TRUE\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
564 }
565 else
566 ExecuteHeap = FALSE((BOOLEAN)(0==1));
567
568 /*DEBUG DEBUG((EFI_D_ERROR, "%d setModulepages - Execute Heap set to TRUE for debug purposes\n", CpuIndex));
569 ExecuteHeap = TRUE;*/
570
571 rc1 = EPTSetPageAttributeRange(
572 mGuestContextCommonSmm[PeType].EptPointer.Uint64,
573 (UINTN)PeVmData[PeType].UserModule.ModuleDataSection,
574 PeVmData[PeType].UserModule.DataRegionSize,
575 StartEndBlock,
576 TRUE((BOOLEAN)(1==1)), /* read */
577 TRUE((BOOLEAN)(1==1)), /* write */
578 ExecuteHeap, /* execute */
579 EptPageAttributeSet,
580 -1);
581
582 if(rc1 != RETURN_SUCCESS0)
583 {
584 DEBUG((EFI_D_ERROR, "%d setModulepages - could not setup end of address space\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d setModulepages - could not setup end of address space\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
585 return ERROR_STM_UNSPECIFIED0x8001FFFF;
586 }
587 DEBUG((EFI_D_ERROR, "%d setModulepages - end address region setup\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d setModulepages - end address region setup\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
588 }
589 else
590 {
591 PeVmData[PeType].UserModule.DataRegionSize = 0;
592 if(module_end == Address_end)
593 {
594 DEBUG((EFI_D_ERROR, "%d setModulepages - no space after end of module\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d setModulepages - no space after end of module\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
595 }
596 else
597 {
598 DEBUG((EFI_D_ERROR, "%d setModulepages - end of Module is beyond address space end\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d setModulepages - end of Module is beyond address space end\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
599 rc1 = ERROR_STM_UNSPECIFIED0x8001FFFF;
600 }
601 }
602
603 // verify the no data section clearing size
604
605 if((UINTN)PeVmData[PeType].UserModule.DoNotClearSize > PeVmData[PeType].UserModule.DataRegionSize)
606 {
607 DEBUG((EFI_D_ERROR, "%d setModulepages - DoNotClearSize larger than DataRegionSize - Using DataRegion Size\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d setModulepages - DoNotClearSize larger than DataRegionSize - Using DataRegion Size\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
608 PeVmData[PeType].UserModule.DoNotClearSize = (UINT32)PeVmData[PeType].UserModule.DataRegionSize;
609 }
610 DEBUG((EFI_D_ERROR, "%d SetModulepages - DoNotClearSize is: 0x%08lx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d SetModulepages - DoNotClearSize is: 0x%08lx\n"
, CpuIndex, PeVmData[PeType].UserModule.DoNotClearSize); } } while
(((BOOLEAN)(0==1)))
611 CpuIndex, PeVmData[PeType].UserModule.DoNotClearSize))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%d SetModulepages - DoNotClearSize is: 0x%08lx\n"
, CpuIndex, PeVmData[PeType].UserModule.DoNotClearSize); } } while
(((BOOLEAN)(0==1)))
;
612
613 //EptDumpPageTable (&mGuestContextCommonSmm[PeType].EptPointer);
614 return (STM_STATUS) rc1;
615}