1
0
Fork 0
mirror of https://github.com/yuzu-emu/unicorn.git synced 2025-04-01 23:07:03 +00:00

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.

Backports commit 6e4c890e15b23f078650499fbde11760b8eccf10 from qemu
This commit is contained in:
Cao jin 2018-03-01 23:55:13 -05:00 committed by Lioncash
parent 217c14ad3e
commit f2a5ddf5dc
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -60,22 +60,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)