diff mbox series

[v3,1/3] bsd-user: Always use mmap_find_vma_aligned() in target_mmap()

Message ID 20250307130951.4816-2-philmd@linaro.org
State Superseded
Headers show
Series user: Extract common MMAP API to 'user/mmap.h' | expand

Commit Message

Philippe Mathieu-Daudé March 7, 2025, 1:09 p.m. UTC
Massage target_mmap(): calculate alignment once, then
unconditionally call mmap_find_vma_aligned().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 bsd-user/mmap.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Richard Henderson March 7, 2025, 4:03 p.m. UTC | #1
On 3/7/25 05:09, Philippe Mathieu-Daudé wrote:
> Massage target_mmap(): calculate alignment once, then
> unconditionally call mmap_find_vma_aligned().
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   bsd-user/mmap.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
> index 346f2cefd32..28d7e387a20 100644
> --- a/bsd-user/mmap.c
> +++ b/bsd-user/mmap.c
> @@ -489,13 +489,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
>        * before we truncate the length for mapping files below.
>        */
>       if (!(flags & MAP_FIXED)) {
> +        abi_ulong alignment = 0;
> +
>           host_len = len + offset - host_offset;
>           host_len = HOST_PAGE_ALIGN(host_len);
> -        if ((flags & MAP_ALIGNMENT_MASK) != 0)
> -            start = mmap_find_vma_aligned(real_start, host_len,
> -                (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT);
> -        else
> -            start = mmap_find_vma(real_start, host_len);
> +        if ((flags & MAP_ALIGNMENT_MASK) != 0) {
> +            alignment = (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT;
> +        }

No need for the if -- (0 & mask) >> shift == 0.

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Warner Losh March 9, 2025, 11:21 p.m. UTC | #2
On Fri, Mar 7, 2025 at 6:09 AM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:

> Massage target_mmap(): calculate alignment once, then
> unconditionally call mmap_find_vma_aligned().
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  bsd-user/mmap.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>
diff mbox series

Patch

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 346f2cefd32..28d7e387a20 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -489,13 +489,14 @@  abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
      * before we truncate the length for mapping files below.
      */
     if (!(flags & MAP_FIXED)) {
+        abi_ulong alignment = 0;
+
         host_len = len + offset - host_offset;
         host_len = HOST_PAGE_ALIGN(host_len);
-        if ((flags & MAP_ALIGNMENT_MASK) != 0)
-            start = mmap_find_vma_aligned(real_start, host_len,
-                (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT);
-        else
-            start = mmap_find_vma(real_start, host_len);
+        if ((flags & MAP_ALIGNMENT_MASK) != 0) {
+            alignment = (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT;
+        }
+        start = mmap_find_vma_aligned(real_start, host_len, alignment);
         if (start == (abi_ulong)-1) {
             errno = ENOMEM;
             goto fail;