aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2023-07-07 21:40:39 +0100
committerRichard Henderson <richard.henderson@linaro.org>2023-07-15 08:02:32 +0100
commit037986053b063866b029733d9508635d31b3f987 (patch)
tree3e6c3abb9e95e2897f578fdc0391c0ab5ad4e92b
parent9c255cb53e44d5db57b3388fd6dfab96d4883790 (diff)
downloadqemu-037986053b063866b029733d9508635d31b3f987.zip
qemu-037986053b063866b029733d9508635d31b3f987.tar.gz
qemu-037986053b063866b029733d9508635d31b3f987.tar.bz2
linux-user: Implement MAP_FIXED_NOREPLACE
Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20230707204054.8792-12-richard.henderson@linaro.org>
-rw-r--r--linux-user/mmap.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 639921d..9dc34fc 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -509,7 +509,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
* If the user is asking for the kernel to find a location, do that
* before we truncate the length for mapping files below.
*/
- if (!(flags & MAP_FIXED)) {
+ if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
host_len = len + offset - host_offset;
host_len = HOST_PAGE_ALIGN(host_len);
start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE);
@@ -551,7 +551,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
}
}
- if (!(flags & MAP_FIXED)) {
+ if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
unsigned long host_start;
void *p;
@@ -600,6 +600,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
goto fail;
}
+ /* Validate that the chosen range is empty. */
+ if ((flags & MAP_FIXED_NOREPLACE)
+ && !page_check_range_empty(start, end - 1)) {
+ errno = EEXIST;
+ goto fail;
+ }
+
/*
* worst case: we cannot map the file because the offset is not
* aligned, so we read it
@@ -615,7 +622,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
goto fail;
}
retaddr = target_mmap(start, len, target_prot | PROT_WRITE,
- MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
+ (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))
+ | MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (retaddr == -1) {
goto fail;