My Project
Loading...
Searching...
No Matches
exception.c
Go to the documentation of this file.
1/*++
2
3Module Name:
4
5 exception.c
6
7Purpose:
8
9 This translation unit contains the implementation of exception checking & handling in MatanelOS (_try _except macros)
10
11Author:
12
13 slep (Matanel) 2025.
14
15Revision History:
16
17--*/
18
20#include "../../includes/ps.h"
21
22bool
24 IN PETHREAD Thread
25)
26
27/*++
28
29 Routine description:
30
31 Checks if an exception handler is present in the current thread context.
32
33 Arguments:
34
35 [IN] PETHREAD Thread - The thread to check on.
36
37 Return Values:
38
39 True if present, false otherwise.
40
41--*/
42
43{
44 if (Thread) {
45 if (Thread->ExceptionRegistration.Handler != NULL) {
46 return true;
47 }
48 else {
49 return false;
50 }
51 }
52 return false;
53}
54
55void
57 IN PTRAP_FRAME TrapFrame,
58 IN PCONTEXT ContextRecord,
59 IN PEXCEPTION_RECORD ExceptionRecord
60)
61
62/*++
63
64 Routine description:
65 (UNUSED)
66 Changes the trap frame to point to the _except handler of the thread.
67
68 Arguments:
69
70 [IN] PTRAP_FRAME trap - Pointer to Trap frame of the thread.
71 [IN] PCONTEXT ContextRecord - Pointer to Context record of the thread (saved in _try by thread)
72 [IN] PEXCEPTION_RECORD ExceptionRecord - Pointer to Exception record of the thread
73
74 Return Values:
75
76 None.
77
78--*/
79
80{
82 // Change trap frame to context record set by thread. (except RIP)
83 TrapFrame->rsp = ContextRecord->Rsp;
84 TrapFrame->rflags = ContextRecord->RFlags;
85
86 // General-purpose registers from the context frame
87 TrapFrame->r15 = ContextRecord->R15;
88 TrapFrame->r14 = ContextRecord->R14;
89 TrapFrame->r13 = ContextRecord->R13;
90 TrapFrame->r12 = ContextRecord->R12;
91
92 TrapFrame->r11 = ContextRecord->R11;
93 TrapFrame->r10 = ContextRecord->R10;
94 TrapFrame->r9 = ContextRecord->R9;
95 TrapFrame->r8 = ContextRecord->R8;
96
97 TrapFrame->rbp = ContextRecord->Rbp;
98 TrapFrame->rdi = ContextRecord->Rdi;
99 TrapFrame->rsi = ContextRecord->Rsi;
100
101 TrapFrame->rcx = ContextRecord->Rcx;
102 TrapFrame->rbx = ContextRecord->Rbx;
103 TrapFrame->rdx = ContextRecord->Rdx;
104 TrapFrame->rax = ContextRecord->Rax;
105
106 // Enumerate all handlers, if one returned FIXME TODO (Decide between return value approach or completely different approach, i scrapped the exception handling idea for now, too complicated and messy, id rather work on memory
107 }
108
109
110}
#define IN
Definition annotations.h:7
TRAP_FRAME * PTRAP_FRAME
Definition core.h:54
ETHREAD * PETHREAD
Definition core.h:42
bool ExpIsExceptionHandlerPresent(IN PETHREAD Thread)
Definition exception.c:23
void ExpDispatchException(IN PTRAP_FRAME TrapFrame, IN PCONTEXT ContextRecord, IN PEXCEPTION_RECORD ExceptionRecord)
Definition exception.c:56
struct _CONTEXT * PCONTEXT
struct _EXCEPTION_RECORD * PEXCEPTION_RECORD
PETHREAD PsGetCurrentThread(void)
Definition thread.c:191