Skip to contentSkip to conversation

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

PATCH Applied Tobias Nygren 2 participants 7 messages Mar 5, 2015 – Mar 13, 2015

lore
Share & tools
lore
#0 lore raw

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

A couple of #ifdef changes necessary to use NetBSD's ucontext structs on sparc64 and arm.

---
 user-exec.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
user-exec.c +15 -1
index 1ff8673..8f57e8a 100644
@@ -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;
Signature · 1 line
2.3.0
#2 lore raw

Hello,

Quoted 10 lines · On Sun, 8 Mar 2015 19:27:27 +0900 Peter Maydell <[email protected]>…
Quoted 4 lines · Tobias Nygren

A couple of #ifdef changes necessary to use NetBSD's ucontext structs on sparc64 and arm.

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

#3 lore raw
Quoted 6 lines · Tobias Nygren
Quoted 2 lines · On Sun, 8 Mar 2015 19:27:27 +0900 Peter Maydell <[email protected]>…

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...)

Quoted 5 lines

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

#4 lore raw
Quoted 13 lines · On Sun, 8 Mar 2015 21:53:30 +0900 Peter Maydell <[email protected]>…
Quoted 6 lines · Tobias Nygren
Quoted 2 lines · On Sun, 8 Mar 2015 19:27:27 +0900 Peter Maydell <[email protected]>…

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.)

Quoted 6 lines

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)

Quoted 9 lines
Quoted 5 lines

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

#5 lore raw
Quoted 3 lines · Tobias Nygren

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

#6 lore raw
In reply to Tobias Nygren
Quoted 7 lines · Tobias Nygren

A couple of #ifdef changes necessary to use NetBSD's ucontext structs on sparc64 and arm.

---
 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