[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 3/8] linux-user: Use MAP_FIXED_NOREPLACE for do_brk()
From: |
Helge Deller |
Subject: |
[PATCH v6 3/8] linux-user: Use MAP_FIXED_NOREPLACE for do_brk() |
Date: |
Wed, 2 Aug 2023 01:27:40 +0200 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
MAP_FIXED_NOREPLACE can ensure the mapped address is fixed without
concerning that the new mapping overwrites something else.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Helge Deller <deller@gmx.de>
Signed-off-by: Helge Deller <deller@gmx.de>
---
linux-user/syscall.c | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b9d2ec02f9..ac429a185a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -854,17 +854,12 @@ abi_long do_brk(abi_ulong brk_val)
return target_brk;
}
- /* We need to allocate more memory after the brk... Note that
- * we don't use MAP_FIXED because that will map over the top of
- * any existing mapping (like the one with the host libc or qemu
- * itself); instead we treat "mapped but at wrong address" as
- * a failure and unmap again.
- */
if (new_host_brk_page > brk_page) {
new_alloc_size = new_host_brk_page - brk_page;
mapped_addr = target_mmap(brk_page, new_alloc_size,
- PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_PRIVATE, 0, 0);
+ PROT_READ | PROT_WRITE,
+ MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE,
+ 0, 0);
} else {
new_alloc_size = 0;
mapped_addr = brk_page;
@@ -883,12 +878,6 @@ abi_long do_brk(abi_ulong brk_val)
target_brk = brk_val;
brk_page = new_host_brk_page;
return target_brk;
- } else if (mapped_addr != -1) {
- /* Mapped but at wrong address, meaning there wasn't actually
- * enough space for this brk.
- */
- target_munmap(mapped_addr, new_alloc_size);
- mapped_addr = -1;
}
#if defined(TARGET_ALPHA)
--
2.41.0
- Re: [PATCH v6 8/8] linux-user: Load pie executables at upper memory, (continued)
- Re: [PATCH v6 8/8] linux-user: Load pie executables at upper memory, Helge Deller, 2023/08/02
- Re: [PATCH v6 8/8] linux-user: Load pie executables at upper memory, Akihiko Odaki, 2023/08/02
- Re: [PATCH v6 8/8] linux-user: Load pie executables at upper memory, Helge Deller, 2023/08/02
- Re: [PATCH v6 8/8] linux-user: Load pie executables at upper memory, Akihiko Odaki, 2023/08/02
- Re: [PATCH v6 8/8] linux-user: Load pie executables at upper memory, Helge Deller, 2023/08/02
Re: [PATCH v6 8/8] linux-user: Load pie executables at upper memory, Richard Henderson, 2023/08/02
[PATCH v6 6/8] linux-user: Show heap address in /proc/pid/maps, Helge Deller, 2023/08/01
[PATCH v6 3/8] linux-user: Use MAP_FIXED_NOREPLACE for do_brk(),
Helge Deller <=
Re: [PATCH v6 0/8] linux-user: brk fixes, Joel Stanley, 2023/08/01