kernel: printk: fix log buffer overflow
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#include <kernel/console.h>
|
#include <kernel/console.h>
|
||||||
#include <kernel/queue.h>
|
|
||||||
#include <kernel/locks.h>
|
|
||||||
#include <kernel/libc/string.h>
|
#include <kernel/libc/string.h>
|
||||||
|
#include <kernel/locks.h>
|
||||||
|
#include <kernel/queue.h>
|
||||||
|
|
||||||
static struct queue consoles;
|
static struct queue consoles = {0};
|
||||||
static spin_lock_t consoles_lock = SPIN_LOCK_INIT;
|
static spin_lock_t consoles_lock = SPIN_LOCK_INIT;
|
||||||
|
|
||||||
static void unregister_boot_consoles(void)
|
static void unregister_boot_consoles(void)
|
||||||
@@ -11,7 +11,8 @@ static void unregister_boot_consoles(void)
|
|||||||
struct queue_entry *cur = queue_first(&consoles);
|
struct queue_entry *cur = queue_first(&consoles);
|
||||||
while (cur) {
|
while (cur) {
|
||||||
struct queue_entry *next = cur->qe_next;
|
struct queue_entry *next = cur->qe_next;
|
||||||
struct console *con = QUEUE_CONTAINER(struct console, c_list, cur);
|
struct console *con
|
||||||
|
= QUEUE_CONTAINER(struct console, c_list, cur);
|
||||||
if (con->c_flags & CON_BOOT) {
|
if (con->c_flags & CON_BOOT) {
|
||||||
queue_delete(&consoles, cur);
|
queue_delete(&consoles, cur);
|
||||||
}
|
}
|
||||||
@@ -25,7 +26,8 @@ kern_status_t console_register(struct console *con)
|
|||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
spin_lock_irqsave(&consoles_lock, &flags);
|
spin_lock_irqsave(&consoles_lock, &flags);
|
||||||
|
|
||||||
queue_foreach (struct console, cur, &consoles, c_list) {
|
queue_foreach(struct console, cur, &consoles, c_list)
|
||||||
|
{
|
||||||
if (!strcmp(cur->c_name, con->c_name)) {
|
if (!strcmp(cur->c_name, con->c_name)) {
|
||||||
spin_unlock_irqrestore(&consoles_lock, flags);
|
spin_unlock_irqrestore(&consoles_lock, flags);
|
||||||
return KERN_NAME_EXISTS;
|
return KERN_NAME_EXISTS;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <kernel/printk.h>
|
|
||||||
#include <kernel/locks.h>
|
|
||||||
#include <kernel/console.h>
|
#include <kernel/console.h>
|
||||||
#include <kernel/libc/stdio.h>
|
#include <kernel/libc/stdio.h>
|
||||||
|
#include <kernel/locks.h>
|
||||||
|
#include <kernel/printk.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define LOG_BUFFER_SIZE 0x40000
|
#define LOG_BUFFER_SIZE 0x40000
|
||||||
@@ -26,13 +26,18 @@ static void flush_log_buffer(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console_write(early_console, log_buffer + log_buffer_readp, log_buffer_writep - log_buffer_readp);
|
console_write(early_console, log_buffer + log_buffer_readp,
|
||||||
|
log_buffer_writep - log_buffer_readp);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct queue *consoles = get_consoles(&flags);
|
struct queue *consoles = get_consoles(&flags);
|
||||||
queue_foreach(struct console, con, consoles, c_list) {
|
queue_foreach(struct console, con, consoles, c_list)
|
||||||
console_write(con, log_buffer + log_buffer_readp, log_buffer_writep - log_buffer_readp);
|
{
|
||||||
|
console_write(
|
||||||
|
con,
|
||||||
|
log_buffer + log_buffer_readp,
|
||||||
|
log_buffer_writep - log_buffer_readp);
|
||||||
}
|
}
|
||||||
|
|
||||||
put_consoles(consoles, flags);
|
put_consoles(consoles, flags);
|
||||||
@@ -61,6 +66,18 @@ void early_printk_init(struct console *con)
|
|||||||
early_console = con;
|
early_console = con;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_msg_direct(const char *s, size_t len)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
struct queue *consoles = get_consoles(&flags);
|
||||||
|
queue_foreach(struct console, con, consoles, c_list)
|
||||||
|
{
|
||||||
|
console_write(con, s, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
put_consoles(consoles, flags);
|
||||||
|
}
|
||||||
|
|
||||||
int printk(const char *format, ...)
|
int printk(const char *format, ...)
|
||||||
{
|
{
|
||||||
char msg[LOG_MSG_SIZE];
|
char msg[LOG_MSG_SIZE];
|
||||||
@@ -74,7 +91,8 @@ int printk(const char *format, ...)
|
|||||||
msg[len + 1] = '\0';
|
msg[len + 1] = '\0';
|
||||||
|
|
||||||
if (log_buffer_writep == LOG_BUFFER_SIZE - 1) {
|
if (log_buffer_writep == LOG_BUFFER_SIZE - 1) {
|
||||||
console_write(early_console, msg, len + 1);
|
print_msg_direct(msg, len + 1);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|||||||
Reference in New Issue
Block a user