[BOOTLIB] Fix 64 bit issues (#433)

This commit is contained in:
Timo Kreuzer 2018-03-18 16:10:41 +01:00 committed by GitHub
parent 8bbbab534a
commit 3be4081607
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 85 additions and 58 deletions

View file

@ -231,7 +231,7 @@ BmpFwGetApplicationDirectoryPath (
)
{
NTSTATUS Status;
ULONG i, AppPathLength;
SIZE_T i, AppPathLength;
PWCHAR ApplicationPath, PathCopy;
/* Clear the incoming string */
@ -257,11 +257,11 @@ BmpFwGetApplicationDirectoryPath (
}
/* Check if we have space for one more character */
Status = RtlULongAdd(i, 1, &AppPathLength);
Status = RtlSIZETAdd(i, 1, &AppPathLength);
if (NT_SUCCESS(Status))
{
/* Check if it's safe to multiply by two */
Status = RtlULongMult(AppPathLength, sizeof(WCHAR), &AppPathLength);
Status = RtlSIZETMult(AppPathLength, sizeof(WCHAR), &AppPathLength);
if (NT_SUCCESS(Status))
{
/* Allocate a copy for the string */
@ -647,11 +647,11 @@ BmpFwGetFullPath (
)
{
NTSTATUS Status;
ULONG BootDirLength, PathLength;
SIZE_T BootDirLength, PathLength;
/* Compute the length of the directory, and add a NUL */
BootDirLength = wcslen(BootDirectory);
Status = RtlULongAdd(BootDirLength, 1, &BootDirLength);
Status = RtlSIZETAdd(BootDirLength, 1, &BootDirLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;
@ -659,14 +659,14 @@ BmpFwGetFullPath (
/* Add the length of the file, make sure it fits */
PathLength = wcslen(FileName);
Status = RtlULongAdd(PathLength, BootDirLength, &PathLength);
Status = RtlSIZETAdd(PathLength, BootDirLength, &PathLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;
}
/* Convert to bytes */
Status = RtlULongLongToULong(PathLength * sizeof(WCHAR), &PathLength);
Status = RtlSIZETMult(PathLength, sizeof(WCHAR), &PathLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;
@ -716,7 +716,7 @@ BmOpenDataStore (
PBL_DEVICE_DESCRIPTOR BcdDevice;
PWCHAR BcdPath, FullPath, PathBuffer;
BOOLEAN HavePath;
ULONG PathLength, FullSize;
SIZE_T PathLength, FullSize;
PVOID FinalBuffer;
UNICODE_STRING BcdString;
@ -795,21 +795,21 @@ BmOpenDataStore (
/* Add a NUL to the path, make sure it'll fit */
PathLength = wcslen(PathBuffer);
Status = RtlULongAdd(PathLength, 1, &PathLength);
Status = RtlSIZETAdd(PathLength, 1, &PathLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;
}
/* Convert to bytes */
Status = RtlULongLongToULong(PathLength * sizeof(WCHAR), &PathLength);
Status = RtlSIZETMult(PathLength, sizeof(WCHAR), &PathLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;
}
/* Now add the size of the path to the device path, check if it fits */
Status = RtlULongAdd(PathLength, BcdDevice->Size, &FullSize);
Status = RtlSIZETAdd(PathLength, BcdDevice->Size, &FullSize);
if (!NT_SUCCESS(Status))
{
goto Quickie;
@ -2158,7 +2158,7 @@ BmDisplayDumpError (
if (BmpInternalBootError)
{
/* Return it -- but it's a pointer? */
return (ULONG)BmpInternalBootError; // ???
return (ULONG_PTR)BmpInternalBootError; // ???
}
/* Otherwise, show the menu to see what to do */

View file

@ -9785,7 +9785,7 @@ OslDrawLogo (
CoordinateX = (DspGraphicalConsole->DisplayMode.HRes / 2) - (BmpWidth / 2);
CoordinateY = (DspGraphicalConsole->DisplayMode.VRes / 2) - (BmpHeight / 2);
BlMmTranslateVirtualAddress(GopBlt, &GopBltPhys);
GopBlt = (PVOID)GopBltPhys.LowPart;
GopBlt = PhysicalAddressToPtr(GopBltPhys);
/* Make the screen black */
RtlFillMemory(DspGraphicalConsole->FrameBuffer,

View file

@ -1385,6 +1385,14 @@ MmMdInitializeListHead (
List->Type = 0;
}
FORCEINLINE
PVOID
PhysicalAddressToPtr (
_In_ PHYSICAL_ADDRESS PhysicalAddress)
{
return (PVOID)(ULONG_PTR)PhysicalAddress.QuadPart;
}
/* INITIALIZATION ROUTINES ***************************************************/
NTSTATUS
@ -2369,7 +2377,7 @@ BlpMmCreateBlockAllocator (
PVOID
BlMmAllocateHeap (
_In_ ULONG Size
_In_ SIZE_T Size
);
NTSTATUS

View file

@ -13,6 +13,9 @@
/* DATA VARIABLES ************************************************************/
PBL_ARCH_CONTEXT CurrentExecutionContext;
PBL_MM_RELOCATE_SELF_MAP BlMmRelocateSelfMap;
PBL_MM_MOVE_VIRTUAL_ADDRESS_RANGE BlMmMoveVirtualAddressRange;
PBL_MM_ZERO_VIRTUAL_ADDRESS_RANGE BlMmZeroVirtualAddressRange;
/* FUNCTIONS *****************************************************************/
@ -50,3 +53,13 @@ Archx86TransferTo32BitApplicationAsm (VOID)
EfiPrintf(L" Archx86TransferTo32BitApplicationAsm NOT IMPLEMENTED for this platform\r\n");
}
NTSTATUS
OslArchTransferToKernel(
_In_ struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
_In_ PVOID KernelEntrypoint
)
{
EfiPrintf(L" OslArchTransferToKernel NOT IMPLEMENTED for this platform\r\n");
return STATUS_NOT_IMPLEMENTED;
}

View file

@ -280,7 +280,7 @@ EfiVmOpenProtocol (
}
/* Check what address the interface lives at, and translate it */
InterfaceVa = (PVOID)InterfaceAddress.LowPart;
InterfaceVa = PhysicalAddressToPtr(InterfaceAddress);
if (BlMmTranslateVirtualAddress(InterfaceVa, &TranslatedAddress))
{
/* We expect firmware to be 1:1 mapped, fail if not */
@ -868,9 +868,9 @@ EfiConInExSetState (
{
/* Translate pointers from virtual to physical */
BlMmTranslateVirtualAddress(ConInEx, &ConInExPhys);
ConInEx = (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL*)ConInExPhys.LowPart;
ConInEx = (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL*)PhysicalAddressToPtr(ConInExPhys);
BlMmTranslateVirtualAddress(KeyToggleState, &KeyTogglePhys);
KeyToggleState = (EFI_KEY_TOGGLE_STATE*)KeyTogglePhys.LowPart;
KeyToggleState = (EFI_KEY_TOGGLE_STATE*)PhysicalAddressToPtr(KeyTogglePhys);
/* Switch to real mode */
BlpArchSwitchContext(BlRealMode);
@ -938,15 +938,15 @@ EfiGetMemoryMap (
{
/* Convert all of the addresses to physical */
BlMmTranslateVirtualAddress(MemoryMapSize, &MemoryMapSizePhysical);
MemoryMapSize = (UINTN*)MemoryMapSizePhysical.LowPart;
MemoryMapSize = (UINTN*)PhysicalAddressToPtr(MemoryMapSizePhysical);
BlMmTranslateVirtualAddress(MemoryMap, &MemoryMapPhysical);
MemoryMap = (EFI_MEMORY_DESCRIPTOR*)MemoryMapPhysical.LowPart;
MemoryMap = (EFI_MEMORY_DESCRIPTOR*)PhysicalAddressToPtr(MemoryMapPhysical);
BlMmTranslateVirtualAddress(MapKey, &MapKeyPhysical);
MapKey = (UINTN*)MapKeyPhysical.LowPart;
MapKey = (UINTN*)PhysicalAddressToPtr(MapKeyPhysical);
BlMmTranslateVirtualAddress(DescriptorSize, &DescriptorSizePhysical);
DescriptorSize = (UINTN*)DescriptorSizePhysical.LowPart;
DescriptorSize = (UINTN*)PhysicalAddressToPtr(DescriptorSizePhysical);
BlMmTranslateVirtualAddress(DescriptorVersion, &DescriptorVersionPhysical);
DescriptorVersion = (UINTN*)DescriptorVersionPhysical.LowPart;
DescriptorVersion = (UINTN*)PhysicalAddressToPtr(DescriptorVersionPhysical);
/* Switch to real mode */
BlpArchSwitchContext(BlRealMode);
@ -1267,15 +1267,15 @@ EfiGopGetFrameBuffer (
{
/* Translate pointer to physical */
BlMmTranslateVirtualAddress(GopInterface, &GopInterfacePhys);
GopInterface = (PVOID)GopInterfacePhys.LowPart;
GopInterface = PhysicalAddressToPtr(GopInterfacePhys);
/* Translate pointer to physical */
BlMmTranslateVirtualAddress(FrameBuffer, &FrameBufferPhys);
FrameBuffer = (PVOID)FrameBufferPhys.LowPart;
FrameBuffer = PhysicalAddressToPtr(FrameBufferPhys);
/* Translate pointer to physical */
BlMmTranslateVirtualAddress(FrameBufferSize, &FrameBufferSizePhys);
FrameBufferSize = (PVOID)FrameBufferSizePhys.LowPart;
FrameBufferSize = PhysicalAddressToPtr(FrameBufferSizePhys);
/* Switch to real mode */
BlpArchSwitchContext(BlRealMode);
@ -1311,21 +1311,21 @@ EfiGopGetCurrentMode (
{
return STATUS_UNSUCCESSFUL;
}
GopInterface = (PVOID)GopInterfacePhys.LowPart;
GopInterface = PhysicalAddressToPtr(GopInterfacePhys);
/* Translate pointer to physical */
if (!BlMmTranslateVirtualAddress(Mode, &ModePhys))
{
return STATUS_UNSUCCESSFUL;
}
Mode = (PVOID)ModePhys.LowPart;
Mode = PhysicalAddressToPtr(ModePhys);
/* Translate pointer to physical */
if (!BlMmTranslateVirtualAddress(Information, &InformationPhys))
{
return STATUS_UNSUCCESSFUL;
}
Information = (PVOID)InformationPhys.LowPart;
Information = PhysicalAddressToPtr(InformationPhys);
/* Switch to real mode */
BlpArchSwitchContext(BlRealMode);
@ -1435,7 +1435,7 @@ EfiLocateHandleBuffer (
{
/* Translate the input buffer from virtual to physical */
TranslateResult = BlMmTranslateVirtualAddress(InputBuffer, &BufferPhys);
InputBuffer = TranslateResult ? (PVOID)BufferPhys.LowPart : NULL;
InputBuffer = TranslateResult ? PhysicalAddressToPtr(BufferPhys) : NULL;
/* Switch to real mode */
BlpArchSwitchContext(BlRealMode);
@ -1478,7 +1478,7 @@ EfiLocateHandleBuffer (
/* Translate the input buffer from virtual to physical */
TranslateResult = BlMmTranslateVirtualAddress(InputBuffer,
&BufferPhys);
InputBuffer = TranslateResult ? (PVOID)BufferPhys.LowPart : NULL;
InputBuffer = TranslateResult ? PhysicalAddressToPtr(BufferPhys) : NULL;
/* Switch to real mode */
BlpArchSwitchContext(BlRealMode);
@ -1581,7 +1581,7 @@ EfiAllocatePages (
{
/* Translate output address */
BlMmTranslateVirtualAddress(Memory, &MemoryPhysical);
Memory = (EFI_PHYSICAL_ADDRESS*)MemoryPhysical.LowPart;
Memory = (EFI_PHYSICAL_ADDRESS*)PhysicalAddressToPtr(MemoryPhysical);
/* Switch to real mode */
BlpArchSwitchContext(BlRealMode);

View file

@ -1835,7 +1835,7 @@ BlockIoEfiHashFunction (
)
{
/* Get rid of the alignment bits to have a more unique number */
return ((ULONG)Entry->Value >> 3) % TableSize;
return ((ULONG_PTR)Entry->Value >> 3) % TableSize;
}
NTSTATUS

View file

@ -61,7 +61,7 @@ DsppLoadFontFile (
{
PBL_DEVICE_DESCRIPTOR FontDevice;
NTSTATUS Status;
ULONG NameLength, DirectoryLength, TotalLength;
SIZE_T NameLength, DirectoryLength, TotalLength;
PWCHAR FontPath, FontDirectory;
BL_LIBRARY_PARAMETERS LibraryParameters;
BOOLEAN CustomDirectory, CustomDevice;
@ -114,21 +114,21 @@ DsppLoadFontFile (
DirectoryLength = wcslen(FontDirectory);
/* Safely add them up*/
Status = RtlULongAdd(NameLength, DirectoryLength, &TotalLength);
Status = RtlSIZETAdd(NameLength, DirectoryLength, &TotalLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;
}
/* Convert to bytes */
Status = RtlULongLongToULong(TotalLength * sizeof(WCHAR), &TotalLength);
Status = RtlSIZETMult(TotalLength, sizeof(WCHAR), &TotalLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;
}
/* Add a terminating NUL */
Status = RtlULongAdd(TotalLength, sizeof(UNICODE_NULL), &TotalLength);
Status = RtlSIZETAdd(TotalLength, sizeof(UNICODE_NULL), &TotalLength);
if (!NT_SUCCESS(Status))
{
goto Quickie;

View file

@ -547,7 +547,8 @@ EtfsOpen (
PBL_FILE_ENTRY NewFile;
PWCHAR FilePath, FormatString;
PBL_ETFS_FILE EtfsFile;
ULONG DeviceId, FileSize, DirOffset, FileOffset, Size;
ULONG DeviceId, FileSize, DirOffset, FileOffset;
SIZE_T Size;
PRAW_DIR_REC DirEntry;
BOOLEAN IsDirectory;

View file

@ -41,7 +41,7 @@ FileIoCopyParentDirectoryPath (
_In_ PWCHAR FilePath
)
{
ULONG PathSize, PathSizeWithNull;
SIZE_T PathSize, PathSizeWithNull;
PWCHAR Backslash, ParentCopy;
PathSize = wcslen(FilePath) * sizeof(WCHAR);
@ -81,7 +81,7 @@ FileIoCopyFileName (
)
{
PWCHAR Separator, FileCopy;
ULONG PathSize;
SIZE_T PathSize;
Separator = wcsrchr(FilePath, '\\');
if (!Separator)

View file

@ -59,7 +59,7 @@ BiConvertRegistryDataToElement (
)
{
NTSTATUS Status;
ULONG Length, Size, ReturnedLength;
SIZE_T Length, Size, ReturnedLength;
PBL_DEVICE_DESCRIPTOR Device;
BOOLEAN NullTerminate;
PBCD_DEVICE_OPTION BcdDevice, ElementDevice;

View file

@ -192,7 +192,7 @@ BiOpenKey(
PBI_KEY_OBJECT ParentKey, NewKey;
PBI_KEY_HIVE ParentHive;
NTSTATUS Status;
ULONG NameLength, SubNameLength, NameBytes;
SIZE_T NameLength, SubNameLength, NameBytes;
PWCHAR NameStart, NameBuffer;
UNICODE_STRING KeyString;
HCELL_INDEX KeyCell;

View file

@ -54,7 +54,7 @@ BfLoadFontFile (
)
{
PBL_DEFERRED_FONT_FILE DeferredFont;
ULONG FontPathSize;
SIZE_T FontPathSize;
/* Allocate the deferred font structure */
DeferredFont = (PBL_DEFERRED_FONT_FILE)BlMmAllocateHeap(sizeof(*DeferredFont));

View file

@ -304,7 +304,7 @@ BlImgAllocateImageBuffer (
}
/* Now map the physical buffer at the address requested */
MappedBase = (PVOID)PhysicalAddress.LowPart;
MappedBase = PhysicalAddressToPtr(PhysicalAddress);
Status = BlMmMapPhysicalAddressEx(&MappedBase,
BlMemoryFixed,
Size,
@ -976,9 +976,9 @@ ImgpLoadPEImage (
}
/* Make sure that the section doesn't overflow in memory */
Status = RtlULongAdd(Section->VirtualAddress,
SectionSize,
&SectionEnd);
Status = RtlULongPtrAdd(Section->VirtualAddress,
SectionSize,
&SectionEnd);
if (!NT_SUCCESS(Status))
{
EfiPrintf(L"fail 21\r\n");
@ -994,9 +994,9 @@ ImgpLoadPEImage (
}
/* Make sure it doesn't overflow on disk */
Status = RtlULongAdd(Section->VirtualAddress,
AlignSize,
&SectionEnd);
Status = RtlULongPtrAdd(Section->VirtualAddress,
AlignSize,
&SectionEnd);
if (!NT_SUCCESS(Status))
{
EfiPrintf(L"fail 31\r\n");
@ -1848,7 +1848,7 @@ ImgArchEfiStartBootApplication (
__sidt(&Idt.Limit);
/* Allocate space for the IDT, GDT, and 24 pages of stack */
BootSizeNeeded = (ULONG)PAGE_ALIGN(Idt.Limit + Gdt.Limit + 1 + 25 * PAGE_SIZE);
BootSizeNeeded = (ULONG_PTR)PAGE_ALIGN(Idt.Limit + Gdt.Limit + 1 + 25 * PAGE_SIZE);
Status = MmPapAllocatePagesInRange(&BootData,
BlLoaderArchData,
BootSizeNeeded >> PAGE_SHIFT,

View file

@ -23,7 +23,11 @@ CHECK_PAGED_CODE_RTL (
}
#endif
#ifdef _WIN64
PVOID MmHighestUserAddress = (PVOID)0xFFFFFFFFULL; // CHECKME
#else
PVOID MmHighestUserAddress = (PVOID)0xFFFFFFFF;
#endif
PVOID
NTAPI

View file

@ -960,6 +960,7 @@ BlArchGetCpuVendor (
{
return CPU_VIA;
}
#ifdef _M_IX86
if (!strncmp((PCHAR)&CpuInfo.Ebx, "CyrixInstead", 12))
{
return CPU_CYRIX;
@ -972,7 +973,7 @@ BlArchGetCpuVendor (
{
return CPU_RISE;
}
#endif // _M_IX86
/* Other */
return CPU_UNKNOWN;
}

View file

@ -48,7 +48,7 @@ MmBapCompareBlockAllocatorTableEntry (
)
{
PBL_BLOCK_DESCRIPTOR BlockInfo = (PBL_BLOCK_DESCRIPTOR)Entry;
ULONG BlockId = (ULONG)Argument1;
ULONG BlockId = PtrToUlong(Argument1);
/* Check if the block ID matches */
return BlockInfo->BlockId == BlockId;
@ -67,7 +67,7 @@ MmBapFindBlockInformation (
MmBlockAllocatorTableEntries,
&EntryId,
MmBapCompareBlockAllocatorTableEntry,
(PVOID)EntryId,
UlongToPtr(EntryId),
NULL,
NULL,
NULL);

View file

@ -567,7 +567,7 @@ MmHaInitialize (
PVOID
BlMmAllocateHeap (
_In_ ULONG Size
_In_ SIZE_T Size
)
{
ULONG BufferSize;
@ -581,8 +581,8 @@ BlMmAllocateHeap (
}
/* Align the buffer size to the minimum size required */
BufferSize = ALIGN_UP(Size + FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer),
FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer));
BufferSize = ALIGN_UP_BY(Size + FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer),
FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer));
/* Watch out for overflow */
if (BufferSize <= Size)

View file

@ -865,7 +865,7 @@ MmPapAllocatePagesInRange (
Type);
/* Return the allocated address */
*PhysicalAddress = (PVOID)BaseAddress.LowPart;
*PhysicalAddress = PhysicalAddressToPtr(BaseAddress);
}
Exit:
@ -1639,7 +1639,7 @@ MmSelectMappingAddress (
if (MmTranslationType == BlNone)
{
/* Just return the physical address as the mapping address */
PreferredAddress = (PVOID)PhysicalAddress.LowPart;
PreferredAddress = PhysicalAddressToPtr(PhysicalAddress);
goto Success;
}