diff mbox series

[for-9.1] linux-user: Preserve NULL hit in target_mmap subroutines

Message ID 20240813094654.306430-1-richard.henderson@linaro.org
State New
Headers show
Series [for-9.1] linux-user: Preserve NULL hit in target_mmap subroutines | expand

Commit Message

Richard Henderson Aug. 13, 2024, 9:46 a.m. UTC
Do not pass guest_base to the host mmap instead of zero hint.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2353
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/mmap.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 13, 2024, 10:38 a.m. UTC | #1
On 13/8/24 11:46, Richard Henderson wrote:
> Do not pass guest_base to the host mmap instead of zero hint.
> 
> Cc: qemu-stable@nongnu.org
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2353
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   linux-user/mmap.c | 18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index 4d09a72fad..6418e811f6 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -560,9 +560,13 @@ static abi_long mmap_h_eq_g(abi_ulong start, abi_ulong len,
>                               int host_prot, int flags, int page_flags,
>                               int fd, off_t offset)
>   {
> -    void *p, *want_p = g2h_untagged(start);
> +    void *p, *want_p = NULL;
>       abi_ulong last;
>   
> +    if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
> +        want_p = g2h_untagged(start);
> +    }
> +
>       p = mmap(want_p, len, host_prot, flags, fd, offset);
>       if (p == MAP_FAILED) {
>           return -1;
> @@ -610,11 +614,15 @@ static abi_long mmap_h_lt_g(abi_ulong start, abi_ulong len, int host_prot,
>                               int mmap_flags, int page_flags, int fd,
>                               off_t offset, int host_page_size)
>   {
> -    void *p, *want_p = g2h_untagged(start);
 > +    void *p, *want_p = NULL;

Maybe extract as static helper?

       void *p, *want_p = g2h_untagged_FOO(start, flags);

>       off_t fileend_adj = 0;
>       int flags = mmap_flags;
>       abi_ulong last, pass_last;
>   
> +    if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
> +        want_p = g2h_untagged(start);
> +    }

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 4d09a72fad..6418e811f6 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -560,9 +560,13 @@  static abi_long mmap_h_eq_g(abi_ulong start, abi_ulong len,
                             int host_prot, int flags, int page_flags,
                             int fd, off_t offset)
 {
-    void *p, *want_p = g2h_untagged(start);
+    void *p, *want_p = NULL;
     abi_ulong last;
 
+    if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
+        want_p = g2h_untagged(start);
+    }
+
     p = mmap(want_p, len, host_prot, flags, fd, offset);
     if (p == MAP_FAILED) {
         return -1;
@@ -610,11 +614,15 @@  static abi_long mmap_h_lt_g(abi_ulong start, abi_ulong len, int host_prot,
                             int mmap_flags, int page_flags, int fd,
                             off_t offset, int host_page_size)
 {
-    void *p, *want_p = g2h_untagged(start);
+    void *p, *want_p = NULL;
     off_t fileend_adj = 0;
     int flags = mmap_flags;
     abi_ulong last, pass_last;
 
+    if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
+        want_p = g2h_untagged(start);
+    }
+
     if (!(flags & MAP_ANONYMOUS)) {
         struct stat sb;
 
@@ -740,12 +748,16 @@  static abi_long mmap_h_gt_g(abi_ulong start, abi_ulong len,
                             int flags, int page_flags, int fd,
                             off_t offset, int host_page_size)
 {
-    void *p, *want_p = g2h_untagged(start);
+    void *p, *want_p = NULL;
     off_t host_offset = offset & -host_page_size;
     abi_ulong last, real_start, real_last;
     bool misaligned_offset = false;
     size_t host_len;
 
+    if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
+        want_p = g2h_untagged(start);
+    }
+
     if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
         /*
          * Adjust the offset to something representable on the host.