From 7fd1fb8745ffde563001bbe743f4a2c08a10378c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 16 Sep 2021 15:02:05 -0400 Subject: [PATCH] kernel: Correct bootloader syslog buffer handoff logic. If keep_debug_output_buffer is true, then we reused the syslog buffer the bootloader allocated (and which has just been re-mapped above), so we do not need to write the buffer in again (and moreover doing so is incorrect, as it contains a raw ring_buffer header, and will be larger than the buffer.) This fixes "" appearing at the beginning of all syslogs (or at least, ones that began with handoffs from the bootloader) spuriously when the whole buffer was really present anyway. --- src/system/kernel/debug/debug.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/system/kernel/debug/debug.cpp b/src/system/kernel/debug/debug.cpp index 7f7bb54324..780180f70d 100644 --- a/src/system/kernel/debug/debug.cpp +++ b/src/system/kernel/debug/debug.cpp @@ -1367,29 +1367,28 @@ syslog_init_post_vm(struct kernel_args* args) status = B_NO_MEMORY; goto err2; } - } else { + } else if (args->debug_output != NULL) { // create an area for the debug syslog buffer void* base = (void*)ROUNDDOWN((addr_t)(void *)args->debug_output, B_PAGE_SIZE); size_t size = ROUNDUP(args->debug_size, B_PAGE_SIZE); area_id area = create_area("syslog debug", &base, B_EXACT_ADDRESS, size, - B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); if (area < 0) { status = B_NO_MEMORY; goto err2; } } + if (!args->keep_debug_output_buffer && args->debug_output != NULL) { + syslog_write((const char*)args->debug_output.Pointer(), + args->debug_size, false); + } + // initialize syslog message sSyslogMessage->from = 0; sSyslogMessage->options = LOG_KERN; sSyslogMessage->priority = LOG_DEBUG; sSyslogMessage->ident[0] = '\0'; - //strcpy(sSyslogMessage->ident, "KERNEL"); - - if (args->debug_output != NULL) { - syslog_write((const char*)args->debug_output.Pointer(), - args->debug_size, false); - } // Allocate memory for the previous session's debug syslog output. In // syslog_init_post_modules() we'll write it back to disk and free it.