Skip to contentSkip to conversation

qemu on Fedora Core 3 (Linux 2.6.9+), glibc-2.3.3

Qemu-devel John Reiser 5 participants 10 messages Dec 19, 2004 – Dec 22, 2004 Kbuild

lore
Share & tools
lore
#0 lore raw

In order to run qemu-snapshot-2004-12-17_23.tar.bz2 on:
Fedora Core 3 kernel-2.6.8-1.681_FC3 i686 gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3) glibc-2.3.3
binutils-2.15.92.0.2-5
I had to use the extra file and patch below. Otherwise I got very early SIGSEGVs.

-----__restore.S [append __restore.o to VL_OBJS in i386/Makefile] #include <asm/unistd.h>

__restore: .globl __restore

	pop %eax
	movl $ __NR_sigreturn,%eax
	int $0x80

__restore_rt: .globl __restore_rt

	movl $ __NR_rt_sigreturn,%eax
	int $0x80

-----

vl.c renamed from vl.c.orig +0 -0
@@ -882,6 +882,9 @@
 

#endif /* !defined(_WIN32) */

+extern void __restore(void);
+extern void __restore_rt(void);
+
static void init_timers(void)

{
    rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
@@ -913,7 +916,9 @@
        sigfillset(&act.sa_mask);
        act.sa_flags = 0;

#if defined (TARGET_I386) && defined(USE_CODE_COPY)
- act.sa_flags |= SA_ONSTACK;
+#define SA_RESTORER 0x04000000
+ act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+ act.sa_restorer = __restore;

#endif
        act.sa_handler = host_alarm_handler;
        sigaction(SIGALRM, &act, NULL);
@@ -3402,7 +3407,8 @@
        sigfillset(&act.sa_mask);
        act.sa_flags = SA_SIGINFO;
#if defined (TARGET_I386) && defined(USE_CODE_COPY)
-        act.sa_flags |= SA_ONSTACK;
+        act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+	act.sa_restorer = __restore_rt;
#endif
        act.sa_sigaction = host_segv_handler;
        sigaction(SIGSEGV, &act, NULL);
#1 lore raw

Could you please re-send your patch, diffed, as an attachment please?

Thanks,
Hetz

Quoted 62 lines · John Reiser

In order to run qemu-snapshot-2004-12-17_23.tar.bz2 on:

    Fedora Core 3  kernel-2.6.8-1.681_FC3  i686
    gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
    glibc-2.3.3
    binutils-2.15.92.0.2-5

I had to use the extra file and patch below.
Otherwise I got very early SIGSEGVs.

-----__restore.S [append __restore.o to VL_OBJS in i386/Makefile] #include <asm/unistd.h>

__restore: .globl __restore
pop %eax
movl $ __NR_sigreturn,%eax
int $0x80

__restore_rt: .globl __restore_rt
movl $ __NR_rt_sigreturn,%eax
int $0x80
-----

vl.c 2004-12-18 20:53:09.496799856 -0800 renamed from vl.c.orig 2004-12-12 14:20:04.000000000 -0800 +8 -3
@@ -882,6 +882,9 @@
 
 #endif /* !defined(_WIN32) */
 
+extern void __restore(void);
+extern void __restore_rt(void);
+
 static void init_timers(void)
 {
     rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
@@ -913,7 +916,9 @@
         sigfillset(&act.sa_mask);
         act.sa_flags = 0;
 #if defined (TARGET_I386) && defined(USE_CODE_COPY)
-        act.sa_flags |= SA_ONSTACK;
+#define SA_RESTORER   0x04000000
+        act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+       act.sa_restorer = __restore;
 #endif
         act.sa_handler = host_alarm_handler;
         sigaction(SIGALRM, &act, NULL);
@@ -3402,7 +3407,8 @@
         sigfillset(&act.sa_mask);
         act.sa_flags = SA_SIGINFO;
 #if defined (TARGET_I386) && defined(USE_CODE_COPY)
-        act.sa_flags |= SA_ONSTACK;
+        act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+       act.sa_restorer = __restore_rt;
 #endif
         act.sa_sigaction = host_segv_handler;
         sigaction(SIGSEGV, &act, NULL);
 
--

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

#2 lore raw
Quoted 1 line

Could you please re-send your patch, diffed, as an attachment please?

The important part of the original post was output from "diff -Naur". Does gmail mangle message bodies, or was the request due to the other small manual adjustments (non-patch) noted in the original post? Anyway, a 100% patch is attached for use by "patch -p1".

vl.c renamed from vl.c.orig +9 -2
@@ -882,6 +882,9 @@
 
 #endif /* !defined(_WIN32) */
 
+extern void __restore(void);
+extern void __restore_rt(void);
+
 static void init_timers(void)
 {
     rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
@@ -913,7 +916,9 @@
         sigfillset(&act.sa_mask);
         act.sa_flags = 0;
 #if defined (TARGET_I386) && defined(USE_CODE_COPY)
-        act.sa_flags |= SA_ONSTACK;
+#define SA_RESTORER   0x04000000
+        act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+        act.sa_restorer = __restore;
 #endif
         act.sa_handler = host_alarm_handler;
         sigaction(SIGALRM, &act, NULL);
@@ -3402,7 +3407,8 @@
         sigfillset(&act.sa_mask);
         act.sa_flags = SA_SIGINFO;
 #if defined (TARGET_I386) && defined(USE_CODE_COPY)
-        act.sa_flags |= SA_ONSTACK;
+        act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+        act.sa_restorer = __restore_rt;
 #endif
         act.sa_sigaction = host_segv_handler;
         sigaction(SIGSEGV, &act, NULL);
@@ -3449,6 +3455,7 @@
             exit(1);
         } else {
             printf("Waiting gdb connection on port %d\n", gdbstub_port);
+sleep(5);
         }
     } else 
 #endif
Makefile.target renamed from Makefile.target.orig +1 -1
@@ -264,7 +264,7 @@
 endif
 
 # must use static linking to avoid leaving stuff in virtual address space
-VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o 
+VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o  __restore.o
 VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o
 
 SOUND_HW = sb16.o
__restore.S renamed from __restore.S.orig +10 -0
@@ -0,0 +1,10 @@
+#include <asm/unistd.h>
+
+__restore: .globl __restore
+	pop %eax
+	movl $ __NR_sigreturn,%eax
+	int $0x80
+
+__restore_rt: .globl __restore_rt
+	movl $ __NR_rt_sigreturn,%eax
+	int $0x80
#3 lore raw

This optional part of the patch to vl.c:
-----
@@ -3449,6 +3455,7 @@

             exit(1);
         } else {
             printf("Waiting gdb connection on port %d\n", gdbstub_port);
+sleep(5);
         }
     } else

