diff options
author | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-01-07 19:09:33 +0000 |
---|---|---|
committer | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-01-07 19:09:33 +0000 |
commit | 6bb60d710b3e041221582400390eca5977cd9aca (patch) | |
tree | 423bce5ae25e03cdd812cc78401c83b7af5f17ea /EdkUnixPkg | |
parent | a53078b6346ebecf6fa39aa93e6500c5be500a2a (diff) | |
download | edk2-platforms-6bb60d710b3e041221582400390eca5977cd9aca.tar.xz |
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
Diffstat (limited to 'EdkUnixPkg')
-rw-r--r-- | EdkUnixPkg/Sec/SecMain.c | 32 |
1 files changed, 21 insertions, 11 deletions
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; } |