mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-09-20 02:41:03 +02:00
more memory protections
Signed-off-by: Slice <sergey.slice@gmail.com>
This commit is contained in:
parent
00466c6e61
commit
48ff60474a
@ -198,6 +198,7 @@
|
|||||||
OcFlexArrayLib|OpenCorePkg/Library/OcFlexArrayLib/OcFlexArrayLib.inf
|
OcFlexArrayLib|OpenCorePkg/Library/OcFlexArrayLib/OcFlexArrayLib.inf
|
||||||
OcMainLib|OpenCorePkg/Library/OcMainLib/OcMainLibClover.inf
|
OcMainLib|OpenCorePkg/Library/OcMainLib/OcMainLibClover.inf
|
||||||
OcMemoryLib|OpenCorePkg/Library/OcMemoryLib/OcMemoryLib.inf
|
OcMemoryLib|OpenCorePkg/Library/OcMemoryLib/OcMemoryLib.inf
|
||||||
|
# OcMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
|
||||||
OcMiscLib|OpenCorePkg/Library/OcMiscLib/OcMiscLib.inf
|
OcMiscLib|OpenCorePkg/Library/OcMiscLib/OcMiscLib.inf
|
||||||
OcOSInfoLib|OpenCorePkg/Library/OcOSInfoLib/OcOSInfoLib.inf
|
OcOSInfoLib|OpenCorePkg/Library/OcOSInfoLib/OcOSInfoLib.inf
|
||||||
# OcPngLib|OpenCorePkg/Library/OcPngLib/OcPngLib.inf
|
# OcPngLib|OpenCorePkg/Library/OcPngLib/OcPngLib.inf
|
||||||
@ -372,10 +373,10 @@
|
|||||||
<BuildOptions>
|
<BuildOptions>
|
||||||
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
||||||
}
|
}
|
||||||
OpenCorePkg/Library/OcMemoryLib/OcMemoryLib.inf {
|
# OpenCorePkg/Library/OcMemoryLib/OcMemoryLib.inf {
|
||||||
<BuildOptions>
|
# <BuildOptions>
|
||||||
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
# *_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
||||||
}
|
# }
|
||||||
OpenCorePkg/Library/OcMiscLib/OcMiscLib.inf {
|
OpenCorePkg/Library/OcMiscLib/OcMiscLib.inf {
|
||||||
<BuildOptions>
|
<BuildOptions>
|
||||||
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 8c86c0e75f6b1b59247f5b4f897f22453e09c26d
|
Subproject commit 7525d807fb9dd156e7e728c591b384f063b657b9
|
@ -70,9 +70,9 @@ then
|
|||||||
|
|
||||||
bios_file=("$(dirname "$qemu_path")"/bios*)
|
bios_file=("$(dirname "$qemu_path")"/bios*)
|
||||||
|
|
||||||
diskutil umount /dev/disk4s1
|
diskutil umount /dev/disk3s1
|
||||||
diskutil umount /dev/disk4s2
|
diskutil umount /dev/disk3s2
|
||||||
diskutil eject disk4
|
diskutil eject disk3
|
||||||
|
|
||||||
"$qemu_path" \
|
"$qemu_path" \
|
||||||
-L "$(dirname "$qemu_path")" \
|
-L "$(dirname "$qemu_path")" \
|
||||||
@ -94,7 +94,7 @@ diskutil eject disk4
|
|||||||
# -hdc /JiefLand/5.Devel/Clover/CloverEfi.vmw/ElCapitan.vmdk \
|
# -hdc /JiefLand/5.Devel/Clover/CloverEfi.vmw/ElCapitan.vmdk \
|
||||||
|
|
||||||
hdiutil attach ./disk_image_gpt.img
|
hdiutil attach ./disk_image_gpt.img
|
||||||
diskutil mount disk4s1
|
diskutil mount disk3s1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
26
buildme
26
buildme
@ -31,9 +31,9 @@ tell application "Terminal"
|
|||||||
activate
|
activate
|
||||||
set bounds of window 1 to {0, 23, 615, 420}
|
set bounds of window 1 to {0, 23, 615, 420}
|
||||||
set current settings of window 1 to settings set "Pro"
|
set current settings of window 1 to settings set "Pro"
|
||||||
set font name of window 1 to "Monaco"
|
# set font name of window 1 to "Monaco"
|
||||||
set font size of window 1 to "11"
|
# set font size of window 1 to "11"
|
||||||
set normal text color of window 1 to {3341, 35186, 50092}
|
# set normal text color of window 1 to {3341, 35186, 50092}
|
||||||
set position of first window to {650, 420}
|
set position of first window to {650, 420}
|
||||||
end tell
|
end tell
|
||||||
EOF
|
EOF
|
||||||
@ -895,8 +895,12 @@ do
|
|||||||
makeV2
|
makeV2
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"build Clover with HFSPlus ")
|
"make Release (Default Toolchain) ")
|
||||||
buildCloverHFSPlus
|
makeRelease
|
||||||
|
BLC
|
||||||
|
buildPkg
|
||||||
|
buildIso
|
||||||
|
makeV2
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"update Clover ")
|
"update Clover ")
|
||||||
@ -928,14 +932,6 @@ do
|
|||||||
makeV2
|
makeV2
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"make Release (Default Toolchain)")
|
|
||||||
makeRelease
|
|
||||||
BLC
|
|
||||||
buildPkg
|
|
||||||
buildIso
|
|
||||||
makeV2
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
"make Release (with XCode)")
|
"make Release (with XCode)")
|
||||||
makeReleaseXC
|
makeReleaseXC
|
||||||
BLC
|
BLC
|
||||||
@ -944,6 +940,10 @@ do
|
|||||||
makeV2
|
makeV2
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
|
"build Clover with HFSPlus ")
|
||||||
|
buildCloverHFSPlus
|
||||||
|
break
|
||||||
|
;;
|
||||||
"Extra Options")
|
"Extra Options")
|
||||||
Extra
|
Extra
|
||||||
break
|
break
|
||||||
|
@ -142,32 +142,73 @@ extern EFI_DXE_SERVICES *gDS;
|
|||||||
|
|
||||||
EFI_PHYSICAL_ADDRESS ExtraSpace = EFI_SYSTEM_TABLE_MAX_ADDRESS;
|
EFI_PHYSICAL_ADDRESS ExtraSpace = EFI_SYSTEM_TABLE_MAX_ADDRESS;
|
||||||
|
|
||||||
|
//VOID
|
||||||
|
//PrintMemoryMap()
|
||||||
|
//{
|
||||||
|
// apd<EFI_MEMORY_DESCRIPTOR*> MemMap;
|
||||||
|
// UINTN MemMapSize;
|
||||||
|
// UINTN MapKey, DescriptorSize;
|
||||||
|
// UINT32 DescriptorVersion;
|
||||||
|
// EFI_STATUS Status;
|
||||||
|
//
|
||||||
|
// MemMapSize = 0;
|
||||||
|
// DescriptorSize = 0;
|
||||||
|
// Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
|
// if (Status != EFI_BUFFER_TOO_SMALL) {
|
||||||
|
// DBG("PrintMemoryMap: GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// MemMapSize += EFI_PAGE_SIZE;
|
||||||
|
// MemMap = (EFI_MEMORY_DESCRIPTOR*)AllocatePool(MemMapSize);
|
||||||
|
//
|
||||||
|
// Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
|
// if ( EFI_ERROR(Status) ) {
|
||||||
|
// DBG("PrintMemoryMap: GetMemoryMap failed=%s\n", efiStrError(Status));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// OcPrintMemoryMap(MemMapSize, MemMap, DescriptorSize);
|
||||||
|
//}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
PrintMemoryMap()
|
PrintMemoryMap (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
{
|
{
|
||||||
apd<EFI_MEMORY_DESCRIPTOR*> MemMap;
|
EFI_MEMORY_DESCRIPTOR *MemMap;
|
||||||
UINTN MemMapSize;
|
EFI_MEMORY_DESCRIPTOR *MemMapPtr;
|
||||||
UINTN MapKey, DescriptorSize;
|
UINTN MemMapSize = 0;
|
||||||
UINT32 DescriptorVersion;
|
UINTN MapKey = 0, DescriptorSize = 0;
|
||||||
EFI_STATUS Status;
|
UINT32 DescriptorVersion = 0;
|
||||||
|
UINT64 Bytes;
|
||||||
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
|
||||||
MemMapSize = 0;
|
MemMapSize = 0;
|
||||||
DescriptorSize = 0;
|
MemMap = NULL;
|
||||||
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
if (Status != EFI_BUFFER_TOO_SMALL) {
|
// ASSERT (Status == EFI_BUFFER_TOO_SMALL);
|
||||||
DBG("PrintMemoryMap: GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MemMapSize += EFI_PAGE_SIZE;
|
MemMapSize += EFI_PAGE_SIZE;
|
||||||
MemMap = (EFI_MEMORY_DESCRIPTOR*)AllocatePool(MemMapSize);
|
Status = gBS->AllocatePool (EfiBootServicesData, MemMapSize, (VOID**)&MemMap);
|
||||||
|
// ASSERT (Status == EFI_SUCCESS);
|
||||||
|
if (EFI_ERROR(Status)) return;
|
||||||
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
if ( EFI_ERROR(Status) ) {
|
// ASSERT (Status == EFI_SUCCESS);
|
||||||
DBG("PrintMemoryMap: GetMemoryMap failed=%s\n", efiStrError(Status));
|
MemMapPtr = MemMap;
|
||||||
return;
|
|
||||||
|
// ASSERT (DescriptorVersion == EFI_MEMORY_DESCRIPTOR_VERSION);
|
||||||
|
|
||||||
|
for (UINTN Index = 0; Index < MemMapSize / DescriptorSize; Index ++) {
|
||||||
|
Bytes = LShiftU64 (MemMap->NumberOfPages, 12);
|
||||||
|
DEBUG ((EFI_D_ERROR, "%lX-%lX %lX %lX %X\n",
|
||||||
|
MemMap->PhysicalStart,
|
||||||
|
MemMap->PhysicalStart + Bytes - 1,
|
||||||
|
MemMap->NumberOfPages,
|
||||||
|
MemMap->Attribute,
|
||||||
|
(UINTN)MemMap->Type));
|
||||||
|
MemMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemMap + DescriptorSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
OcPrintMemoryMap(MemMapSize, MemMap, DescriptorSize);
|
gBS->FreePool(MemMapPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -215,32 +256,32 @@ void AllocSmallBlocks(UINTN NumberOfPagesMax)
|
|||||||
FreePool(MemMap);
|
FreePool(MemMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AllocSmallBlocks()
|
//void AllocSmallBlocks()
|
||||||
{
|
//{
|
||||||
CONST EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
|
// CONST EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
|
||||||
|
//
|
||||||
PrintMemoryMap();
|
////PrintMemoryMap();
|
||||||
|
//
|
||||||
UINTN size = 64;
|
// UINTN size = 64;
|
||||||
UINTN nb = 0;
|
// UINTN nb = 0;
|
||||||
|
//
|
||||||
AllocSmallBlocks(size); // 252KB
|
// AllocSmallBlocks(size); // 252KB
|
||||||
|
//
|
||||||
MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
// MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
||||||
nb = MemoryAttributesTable->NumberOfEntries;
|
// nb = MemoryAttributesTable->NumberOfEntries;
|
||||||
|
//
|
||||||
PrintMemoryMap();
|
////PrintMemoryMap();
|
||||||
while ( size <= 2048 && nb > 100 ) { // XNU seems to handle max 128 entries. So let's shrink a little bit under 128
|
// while ( size <= 2048 && nb > 100 ) { // XNU seems to handle max 128 entries. So let's shrink a little bit under 128
|
||||||
size *= 2;
|
// size *= 2;
|
||||||
AllocSmallBlocks(size);
|
// AllocSmallBlocks(size);
|
||||||
MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
// MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
||||||
nb = MemoryAttributesTable->NumberOfEntries;
|
// nb = MemoryAttributesTable->NumberOfEntries;
|
||||||
PrintMemoryMap();
|
////PrintMemoryMap();
|
||||||
}
|
// }
|
||||||
if ( size > 2048 ) {
|
// if ( size > 2048 ) {
|
||||||
DBG("Cannot shrink memory map enough. Nb entries = %lld\n", nb);
|
// DBG("Cannot shrink memory map enough. Nb entries = %lld\n", nb);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
|
static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
|
||||||
@ -1729,9 +1770,11 @@ void LOADER_ENTRY::StartLoader()
|
|||||||
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG);
|
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG);
|
||||||
}
|
}
|
||||||
gBS->FreePages (ExtraSpace, 90000);
|
gBS->FreePages (ExtraSpace, 90000);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef JIEF_DEBUG
|
||||||
AllocSmallBlocks(); // shrink memory map;
|
AllocSmallBlocks(); // shrink memory map;
|
||||||
PrintMemoryMap();
|
PrintMemoryMap();
|
||||||
#ifdef JIEF_DEBUG
|
|
||||||
displayFreeMemory("Just before launching image"_XS8);
|
displayFreeMemory("Just before launching image"_XS8);
|
||||||
#endif
|
#endif
|
||||||
Status = gBS->StartImage (ImageHandle, 0, NULL); // point to OcStartImage from OC
|
Status = gBS->StartImage (ImageHandle, 0, NULL); // point to OcStartImage from OC
|
||||||
@ -2911,6 +2954,9 @@ RefitMainMain (IN EFI_HANDLE ImageHandle,
|
|||||||
#if 0
|
#if 0
|
||||||
//testing place
|
//testing place
|
||||||
{
|
{
|
||||||
|
//#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
|
||||||
|
#define L_STR_LEN(String) (ARRAY_SIZE (String) - 1)
|
||||||
|
DBG("strlen '<' =%ld or %lld\n", L_STR_LEN("<"), AsciiStrLen("<"));
|
||||||
DBG(" size CHAR8=%ld\n", sizeof(CHAR8));
|
DBG(" size CHAR8=%ld\n", sizeof(CHAR8));
|
||||||
DBG(" size CHAR16=%ld\n", sizeof(CHAR16));
|
DBG(" size CHAR16=%ld\n", sizeof(CHAR16));
|
||||||
DBG(" size wchar_t=%ld\n", sizeof(wchar_t));
|
DBG(" size wchar_t=%ld\n", sizeof(wchar_t));
|
||||||
|
Loading…
Reference in New Issue
Block a user