Always return an aligned block when mapping memory.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2185 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -313,18 +313,28 @@ MapMemory (
|
|||||||
INTN prot,
|
INTN prot,
|
||||||
INTN flags)
|
INTN flags)
|
||||||
{
|
{
|
||||||
static UINTN base = 0x40000000;
|
STATIC UINTN base = 0x40000000;
|
||||||
const UINTN align = (1 << 24);
|
CONST UINTN align = (1 << 24);
|
||||||
void *res;
|
VOID *res;
|
||||||
|
BOOLEAN isAligned = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try to get an aligned block somewhere in the address space of this
|
||||||
|
// process.
|
||||||
|
//
|
||||||
|
while((!isAligned) && (base != 0)) {
|
||||||
res = mmap ((void *)base, length, prot, flags, fd, 0);
|
res = mmap ((void *)base, length, prot, flags, fd, 0);
|
||||||
if (res == MAP_FAILED)
|
if (res == MAP_FAILED) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
// Guard page.
|
if ((((UINTN)res) & ~(align-1)) == (UINTN)res) {
|
||||||
base += length + 4096;
|
isAligned=1;
|
||||||
base = (base + align - 1) & ~(align - 1);
|
}
|
||||||
|
else {
|
||||||
|
munmap(res, length);
|
||||||
|
base += align;
|
||||||
|
}
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user