Skip to contentSkip to conversation

Fix NULL alarm_timer pointer at exit

PATCH In review Jean-Christophe Dubois 2 participants 2 messages May 17, 2009 – May 20, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix NULL alarm_timer pointer at exit

This fixes a SIGSEGV error on qemu exit.

Here is the valgrind output related to this error

==3648== Process terminating with default action of signal 11 (SIGSEGV) ==3648== Access not within mapped region at address 0x8

==3648==    at 0x40636B: host_alarm_handler (vl.c:1345)                                                     
==3648==    by 0x52D807F: (within /lib/libpthread-2.9.so)                                                   
==3648==    by 0x5C0A12E: tcsetattr (in /lib/libc-2.9.so)                                                   
==3648==    by 0x4DD601: term_exit (qemu-char.c:700)                                                        
==3648==    by 0x5B636EC: exit (in /lib/libc-2.9.so)                                                        
==3648==    by 0x5B4B5AC: (below main) (in /lib/libc-2.9.so)  

This simple fix check for a valid pointer as host_alarm_handler is also called after alarm_timer is released in the exit path.

vl.c +2 -2
@@ -915,7 +915,7 @@
 
 static inline int alarm_has_dynticks(struct qemu_alarm_timer *t)
 {
-    return t->flags & ALARM_FLAG_DYNTICKS;
+    return t && (t->flags & ALARM_FLAG_DYNTICKS);
 }
 
 static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t)
@@ -1349,7 +1349,7 @@
         qemu_timer_expired(active_timers[QEMU_TIMER_REALTIME],
                            qemu_get_clock(rt_clock))) {
         qemu_event_increment();
-        alarm_timer->flags |= ALARM_FLAG_EXPIRED;
+        if (alarm_timer) alarm_timer->flags |= ALARM_FLAG_EXPIRED;
 
 #ifndef CONFIG_IOTHREAD
         if (next_cpu) {
#1 lore raw

Hi,

I think the right fix is to block SIGALRM in quit_timers, which is called from main():

static void quit_timers(void)

{
    alarm_timer->stop(alarm_timer);
    alarm_timer = NULL;
}
Quoted 40 lines · Jean-Christophe Dubois

This fixes a SIGSEGV error on qemu exit.

Here is the valgrind output related to this error

==3648== Process terminating with default action of signal 11 (SIGSEGV) ==3648== Access not within mapped region at address 0x8

==3648==    at 0x40636B: host_alarm_handler (vl.c:1345)                                                     
==3648==    by 0x52D807F: (within /lib/libpthread-2.9.so)                                                   
==3648==    by 0x5C0A12E: tcsetattr (in /lib/libc-2.9.so)                                                   
==3648==    by 0x4DD601: term_exit (qemu-char.c:700)                                                        
==3648==    by 0x5B636EC: exit (in /lib/libc-2.9.so)                                                        
==3648==    by 0x5B4B5AC: (below main) (in /lib/libc-2.9.so)  

This simple fix check for a valid pointer as host_alarm_handler is also called after alarm_timer is released in the exit path.

vl.c +2 -2
@@ -915,7 +915,7 @@
 
 static inline int alarm_has_dynticks(struct qemu_alarm_timer *t)
 {
-    return t->flags & ALARM_FLAG_DYNTICKS;
+    return t && (t->flags & ALARM_FLAG_DYNTICKS);
 }
 
 static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t)
@@ -1349,7 +1349,7 @@
         qemu_timer_expired(active_timers[QEMU_TIMER_REALTIME],
                            qemu_get_clock(rt_clock))) {
         qemu_event_increment();
-        alarm_timer->flags |= ALARM_FLAG_EXPIRED;
+        if (alarm_timer) alarm_timer->flags |= ALARM_FLAG_EXPIRED;
 
 #ifndef CONFIG_IOTHREAD
         if (next_cpu) {