#endif
-----
resulted from my misunderstanding of what qemu actually does. I interpreted "Waiting" as a synchronizing rendezvous blocking wait, while it seems that qemu is merely "Listening" without blocking. The difference is important to me because I want to observe the very first emulated instruction at hardware boot. For the moment, I have put an infinite loop there, then advance the instruction pointer by hand once the gdb connection is established.

#4 lore raw
In reply to John Reiser

Can you move the restorer patch in osdep.c:qemu_sigaction() ? I see no reason to do it in vl.c. Moreover, you should do it only for "qemu-fast".

Fabrice.

Quoted 84 lines · John Reiser
Quoted 1 line

Could you please re-send your patch, diffed, as an attachment please?

The important part of the original post was output from "diff -Naur". Does gmail mangle message bodies, or was the request due to the other small manual adjustments (non-patch) noted in the original post? Anyway, a 100% patch is attached for use by "patch -p1".

------------------------------------------------------------------------

vl.c renamed from vl.c.orig +9 -2
@@ -882,6 +882,9 @@
 
 #endif /* !defined(_WIN32) */
 
+extern void __restore(void);
+extern void __restore_rt(void);
+
 static void init_timers(void)
 {
     rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
@@ -913,7 +916,9 @@
         sigfillset(&act.sa_mask);
         act.sa_flags = 0;
 #if defined (TARGET_I386) && defined(USE_CODE_COPY)
-        act.sa_flags |= SA_ONSTACK;
+#define SA_RESTORER   0x04000000
+        act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+        act.sa_restorer = __restore;
 #endif
         act.sa_handler = host_alarm_handler;
         sigaction(SIGALRM, &act, NULL);
@@ -3402,7 +3407,8 @@
         sigfillset(&act.sa_mask);
         act.sa_flags = SA_SIGINFO;
 #if defined (TARGET_I386) && defined(USE_CODE_COPY)
-        act.sa_flags |= SA_ONSTACK;
+        act.sa_flags |= SA_ONSTACK | SA_RESTORER;
+        act.sa_restorer = __restore_rt;
 #endif
         act.sa_sigaction = host_segv_handler;
         sigaction(SIGSEGV, &act, NULL);
@@ -3449,6 +3455,7 @@
             exit(1);
         } else {
             printf("Waiting gdb connection on port %d\n", gdbstub_port);
+sleep(5);
         }
     } else 
 #endif
Makefile.target renamed from Makefile.target.orig +1 -1
@@ -264,7 +264,7 @@
 endif
 
 # must use static linking to avoid leaving stuff in virtual address space
-VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o 
+VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o  __restore.o
 VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o
 
 SOUND_HW = sb16.o
__restore.S renamed from __restore.S.orig +10 -1
@@ -0,0 +1,10 @@
+#include <asm/unistd.h>
+
+__restore: .globl __restore
+	pop %eax
+	movl $ __NR_sigreturn,%eax
+	int $0x80
+
+__restore_rt: .globl __restore_rt
+	movl $ __NR_rt_sigreturn,%eax
+	int $0x80
 
 
------------------------------------------------------------------------

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

