[FREELDR]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 23 Sep 2011 17:35:45 +0000 (17:35 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 23 Sep 2011 17:35:45 +0000 (17:35 +0000)
commit5f22a73516bcdd60c8361164a73ae3eac999874c
tree3b6d51198d94a636aeccbbf9f87996c591d6d4ed
parent184aeeeeefc4fd2e3a6eb4884c65bda3823bfc04
[FREELDR]
Fix some bugs in the code that deals with memory descriptors:
ArcGetMemoryDescriptor was enumerating the bios generated entries first and then the static entries. The latter were conflicting with the former and took precedence when initializing the page lookup table. The problem was, that MmFindLocationForPageLookupTable would use the highest range of pages available. If that range would be conflicting with a following static descriptor, the static would have been ignored. It only worked because on x86 the highest bios descriptor has enough free pages, before it conflicts with a static entry (page 0xfff, marked as unusable), so that the page lookup table could be created.

MmGetAddressablePageCountIncludingHoles enumerated all memory descriptors to find MmLowestPhysicalPage, but it was only counting FreeMemory, thus skipping all other memory ranges. This only worked, due to the previous bug, so that the bios pages shown first took precedence over the following static descriptors. Without the former bug MmLowestPhysicalPage would be 0x100 which would tigger in the next bug:
MmAreMemoryPagesAvailable took the passed address range and looked up all pages in the lookup table to see whether all are free. Now the function didn't check, whether the passed address was below MmLowestPhysicalPage and in case it was, happily accessed the memory below the lookup table. This would result in hal being loaded at 0x40000 overwriting the loader itself.

This is all fixe by implementing a new way of creating the memory map. First there is a static memory map, which has enough free entries to add dynamic ranges. Then AddMemoryDescriptor will allow you to add a new range,
while the already existing ranges will take precedence and the new ranges will be properly split and inserted, so that the resulting map does not contain any overlapping regions and is sorted from low to high pages. The static memory descriptor exists in the architecture specific file.
The code that enumerates the bios information now uses this function to add the ranges on top of the static descriptor.
More cleanup work to follow.

svn path=/trunk/; revision=53816
reactos/boot/freeldr/freeldr/arch/arm/macharm.c
reactos/boot/freeldr/freeldr/arch/i386/pcmem.c
reactos/boot/freeldr/freeldr/arch/i386/xboxmem.c
reactos/boot/freeldr/freeldr/debug.c
reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h
reactos/boot/freeldr/freeldr/include/arch/pc/machpc.h
reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h
reactos/boot/freeldr/freeldr/include/machine.h
reactos/boot/freeldr/freeldr/mm/meminit.c