diff mbox series

[22/22] Add stubs for vadvise(), sbrk() and sstk()

Message ID 20230819094806.14965-23-kariem.taha2.7@gmail.com
State New
Headers show
Series Implement the mmap system call for FreeBSD. | expand

Commit Message

Karim Taha Aug. 19, 2023, 9:48 a.m. UTC
From: Stacey Son <sson@FreeBSD.org>

The above system calls are not supported by qemu.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
 bsd-user/bsd-mem.h            | 21 +++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
 2 files changed, 33 insertions(+)

Comments

Warner Losh Aug. 20, 2023, 4:45 a.m. UTC | #1
On Sat, Aug 19, 2023 at 3:49 AM Karim Taha <kariem.taha2.7@gmail.com> wrote:

> From: Stacey Son <sson@FreeBSD.org>
>
> The above system calls are not supported by qemu.
>
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
> ---
>  bsd-user/bsd-mem.h            | 21 +++++++++++++++++++++
>  bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
>  2 files changed, 33 insertions(+)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>
Richard Henderson Aug. 20, 2023, 3:35 p.m. UTC | #2
On 8/19/23 02:48, Karim Taha wrote:
> From: Stacey Son <sson@FreeBSD.org>
> 
> The above system calls are not supported by qemu.
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
> ---
>   bsd-user/bsd-mem.h            | 21 +++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
>   2 files changed, 33 insertions(+)
> 
> diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
> index f737b94885..274178bef7 100644
> --- a/bsd-user/bsd-mem.h
> +++ b/bsd-user/bsd-mem.h
> @@ -407,4 +407,25 @@ static inline abi_long do_bsd_shmdt(abi_ulong shmaddr)
>       return get_errno(shmdt(g2h_untagged(shmaddr)));
>   }
>   
> +static inline abi_long do_bsd_vadvise(void)
> +{
> +    /* See sys_ovadvise() in vm_unix.c */
> +    qemu_log("qemu: Unsupported syscall vadvise()\n");
> +    return -TARGET_ENOSYS;
> +}

I see EINVAL not ENOSYS.

> +static inline abi_long do_bsd_sbrk(void)
> +{
> +    /* see sys_sbrk() in vm_mmap.c */
> +    qemu_log("qemu: Unsupported syscall sbrk()\n");
> +    return -TARGET_ENOSYS;
> +}
> +
> +static inline abi_long do_bsd_sstk(void)
> +{
> +    /* see sys_sstk() in vm_mmap.c */
> +    qemu_log("qemu: Unsupported syscall sstk()\n");
> +    return -TARGET_ENOSYS;
> +}

I see EOPNOTSUPP not ENOSYS.

I don't see any point in logging these.


r~
Warner Losh Aug. 20, 2023, 8:42 p.m. UTC | #3
On Sun, Aug 20, 2023 at 9:35 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 8/19/23 02:48, Karim Taha wrote:
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > The above system calls are not supported by qemu.
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
> > ---
> >   bsd-user/bsd-mem.h            | 21 +++++++++++++++++++++
> >   bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
> >   2 files changed, 33 insertions(+)
> >
> > diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
> > index f737b94885..274178bef7 100644
> > --- a/bsd-user/bsd-mem.h
> > +++ b/bsd-user/bsd-mem.h
> > @@ -407,4 +407,25 @@ static inline abi_long do_bsd_shmdt(abi_ulong
> shmaddr)
> >       return get_errno(shmdt(g2h_untagged(shmaddr)));
> >   }
> >
> > +static inline abi_long do_bsd_vadvise(void)
> > +{
> > +    /* See sys_ovadvise() in vm_unix.c */
> > +    qemu_log("qemu: Unsupported syscall vadvise()\n");
> > +    return -TARGET_ENOSYS;
> > +}
>
> I see EINVAL not ENOSYS.
>

When the system call isn't present at all, it's ENOSYS + SIGSYS (I have
patches to implement this
that developers love, but users hate it since many programs cope OK when an
error is returned for
obscure system calls). When it is present, it's implemented as EINVAL. So
maybe the right thing
here is to remove the log and just return EINVAL for the implementation.


> > +static inline abi_long do_bsd_sbrk(void)
> > +{
> > +    /* see sys_sbrk() in vm_mmap.c */
> > +    qemu_log("qemu: Unsupported syscall sbrk()\n");
> > +    return -TARGET_ENOSYS;
> > +}
> > +
> > +static inline abi_long do_bsd_sstk(void)
> > +{
> > +    /* see sys_sstk() in vm_mmap.c */
> > +    qemu_log("qemu: Unsupported syscall sstk()\n");
> > +    return -TARGET_ENOSYS;
> > +}
>
> I see EOPNOTSUPP not ENOSYS.
>

Same comment as above: we should just return EOPNOSUPP and call it
implemented.


> I don't see any point in logging these.
>

Yea, that's a general pattern that we have upstream, but there's a
catch-all 'default' case that does
the logging with the right mask.

Warner
diff mbox series

Patch

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index f737b94885..274178bef7 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -407,4 +407,25 @@  static inline abi_long do_bsd_shmdt(abi_ulong shmaddr)
     return get_errno(shmdt(g2h_untagged(shmaddr)));
 }
 
+static inline abi_long do_bsd_vadvise(void)
+{
+    /* See sys_ovadvise() in vm_unix.c */
+    qemu_log("qemu: Unsupported syscall vadvise()\n");
+    return -TARGET_ENOSYS;
+}
+
+static inline abi_long do_bsd_sbrk(void)
+{
+    /* see sys_sbrk() in vm_mmap.c */
+    qemu_log("qemu: Unsupported syscall sbrk()\n");
+    return -TARGET_ENOSYS;
+}
+
+static inline abi_long do_bsd_sstk(void)
+{
+    /* see sys_sstk() in vm_mmap.c */
+    qemu_log("qemu: Unsupported syscall sstk()\n");
+    return -TARGET_ENOSYS;
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index f76bc1eb38..cf4b894fee 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -567,6 +567,18 @@  static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_shmdt(arg1);
         break;
 
+    case TARGET_FREEBSD_NR_freebsd11_vadvise:
+        ret = do_bsd_vadvise();
+        break;
+
+    case TARGET_FREEBSD_NR_sbrk:
+        ret = do_bsd_sbrk();
+        break;
+
+    case TARGET_FREEBSD_NR_sstk:
+        ret = do_bsd_sstk();
+        break;
+
         /*
          * Misc
          */