Introduce very basic exception handling support
This commit is contained in:
@@ -32,6 +32,16 @@
|
|||||||
#define DOUBLE_SCIENTIFIC_PRECISION -4
|
#define DOUBLE_SCIENTIFIC_PRECISION -4
|
||||||
#define DOUBLE_SIGN_BIT 0x8000000000000000ULL
|
#define DOUBLE_SIGN_BIT 0x8000000000000000ULL
|
||||||
|
|
||||||
|
/* Exception Record flags */
|
||||||
|
#define EXCEPTION_CONTINUE_SEARCH 0x00
|
||||||
|
#define EXCEPTION_NONCONTINUABLE 0x01
|
||||||
|
#define EXCEPTION_UNWINDING 0x02
|
||||||
|
#define EXCEPTION_EXIT_UNWIND 0x04
|
||||||
|
#define EXCEPTION_STACK_INVALID 0x08
|
||||||
|
#define EXCEPTION_NESTED_CALL 0x10
|
||||||
|
#define EXCEPTION_TARGET_UNWIND 0x20
|
||||||
|
#define EXCEPTION_COLLIDED_UNWIND 0x40
|
||||||
|
|
||||||
/* Maximum number of lead bytes for NLS */
|
/* Maximum number of lead bytes for NLS */
|
||||||
#define NLS_MAXIMUM_LEADBYTES 12
|
#define NLS_MAXIMUM_LEADBYTES 12
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ list(APPEND XTOSKRNL_SOURCE
|
|||||||
${XTOSKRNL_SOURCE_DIR}/rtl/data.cc
|
${XTOSKRNL_SOURCE_DIR}/rtl/data.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/endian.cc
|
${XTOSKRNL_SOURCE_DIR}/rtl/endian.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/exports.cc
|
${XTOSKRNL_SOURCE_DIR}/rtl/exports.cc
|
||||||
|
${XTOSKRNL_SOURCE_DIR}/rtl/exsup.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/guid.cc
|
${XTOSKRNL_SOURCE_DIR}/rtl/guid.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/lifo.cc
|
${XTOSKRNL_SOURCE_DIR}/rtl/lifo.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/llist.cc
|
${XTOSKRNL_SOURCE_DIR}/rtl/llist.cc
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <rtl/bitmap.hh>
|
#include <rtl/bitmap.hh>
|
||||||
#include <rtl/dispatch.hh>
|
#include <rtl/dispatch.hh>
|
||||||
#include <rtl/endian.hh>
|
#include <rtl/endian.hh>
|
||||||
|
#include <rtl/exsup.hh>
|
||||||
#include <rtl/guid.hh>
|
#include <rtl/guid.hh>
|
||||||
#include <rtl/lifo.hh>
|
#include <rtl/lifo.hh>
|
||||||
#include <rtl/llist.hh>
|
#include <rtl/llist.hh>
|
||||||
|
|||||||
27
xtoskrnl/includes/rtl/exsup.hh
Normal file
27
xtoskrnl/includes/rtl/exsup.hh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* PROJECT: ExectOS
|
||||||
|
* COPYRIGHT: See COPYING.md in the top level directory
|
||||||
|
* FILE: xtoskrnl/includes/rtl/exsup.hh
|
||||||
|
* DESCRIPTION: Exception handling
|
||||||
|
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __XTOSKRNL_RTL_EXSUP_HH
|
||||||
|
#define __XTOSKRNL_RTL_EXSUP_HH
|
||||||
|
|
||||||
|
#include <xtos.hh>
|
||||||
|
|
||||||
|
|
||||||
|
/* Runtime Library */
|
||||||
|
namespace RTL
|
||||||
|
{
|
||||||
|
class Exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
STATIC XTAPI VOID RaiseException(IN PEXCEPTION_RECORD ExceptionRecord);
|
||||||
|
STATIC XTAPI VOID RaiseStatus(IN XTSTATUS Status);
|
||||||
|
STATIC XTAPI LONG SystemFilter(VOID);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __XTOSKRNL_RTL_EXSUP_HH */
|
||||||
89
xtoskrnl/rtl/exsup.cc
Normal file
89
xtoskrnl/rtl/exsup.cc
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/**
|
||||||
|
* PROJECT: ExectOS
|
||||||
|
* COPYRIGHT: See COPYING.md in the top level directory
|
||||||
|
* FILE: xtoskrnl/rtl/exsup.cc
|
||||||
|
* DESCRIPTION: Exception handling
|
||||||
|
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <xtos.hh>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raises a structured exception using an exception record.
|
||||||
|
*
|
||||||
|
* @param ExceptionRecord
|
||||||
|
* Supplies a pointer to the exception record containing details.
|
||||||
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RTL::Exception::RaiseException(IN PEXCEPTION_RECORD ExceptionRecord)
|
||||||
|
{
|
||||||
|
/* Not implemented */
|
||||||
|
UNIMPLEMENTED;
|
||||||
|
|
||||||
|
/* Disable interrupts */
|
||||||
|
AR::CpuFunctions::ClearInterruptFlag();
|
||||||
|
|
||||||
|
/* Halt the system */
|
||||||
|
KE::Crash::Panic(ExceptionRecord->ExceptionCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raises a structured exception based on the provided status code.
|
||||||
|
*
|
||||||
|
* @param Status
|
||||||
|
* Supplies the status code to be raised as an exception.
|
||||||
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RTL::Exception::RaiseStatus(IN XTSTATUS Status)
|
||||||
|
{
|
||||||
|
EXCEPTION_RECORD ExceptionRecord;
|
||||||
|
|
||||||
|
/* Not implemented */
|
||||||
|
UNIMPLEMENTED;
|
||||||
|
|
||||||
|
/* Create a basic exception record */
|
||||||
|
ExceptionRecord.ExceptionAddress = _ReturnAddress();
|
||||||
|
ExceptionRecord.ExceptionCode = Status;
|
||||||
|
ExceptionRecord.ExceptionRecord = NULLPTR;
|
||||||
|
ExceptionRecord.NumberParameters = 0;
|
||||||
|
ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
|
||||||
|
|
||||||
|
/* Dispatch the exception */
|
||||||
|
RaiseException(&ExceptionRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether a SEH exception should be handled or lead to a kernel panic based on the processor mode.
|
||||||
|
*
|
||||||
|
* @return This routine returns EXCEPTION_EXECUTE_HANDLER if the CPU was in UserMode,
|
||||||
|
* or EXCEPTION_CONTINUE_SEARCH if the CPU was in KernelMode.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
LONG
|
||||||
|
RTL::Exception::SystemFilter(VOID)
|
||||||
|
{
|
||||||
|
/* Check if the exception originated from kernel-mode execution */
|
||||||
|
if(KE::Processor::GetCurrentThread()->PreviousMode == KernelMode)
|
||||||
|
{
|
||||||
|
/* Kernel-mode fault, force a kernel panic */
|
||||||
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* User-mode fault, catch it and return the error status gracefully */
|
||||||
|
return EXCEPTION_EXECUTE_HANDLER;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user