ReactOS  0.4.14-dev-114-gc8cbd56
gpfault.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4 
5 Module Name:
6 
7  GPFault.c
8 
9 Abstract:
10 
11  handle general protection faults on x86
12 
13 Environment:
14 
15  Kernel mode only
16 
17 Author:
18 
19  Klaus P. Gerlicher
20 
21 Revision History:
22 
23  13-Nov-1999: created
24  15-Nov-2000: general cleanup of source files
25 
26 Copyright notice:
27 
28  This file may be distributed under the terms of the GNU Public License.
29 
30 --*/
31 
33 // INCLUDES
35 #include "remods.h"
36 #include "precomp.h"
37 
39 // GLOBALS
42 
43 char tempGP[1024];
44 
46 // FUNCTIONS
48 
49 //*************************************************************************
50 // NewGPFaultHandler()
51 //
52 //*************************************************************************
54 {
55  DPRINT((0,"HandleGPFault(): ptr = %x at eip: %x\n",ptr, ptr->eip));
56 }
57 
58 //*************************************************************************
59 // NewGPFaultHandler()
60 //
61 //*************************************************************************
62 __asm__ ("\n\t \
63  NewGPFaultHandler:\n\t \
64  pushfl\n\t \
65  cli\n\t \
66  cld\n\t \
67  pushal\n\t \
68  pushl %ds\n\t \
69 \n\t \
70  // test for v86 mode\n\t \
71  testl $0x20000,40(%esp)\n\t \
72  jnz notv86\n\t \
73  popl %ds\n\t \
74  popal\n\t \
75  popfl\n\t \
76  .byte 0x2e\n\t \
77  jmp *_OldGPFaultHandler\n\t \
78  notv86:\n\t \
79  // setup default data selectors\n\t \
80  movw %ss,%ax\n\t \
81  movw %ax,%ds\n\t \
82 \n\t \
83  // get frame ptr\n\t \
84  lea 40(%esp),%eax\n\t \
85  pushl %eax\n\t \
86  call _HandleGPFault\n\t \
87  addl $4,%esp\n\t \
88 \n \t \
89  popl %ds\n\t \
90  popal\n\t \
91  popfl\n\t \
92  // remove error code from stack and replace with reason code\n\t \
93  movl $" STR(REASON_GP_FAULT) ",(%esp)\n\t \
94  // call debugger loop\n\t \
95  jmp NewInt31Handler\n\t \
96  ");
97 
98 //*************************************************************************
99 // InstallGPFaultHook()
100 //
101 //*************************************************************************
103 {
104  ULONG LocalGPFaultHandler;
105 
106  ENTER_FUNC();
107 
108  MaskIrqs();
109  if(!OldGPFaultHandler)
110  {
111  __asm__("mov $NewGPFaultHandler,%0"
112  :"=r" (LocalGPFaultHandler)
113  :
114  :"eax");
115  OldGPFaultHandler=SetGlobalInt(0x0D,(ULONG)LocalGPFaultHandler);
116  }
117  UnmaskIrqs();
118 
119  LEAVE_FUNC();
120 }
121 
122 //*************************************************************************
123 // DeInstallGPFaultHook()
124 //
125 //*************************************************************************
127 {
128  ENTER_FUNC();
129 
130  MaskIrqs();
132  {
136  }
137  UnmaskIrqs();
138 
139  LEAVE_FUNC();
140 }
141 
142 // EOF
#define TRUE
Definition: types.h:120
void DeInstallGPFaultHook(void)
Definition: gpfault.c:126
ULONG SetGlobalInt(ULONG dwInt, ULONG NewIntHandler)
Definition: hooks.c:95
#define LEAVE_FUNC()
Definition: debug.h:43
#define STR(x)
Definition: utils.h:34
#define REASON_GP_FAULT
Definition: shell.h:75
static PVOID ptr
Definition: dispmode.c:27
void InstallGPFaultHook(void)
Definition: gpfault.c:102
void DPRINT(...)
Definition: polytest.cpp:61
void MaskIrqs(void)
Definition: hooks.c:68
BOOLEAN RemoveAllSWBreakpoints(BOOLEAN bEvenPermanents)
Definition: bp.c:463
__asm__("\n\t \ NewGPFaultHandler:\n\t \ pushfl\n\t \ cli\n\t \ cld\n\t \ pushal\n\t \ pushl %ds\n\t \ \n\t \ // test for v86 mode\n\t \ testl $0x20000,40(%esp)\n\t \ jnz notv86\n\t \ popl %ds\n\t \ popal\n\t \ popfl\n\t \ .byte 0x2e\n\t \ jmp *_OldGPFaultHandler\n\t \ notv86:\n\t \ // setup default data selectors\n\t \ movw %ss,%ax\n\t \ movw %ax,%ds\n\t \ \n\t \ // get frame ptr\n\t \ lea 40(%esp),%eax\n\t \ pushl %eax\n\t \ call _HandleGPFault\n\t \ addl $4,%esp\n\t \ \n \t \ popl %ds\n\t \ popal\n\t \ popfl\n\t \ // remove error code from stack and replace with reason code\n\t \ movl $" STR(REASON_GP_FAULT) ",(%esp)\n\t \ // call debugger loop\n\t \ jmp NewInt31Handler\n\t \ ")
ULONG OldGPFaultHandler
Definition: gpfault.c:41
void HandleGPFault(FRAME *ptr)
Definition: gpfault.c:53
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
char tempGP[1024]
Definition: gpfault.c:43
Definition: i386bug.c:6
void UnmaskIrqs(void)
Definition: hooks.c:82