diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-03 19:59:45 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-03 19:59:45 -0400 |
commit | 23a8e1b78063c0276d987e835434700267b9c8f8 (patch) | |
tree | 19886b291f9c56fb2c90068aece37aee991cca79 /sys/include/dev | |
parent | 9c7fcf89f9ec234dd55ace2c48f4fcc84069c5ac (diff) |
kernel: Ensure mutually exclusive console accessexpt
If multiple processes try to write to the console, a race condition
of sorts may occur. Similarly, if multiple processes try to read from the
console and contend with the console input buffer. One process may steal
keys from the other. Prevent this by implementing a mutex within the
console descriptor. Each time a process reads or writes the console, it
attaches itself. Any other processes attempting to read or write the
console while another is attached will be yielded to the scheduler
until the resource is free.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/include/dev')
-rw-r--r-- | sys/include/dev/cons/cons.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/sys/include/dev/cons/cons.h b/sys/include/dev/cons/cons.h index aa9d8e3..c82c3c5 100644 --- a/sys/include/dev/cons/cons.h +++ b/sys/include/dev/cons/cons.h @@ -32,6 +32,8 @@ #include <sys/types.h> #include <sys/spinlock.h> +#include <sys/proc.h> +#include <sys/mutex.h> #include <sys/console.h> #include <dev/video/fbdev.h> #include <dev/cons/consvar.h> @@ -49,6 +51,8 @@ struct cons_screen { struct fbdev fbdev; struct ansi_state ansi_s; struct console_feat feat; /* Features */ + struct proc *atproc; /* Attached proc */ + struct mutex *atproc_lock; uint32_t fg; uint32_t bg; @@ -72,6 +76,8 @@ void cons_update_color(struct cons_screen *scr, uint32_t fg, uint32_t bg); void cons_clear_scr(struct cons_screen *scr, uint32_t bg); void cons_reset_color(struct cons_screen *scr); void cons_reset_cursor(struct cons_screen *scr); +int cons_attach(void); +int cons_detach(void); int cons_putch(struct cons_screen *scr, char c); int cons_putstr(struct cons_screen *scr, const char *s, size_t len); |