diff options
author | Cao jin <caoj.fnst@cn.fujitsu.com> | 2016-11-02 21:44:47 +0800 |
---|---|---|
committer | Michael Tokarev <mjt@tls.msk.ru> | 2017-01-24 23:26:53 +0300 |
commit | 6e4c890e15b23f078650499fbde11760b8eccf10 (patch) | |
tree | 0c606e5587a6c6a59b10d297e19ef9f5ca48f6a8 /util/mmap-alloc.c | |
parent | 4a3ecf201a1a49a804e8506df5906e446707c3b1 (diff) | |
download | qemu-6e4c890e15b23f078650499fbde11760b8eccf10.zip qemu-6e4c890e15b23f078650499fbde11760b8eccf10.tar.gz qemu-6e4c890e15b23f078650499fbde11760b8eccf10.tar.bz2 |
util/mmap-alloc: refactor a little bit for readability
1st mmap returns *ptr* which aligns to host page size,
| size + align |
------------------------------------------
ptr
input param *align* could be 1M, or 2M, or host page size. After
QEMU_ALIGN_UP, offset will >= 0
2nd mmap use flag MAP_FIXED, then it return ptr+offset, or else fail.
If it success, then we will have something like:
| offset | size |
--------------------------------------
ptr ptr1
*ptr1* is what we really want to return, it equals ptr+offset.
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'util/mmap-alloc.c')
-rw-r--r-- | util/mmap-alloc.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index d713a72..2f55f5e 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -84,22 +84,20 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) return MAP_FAILED; } - ptr += offset; - total -= offset; - if (offset > 0) { - munmap(ptr - offset, offset); + munmap(ptr, offset); } /* * Leave a single PROT_NONE page allocated after the RAM block, to serve as * a guard page guarding against potential buffer overflows. */ + total -= offset; if (total > size + getpagesize()) { - munmap(ptr + size + getpagesize(), total - size - getpagesize()); + munmap(ptr1 + size + getpagesize(), total - size - getpagesize()); } - return ptr; + return ptr1; } void qemu_ram_munmap(void *ptr, size_t size) |