#5 lore raw
Quoted 1 line · Fabrice Bellard

Can you move the restorer patch in osdep.c:qemu_sigaction() ? I see no reason to do it in vl.c. Moreover, you should do it only for "qemu-fast".

The attached patch moves the changes out of vl.c and into osdep.c. But the easiest and clearest code requires removing the 'const' attribute for the new struct qemu_sigaction *. This is OK because the only callers are internal, and use temporary struct qemu_sigaction anyway. To insist on keeping the 'const' requires qemu_sigaction to perform a copy before making the modifications for SA_RESTORER and .sa_restorer, and to pass a pointer to the copy as the argument to the syscall. If you want that, then just copy the implementation out of glibc-2.3.

It seems to me that the restorer actions must apply to all qemu_sigaction for Linux 2.6.x. If restricted to qemu-fast only, then only qemu-fast will work correctly; the other cases will get SIGSEGV upon return from the corresponding signal handlers. Why should qemu-fast be a special case?

Makefile.target renamed from Makefile.target.orig +1 -1
@@ -264,7 +264,7 @@
 endif
 
 # must use static linking to avoid leaving stuff in virtual address space
-VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o 
+VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o  __restore.o
 VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o
 
 SOUND_HW = sb16.o
__restore.S renamed from __restore.S.orig +10 -0
@@ -0,0 +1,10 @@
+#include <asm/unistd.h>
+
+__restore: .globl __restore
+	pop %eax
+	movl $ __NR_sigreturn,%eax
+	int $0x80
+
+__restore_rt: .globl __restore_rt
+	movl $ __NR_rt_sigreturn,%eax
+	int $0x80
osdep.c renamed from osdep.c.orig +17 -1
@@ -153,9 +153,25 @@
     QEMU_SYSCALL4(rt_sigaction, signum, act, oldact, sigsetsize);
 }
 
-int qemu_sigaction(int signum, const struct qemu_sigaction *act, 
+int qemu_sigaction(int signum, struct qemu_sigaction *act, 
                    struct qemu_sigaction *oldact)
 {
+#define SA_RESTORER   0x04000000
+    if (!(act->sa_flags & SA_RESTORER)) {
+        /* Required for Linux 2.6.x "no-exec stack": kernel does not
+         * push trampoline instructions for handler return,
+         * so user-mode code must supply the correct .sa_restorer.
+         */
+        extern void __restore(void);
+        extern void __restore_rt(void);
+        act->sa_flags |= SA_RESTORER;
+        if (act->sa_flags & SA_SIGINFO) {
+            act->sa_restorer = __restore_rt;
+        }
+        else {
+            act->sa_restorer = __restore;
+        }
+    }
     return kernel_sigaction(signum, act, oldact, 8);
 }
 
osdep.h renamed from osdep.h.orig +1 -1
@@ -35,7 +35,7 @@
     sigset_t sa_mask;		/* mask last for extensibility */
 };
 
-int qemu_sigaction(int signum, const struct qemu_sigaction *act, 
+int qemu_sigaction(int signum, struct qemu_sigaction *act, 
                    struct qemu_sigaction *oldact);
 
 #undef sigaction
#6 lore raw

Hi,

silly question: why don't you use inline assembly to make those two functions?

Ciao,
Dscho

#7 lore raw
Quoted 3 lines

silly question: why don't you use inline assembly to make those two functions?

The calls are not execution-time critical (fewer than 10 calls). They are complexity, platform, and developer-time critical. More time will be spent by developers and future maintainers than the total machine cycles spent executing the code, over all the machines in the world, ever. So making the developer+maintainer tasks simple and quick is more important than cycle- or byte-efficiency.

#8 lore raw

where can I d/l the source code with this patch as I am having problems running qemu on FC3

DV

Quoted 12 lines · John Reiser
Quoted 3 lines

silly question: why don't you use inline assembly to make those two functions?

The calls are not execution-time critical (fewer than 10 calls). They are complexity, platform, and developer-time critical. More time will be spent by developers and future maintainers than the total machine cycles spent executing the code, over all the machines in the world, ever. So making the developer+maintainer tasks simple and quick is more important than cycle- or byte-efficiency.

#9 lore raw
Quoted 1 line

where can I d/l the source code with this patch as I am having problems running qemu on FC3

From the qemu home page http://fabrice.bellard.free.fr/qemu/
follow the Link "Pending patches" to http://www.dad-answers.com/qemu/
and choose http://www.dad-answers.com/qemu/qemu-snapshot-2004-12-21_23.tar.bz2
The patch (your choice of 2) is in another message of this current thread of this mailing list. If necessary, see the archive at
http://lists.gnu.org/archive/html/qemu-devel/2004-12/threads.html