diff mbox

user-exec.c: fix build on NetBSD/sparc64 and NetBSD/arm

Message ID 1425591461-17550-1-git-send-email-tnn@NetBSD.org
State New
Headers show

Commit Message

Tobias Nygren March 5, 2015, 9:37 p.m. UTC
A couple of #ifdef changes necessary to use NetBSD's ucontext
structs on sparc64 and arm.

Signed-off-by: Tobias Nygren <tnn@NetBSD.org>
---
 user-exec.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Peter Maydell March 8, 2015, 10:27 a.m. UTC | #1
On 6 March 2015 at 06:37, Tobias Nygren <tnn@netbsd.org> wrote:
> A couple of #ifdef changes necessary to use NetBSD's ucontext
> structs on sparc64 and arm.
>
> Signed-off-by: Tobias Nygren <tnn@NetBSD.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

Does NetBSD have a big stack of out-of-tree patches for QEMU,
or do you run basically stock upstream QEMU?

thanks
-- PMM
Tobias Nygren March 8, 2015, 12:37 p.m. UTC | #2
Hello,

On Sun, 8 Mar 2015 19:27:27 +0900
Peter Maydell <peter.maydell@linaro.org> wrote:

> On 6 March 2015 at 06:37, Tobias Nygren <tnn@netbsd.org> wrote:
> > A couple of #ifdef changes necessary to use NetBSD's ucontext
> > structs on sparc64 and arm.
> >
> > Signed-off-by: Tobias Nygren <tnn@NetBSD.org>
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> 
> Does NetBSD have a big stack of out-of-tree patches for QEMU,
> or do you run basically stock upstream QEMU?

Hi, it is more or less stock except for this patch. There
are three other small patches that add parenthesis in a few
places to work around a conflict with system macros when
-fstack-protector is enabled but I'm not confident
those are suitable for upstreaming.

Kind regards,
-Tobias
Peter Maydell March 8, 2015, 12:53 p.m. UTC | #3
On 8 March 2015 at 21:37, Tobias Nygren <tnn@netbsd.org> wrote:
> On Sun, 8 Mar 2015 19:27:27 +0900
> Peter Maydell <peter.maydell@linaro.org> wrote:
>> Does NetBSD have a big stack of out-of-tree patches for QEMU,
>> or do you run basically stock upstream QEMU?
>
> Hi, it is more or less stock except for this patch.

Cool. (I know the FreeBSD folk have a pretty large set
of user-mode emulation changes which we've unfortunately
not been able to get upstream yet since there's a lot of
cleanup work required.)

Does the user-emulation work for running random
binaries, or are there known limitations to what
guest/host architectures work well? (I have some
BSD VMs which I was using for compile testing of
the bsd-user code a while back, but I forget what
results I was seeing with which BSD variant...)

> There
> are three other small patches that add parenthesis in a few
> places to work around a conflict with system macros when
> -fstack-protector is enabled but I'm not confident
> those are suitable for upstreaming.

If they're small you might as well post them here anyway;
we may be able to suggest a better fix or perhaps they'll
be OK to apply upstream anyway.

-- PMM
Tobias Nygren March 8, 2015, 2:59 p.m. UTC | #4
On Sun, 8 Mar 2015 21:53:30 +0900
Peter Maydell <peter.maydell@linaro.org> wrote:

> On 8 March 2015 at 21:37, Tobias Nygren <tnn@netbsd.org> wrote:
> > On Sun, 8 Mar 2015 19:27:27 +0900
> > Peter Maydell <peter.maydell@linaro.org> wrote:
> >> Does NetBSD have a big stack of out-of-tree patches for QEMU,
> >> or do you run basically stock upstream QEMU?
> >
> > Hi, it is more or less stock except for this patch.
> 
> Cool. (I know the FreeBSD folk have a pretty large set
> of user-mode emulation changes which we've unfortunately
> not been able to get upstream yet since there's a lot of
> cleanup work required.)
> 
> Does the user-emulation work for running random
> binaries, or are there known limitations to what
> guest/host architectures work well? (I have some
> BSD VMs which I was using for compile testing of
> the bsd-user code a while back, but I forget what
> results I was seeing with which BSD variant...)

I don't know much more than that developers are actively using it to
test their changes on some architectures. It works well enough for them
to get their job done, I suppose.

Standalone static binaries and basic syscall emulation seem to work OK.
There is a problem with ps_strings / argv[0] being NULL in crt0.o.
(looks like it would not be hard to fix)

> > There
> > are three other small patches that add parenthesis in a few
> > places to work around a conflict with system macros when
> > -fstack-protector is enabled but I'm not confident
> > those are suitable for upstreaming.
> 
> If they're small you might as well post them here anyway;
> we may be able to suggest a better fix or perhaps they'll
> be OK to apply upstream anyway.

Actually looking further this has been properly fixed in the base system
and only affects the old 5.x release which is due to be desupported
when 7.0 is released, so I wouldn't worry about it.

Cheers,
-Tobias
Peter Maydell March 8, 2015, 3:01 p.m. UTC | #5
On 8 March 2015 at 23:59, Tobias Nygren <tnn@netbsd.org> wrote:
> Standalone static binaries and basic syscall emulation seem to work OK.
> There is a problem with ps_strings / argv[0] being NULL in crt0.o.
> (looks like it would not be hard to fix)

Yeah, ps_strings rings a bell, I think that was what I was seeing.

-- PMM
Peter Maydell March 13, 2015, 4:38 p.m. UTC | #6
On 5 March 2015 at 21:37, Tobias Nygren <tnn@netbsd.org> wrote:
> A couple of #ifdef changes necessary to use NetBSD's ucontext
> structs on sparc64 and arm.
>
> Signed-off-by: Tobias Nygren <tnn@NetBSD.org>
> ---
>  user-exec.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)

Applied to qemu master, since we don't have any
particularly BSD-specific subtree at the moment.

-- PMM
diff mbox

Patch

diff --git a/user-exec.c b/user-exec.c
index 1ff8673..8f57e8a 100644
--- a/user-exec.c
+++ b/user-exec.c
@@ -404,6 +404,10 @@  int cpu_signal_handler(int host_signum, void *pinfo,
     struct sigcontext *uc = puc;
     unsigned long pc = uc->sc_pc;
     void *sigmask = (void *)(long)uc->sc_mask;
+#elif defined(__NetBSD__)
+    ucontext_t *uc = puc;
+    unsigned long pc = _UC_MACHINE_PC(uc);
+    void *sigmask = (void *)&uc->uc_sigmask;
 #endif
 #endif
 
@@ -441,15 +445,25 @@  int cpu_signal_handler(int host_signum, void *pinfo,
 
 #elif defined(__arm__)
 
+#if defined(__NetBSD__)
+#include <ucontext.h>
+#endif
+
 int cpu_signal_handler(int host_signum, void *pinfo,
                        void *puc)
 {
     siginfo_t *info = pinfo;
+#if defined(__NetBSD__)
+    ucontext_t *uc = puc;
+#else
     struct ucontext *uc = puc;
+#endif
     unsigned long pc;
     int is_write;
 
-#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
+#if defined(__NetBSD__)
+    pc = uc->uc_mcontext.__gregs[_REG_R15];
+#elif defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
     pc = uc->uc_mcontext.gregs[R15];
 #else
     pc = uc->uc_mcontext.arm_pc;