From 3eb3c34275aeaa4375fc9a97fa90feb4b4a06349 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Fri, 3 Nov 2017 03:14:46 +0000 Subject: [PATCH] Add guards --- arch/config.h | 10 ++++++++++ arch/exception.c | 8 ++++++++ arch/hwint.c | 12 +++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/config.h b/arch/config.h index 6056b76..50071b4 100644 --- a/arch/config.h +++ b/arch/config.h @@ -20,4 +20,14 @@ #define GDT_USER_CS_SELECTOR GDT_SEGMENT_SELECTOR(GDT_USER_CS_INDEX) #define GDT_USER_DS_SELECTOR GDT_SEGMENT_SELECTOR(GDT_USER_DS_INDEX) +#define INT_EXCEPTION_COUNT 32 +#define INT_HWINT_COUNT 16 +#define INT_TOTAL_COUNT (INT_EXCEPTION_COUNT + INT_HWINT_COUNT) + +#define INT_EXCEPTION_FIRST 0 +#define INT_EXCEPTION_LAST (INT_EXCEPTION_FIRST + INT_EXCEPTION_COUNT - 1) + +#define INT_HWINT_FIRST (INT_EXCEPTION_LAST + 1) +#define INT_HWINT_LAST (INT_HWINT_FIRST + INT_HWINT_COUNT - 1) + #endif diff --git a/arch/exception.c b/arch/exception.c index 9676554..5e46dfd 100644 --- a/arch/exception.c +++ b/arch/exception.c @@ -1,3 +1,4 @@ +#include "config.h" #include "logger.h" struct IsrRegisters { @@ -44,5 +45,12 @@ static const char *const messages[] = { void exception_handler(struct IsrRegisters regs) { + if ( + !(regs.int_no >= INT_EXCEPTION_FIRST && + regs.int_no <= INT_EXCEPTION_LAST) + ) { + return; + } + logger_warn(messages[regs.int_no]); } diff --git a/arch/hwint.c b/arch/hwint.c index aafb9ee..bce0325 100644 --- a/arch/hwint.c +++ b/arch/hwint.c @@ -1,3 +1,4 @@ +#include "config.h" #include "logger.h" struct IsrRegisters { @@ -28,5 +29,14 @@ static const char *const messages[] = { void hwint_handler(struct IsrRegisters regs) { - logger_warn(messages[regs.int_no - 32]); + if ( + !(regs.int_no >= INT_HWINT_FIRST && + regs.int_no <= INT_HWINT_LAST) + ) { + return; + } + + const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST; + + logger_warn(messages[hwint_no]); }