diff mbox series

[02/16] bsd-user: Ifdef a few MAP_ constants for NetBSD

Message ID 20230405213612.15942-3-imp@bsdimp.com (mailing list archive)
State New, archived
Headers show
Series bsd-user 2023 Q2 first batch | expand

Commit Message

Warner Losh April 5, 2023, 9:35 p.m. UTC
MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Add back the
ifdefs that I removed in 36d5d891559f (but only these ifdefs, the
rest of the commit is not reverted).

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/mmap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Richard Henderson April 8, 2023, 7:03 p.m. UTC | #1
On 4/5/23 14:35, Warner Losh wrote:
> MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Add back the
> ifdefs that I removed in 36d5d891559f (but only these ifdefs, the
> rest of the commit is not reverted).
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/mmap.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
> index d6c5a344c9b..f732a6f6f2b 100644
> --- a/bsd-user/mmap.c
> +++ b/bsd-user/mmap.c
> @@ -416,27 +416,33 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
>               qemu_log("MAP_ALIGNED(%u) ",
>                        (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT);
>           }
> +#ifdef MAP_GUARD
>           if (flags & MAP_GUARD) {
>               qemu_log("MAP_GUARD ");
>           }
> +#endif

Maybe better as

#ifndef MAP_GUARD
#define MAP_GUARD 0
#endif

etc, somewhere common, and let the compiler eliminate the always false conditions.


r~
Warner Losh April 8, 2023, 7:29 p.m. UTC | #2
On Sat, Apr 8, 2023 at 1:03 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 4/5/23 14:35, Warner Losh wrote:
> > MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Add back the
> > ifdefs that I removed in 36d5d891559f (but only these ifdefs, the
> > rest of the commit is not reverted).
> >
> > Signed-off-by: Warner Losh<imp@bsdimp.com>
> > ---
> >   bsd-user/mmap.c | 10 ++++++++++
> >   1 file changed, 10 insertions(+)
> >
> > diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
> > index d6c5a344c9b..f732a6f6f2b 100644
> > --- a/bsd-user/mmap.c
> > +++ b/bsd-user/mmap.c
> > @@ -416,27 +416,33 @@ abi_long target_mmap(abi_ulong start, abi_ulong
> len, int prot,
> >               qemu_log("MAP_ALIGNED(%u) ",
> >                        (flags & MAP_ALIGNMENT_MASK) >>
> MAP_ALIGNMENT_SHIFT);
> >           }
> > +#ifdef MAP_GUARD
> >           if (flags & MAP_GUARD) {
> >               qemu_log("MAP_GUARD ");
> >           }
> > +#endif
>
> Maybe better as
>
> #ifndef MAP_GUARD
> #define MAP_GUARD 0
> #endif
>
> etc, somewhere common, and let the compiler eliminate the always false
> conditions.
>

Interesting notion...  I can do that in syscall_defs.h. If that's the
pattern in qemu I'll
do it here.... but I've been burned in the past by warnings about always
true or always
false conditions...  It would be less invasive though...

Warner
diff mbox series

Patch

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index d6c5a344c9b..f732a6f6f2b 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -416,27 +416,33 @@  abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             qemu_log("MAP_ALIGNED(%u) ",
                      (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT);
         }
+#ifdef MAP_GUARD
         if (flags & MAP_GUARD) {
             qemu_log("MAP_GUARD ");
         }
+#endif
         if (flags & MAP_FIXED) {
             qemu_log("MAP_FIXED ");
         }
         if (flags & MAP_ANON) {
             qemu_log("MAP_ANON ");
         }
+#ifdef MAP_EXCL
         if (flags & MAP_EXCL) {
             qemu_log("MAP_EXCL ");
         }
+#endif
         if (flags & MAP_PRIVATE) {
             qemu_log("MAP_PRIVATE ");
         }
         if (flags & MAP_SHARED) {
             qemu_log("MAP_SHARED ");
         }
+#ifdef MAP_NOCORE
         if (flags & MAP_NOCORE) {
             qemu_log("MAP_NOCORE ");
         }
+#endif
         if (flags & MAP_STACK) {
             qemu_log("MAP_STACK ");
         }
@@ -454,6 +460,7 @@  abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             goto fail;
         }
     }
+#ifdef MAP_GUARD
     if ((flags & MAP_GUARD) && (prot != PROT_NONE || fd != -1 ||
         offset != 0 || (flags & (MAP_SHARED | MAP_PRIVATE |
         /* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */
@@ -461,6 +468,7 @@  abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
         errno = EINVAL;
         goto fail;
     }
+#endif
 
     if (offset & ~TARGET_PAGE_MASK) {
         errno = EINVAL;
@@ -608,11 +616,13 @@  abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             goto the_end;
         }
 
+#ifdef MAP_EXCL
         /* Reject the mapping if any page within the range is mapped */
         if ((flags & MAP_EXCL) && page_check_range(start, len, 0) < 0) {
             errno = EINVAL;
             goto fail;
         }
+#endif
 
         /* handle the start of the mapping */
         if (start > real_start) {