From 8083619cf7874599cccc82527b90362de5691efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 25 Oct 2004 22:53:37 +0000 Subject: [PATCH] Since the additional 512 bytes of dprintf() on the stack can potentially change the flow of things, it now has its own buffer, and fills it with interrupts disabled (everything comes at a price). Now uses the safe vsnprintf() instead of vsprintf() which could crash the kernel. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9510 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/debug.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/kernel/core/debug.c b/src/kernel/core/debug.c index b262a0ff5a..d7f460ffa1 100644 --- a/src/kernel/core/debug.c +++ b/src/kernel/core/debug.c @@ -43,6 +43,9 @@ static int debugger_on_cpu = -1; static struct debugger_command *sCommands; +#define OUTPUT_BUFFER_SIZE 1024 +static char sOutputBuffer[OUTPUT_BUFFER_SIZE]; + #define LINE_BUF_SIZE 1024 #define MAX_ARGS 16 #define HISTORY_SIZE 16 @@ -517,16 +520,27 @@ set_dprintf_enabled(bool newState) void dprintf(const char *fmt, ...) { + cpu_status state; va_list args; - char temp[512]; - if (sSerialDebugEnabled) { - va_start(args, fmt); - vsprintf(temp, fmt, args); - va_end(args); + if (!sSerialDebugEnabled) + return; - dbg_puts(temp); - } + // ToDo: maybe add a non-interrupt buffer and path that only + // needs to acquire a semaphore instead of needing to disable + // interrupts? + + state = disable_interrupts(); + acquire_spinlock(&dbg_spinlock); + + va_start(args, fmt); + vsnprintf(sOutputBuffer, OUTPUT_BUFFER_SIZE, fmt, args); + va_end(args); + + arch_dbg_con_puts(sOutputBuffer); + + release_spinlock(&dbg_spinlock); + restore_interrupts(state); }