From 9f86e52164b689dc450230f3de4c1237cda79cfc Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Mon, 8 Nov 2021 01:33:18 +0800 Subject: [PATCH] runtime: disable interrupts on Printf Printf uses vsnprintf and a global buffer prone to race conditions. --- runtime/stdio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/stdio.c b/runtime/stdio.c index 950f8cb..cbe784d 100644 --- a/runtime/stdio.c +++ b/runtime/stdio.c @@ -5,6 +5,7 @@ #include "../memory/memory.h" #include "../graphics/graphics.h" #include "../driver/irq/pic/serial/serial.h" +#include "../interrupt/interrupt.h" #include "../efimain.h" #include @@ -92,6 +93,7 @@ void io_WriteConsoleASCII(const char *str) { char __io_Printf_buffer[4096]; int io_Printf(const char *fmt, ...) { + INTERRUPT_DISABLE; va_list args; va_start(args, fmt); int ret = vsnprintf(__io_Printf_buffer, sizeof(__io_Printf_buffer), fmt, args); @@ -99,5 +101,6 @@ int io_Printf(const char *fmt, ...) { io_WriteConsole(__io_Printf_buffer); + INTERRUPT_RESTORE; return ret; }