X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkUnixPkg%2FSec%2FSecMain.c;h=32793f7c645e8644c7c03b10fb605a3305c507d9;hp=b2234c49a92fce7fcda3cd0ebc124d76b70817a9;hb=6bb60d710b3e041221582400390eca5977cd9aca;hpb=c9093a06e72ef16d2f3bd7ce0a2b9a172e9d048c diff --git a/EdkUnixPkg/Sec/SecMain.c b/EdkUnixPkg/Sec/SecMain.c index b2234c49a9..32793f7c64 100644 --- a/EdkUnixPkg/Sec/SecMain.c +++ b/EdkUnixPkg/Sec/SecMain.c @@ -313,18 +313,28 @@ MapMemory ( INTN prot, INTN flags) { - static UINTN base = 0x40000000; - const UINTN align = (1 << 24); - void *res; - - res = mmap ((void *)base, length, prot, flags, fd, 0); - if (res == MAP_FAILED) - return NULL; - - // Guard page. - base += length + 4096; - base = (base + align - 1) & ~(align - 1); + STATIC UINTN base = 0x40000000; + CONST UINTN align = (1 << 24); + 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); + if (res == MAP_FAILED) { + return NULL; + } + if ((((UINTN)res) & ~(align-1)) == (UINTN)res) { + isAligned=1; + } + else { + munmap(res, length); + base += align; + } + } return res; }