ia64/xen-unstable

changeset 3864:7d995f85672d

bitkeeper revision 1.1205.1.4 (4215f76aKShpc2MoKv20Ho-I6PFwGg)

Bug fixes for out-of-bounds bug in the rewrite of debugtrace_printk
author maf46@burn.cl.cam.ac.uk
date Fri Feb 18 14:10:50 2005 +0000 (2005-02-18)
parents ea5144e1109e
children ac04aeeaf462
files xen/drivers/char/console.c
line diff
     1.1 --- a/xen/drivers/char/console.c	Fri Feb 18 13:32:50 2005 +0000
     1.2 +++ b/xen/drivers/char/console.c	Fri Feb 18 14:10:50 2005 +0000
     1.3 @@ -479,13 +479,20 @@ void console_force_lock(void)
     1.4  static unsigned char *debugtrace_buf; /* Debug-trace buffer */
     1.5  static unsigned int   debugtrace_prd; /* Producer index     */
     1.6  static unsigned int   debugtrace_kilobytes = 128, debugtrace_bytes;
     1.7 +static spinlock_t debugtrace_lock = SPIN_LOCK_UNLOCKED;
     1.8  integer_param("debugtrace", debugtrace_kilobytes);
     1.9 -#define DEBUGTRACE_MASK(_p) ((_p) & (debugtrace_bytes-1))
    1.10  
    1.11  void debugtrace_reset(void)
    1.12  {
    1.13 +    unsigned long  flags;
    1.14 +
    1.15 +    spin_lock_irqsave(&debugtrace_lock, flags);
    1.16 +
    1.17      if ( debugtrace_bytes != 0 )
    1.18          memset(debugtrace_buf, '\0', debugtrace_bytes);
    1.19 +    debugtrace_prd = 0;
    1.20 +
    1.21 +    spin_unlock_irqrestore(&debugtrace_lock, flags);
    1.22  }
    1.23  
    1.24  void debugtrace_dump(void)
    1.25 @@ -498,23 +505,25 @@ void debugtrace_dump(void)
    1.26      /* Watchdog can trigger if we print a really large buffer. */
    1.27      watchdog_on = 0;
    1.28  
    1.29 +    spin_lock(&debugtrace_lock);
    1.30 +
    1.31      /* Print oldest portion of the ring. */
    1.32 -    serial_puts(sercon_handle,
    1.33 -                &debugtrace_buf[DEBUGTRACE_MASK(debugtrace_prd)]);
    1.34 +    serial_puts(sercon_handle, &debugtrace_buf[debugtrace_prd]);
    1.35  
    1.36      /* Print youngest portion of the ring. */
    1.37 -    debugtrace_buf[DEBUGTRACE_MASK(debugtrace_prd)] = '\0';
    1.38 -    serial_puts(sercon_handle,
    1.39 -                &debugtrace_buf[0]);
    1.40 +    debugtrace_buf[debugtrace_prd] = '\0';
    1.41 +    serial_puts(sercon_handle, &debugtrace_buf[0]);
    1.42  
    1.43 -    debugtrace_reset();
    1.44 +    memset(debugtrace_buf, '\0', debugtrace_bytes);
    1.45 +    debugtrace_prd = 0;
    1.46 +
    1.47 +    spin_unlock(&debugtrace_lock);
    1.48  
    1.49      watchdog_on = _watchdog_on;
    1.50  }
    1.51  
    1.52  void debugtrace_printk(const char *fmt, ...)
    1.53  {
    1.54 -    static spinlock_t _lock = SPIN_LOCK_UNLOCKED;
    1.55      static char       buf[1024];
    1.56  
    1.57      va_list       args;
    1.58 @@ -524,16 +533,22 @@ void debugtrace_printk(const char *fmt, 
    1.59      if ( debugtrace_bytes == 0 )
    1.60          return;
    1.61  
    1.62 -    spin_lock_irqsave(&_lock, flags);
    1.63 +    spin_lock_irqsave(&debugtrace_lock, flags);
    1.64  
    1.65      va_start(args, fmt);
    1.66      (void)vsnprintf(buf, sizeof(buf), fmt, args);
    1.67      va_end(args);        
    1.68  
    1.69      for ( p = buf; *p != '\0'; p++ )
    1.70 -        debugtrace_buf[DEBUGTRACE_MASK(debugtrace_prd++)] = *p;
    1.71 +    {
    1.72 +        debugtrace_buf[debugtrace_prd++] = *p;
    1.73  
    1.74 -    spin_unlock_irqrestore(&_lock, flags);
    1.75 +        /* always leave a null byte at the end of the buffer */
    1.76 +        if (debugtrace_prd == debugtrace_bytes-1)
    1.77 +            debugtrace_prd = 0;
    1.78 +    }
    1.79 +
    1.80 +    spin_unlock_irqrestore(&debugtrace_lock, flags);
    1.81  }
    1.82  
    1.83  static int __init debugtrace_init(void)