ReactOS  0.4.12-dev-914-g71f84a3
hooks.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4 
5 Module Name:
6 
7  hooks.c
8 
9 Abstract:
10 
11  hooking of interrupts
12 
13 Environment:
14 
15  Kernel mode only
16 
17 Author:
18 
19  Klaus P. Gerlicher
20 
21 Revision History:
22 
23  16-Jul-1998: 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 // PROTOTYPES
41 void DeinstallHooks(void);
42 
44 // DEFINES
46 
48 // GLOBALS
50 
51 // IDT entries
52 //PIDTENTRY pidt[256];
53 IDTENTRY oldidt[256]={{0},};
54 
55 IDTENTRY idt_snapshot[256]={{0},};
56 
57 // processor flag for interrupt suspension
59 
61 // PROCEDURES
63 
64 //*************************************************************************
65 // MaskIrqs()
66 //
67 //*************************************************************************
68 void MaskIrqs(void)
69 {
70  ENTER_FUNC();
71 
73  cli();
74 
75  LEAVE_FUNC();
76 }
77 
78 //*************************************************************************
79 // UnmaskIrqs()
80 //
81 //*************************************************************************
82 void UnmaskIrqs(void)
83 {
84  ENTER_FUNC();
85 
87 
88  LEAVE_FUNC();
89 }
90 
91 //*************************************************************************
92 // SetGlobalInt()
93 //
94 //*************************************************************************
95 ULONG SetGlobalInt(ULONG dwInt,ULONG NewIntHandler)
96 {
97  ULONG idt[2];
99  struct IdtEntry* pidt;
100  struct IdtEntry oldidt;
101 
102  ENTER_FUNC();
103 
104  // get linear location of IDT
105  __asm__("sidt %0":"=m" (idt));
106 
107  // get pointer to idte for int 3
108  pidt=((struct IdtEntry*)((idt[1]<<16)|((idt[0]>>16)&0x0000FFFF)))+dwInt;
109 
110  oldidt=*pidt;
111 
112  // set new handler address
113  pidt->HiOffset=(USHORT)(((ULONG)NewIntHandler)>>16);
114  pidt->LoOffset=(USHORT)(((ULONG)NewIntHandler)&0x0000FFFF);
115 
116  DPRINT((0,"new INT(%0.2x) handler = %0.4x:%x\n",dwInt,pidt->SegSel,(pidt->HiOffset<<16)|(pidt->LoOffset&0x0000FFFF)));
117 
118  OldIntHandler=(oldidt.HiOffset<<16)|(oldidt.LoOffset&0x0000FFFF);
119 
120  DPRINT((0,"old INT(%0.2x) handler = %0.4x:%x\n",dwInt,pidt->SegSel,OldIntHandler));
121 
122  LEAVE_FUNC();
123 
124  return OldIntHandler;
125 }
126 
127 //*************************************************************************
128 // TakeIdtSnapshot()
129 //
130 //*************************************************************************
131 void TakeIdtSnapshot(void)
132 {
133  ULONG idt[2],i;
134  struct IdtEntry* pidt;
135 
136  __asm__("sidt %0":"=m" (idt));
137 
138  // get pointer to idte for int 3
139  pidt=((struct IdtEntry*)((idt[1]<<16)|((idt[0]>>16)&0x0000FFFF)));
140 
141  for(i=0;i<256;i++)
142  {
143  DPRINT((11,"TakeIdtSnapShot(): saving vector %u\n",i));
144  if(IsRangeValid((ULONG)pidt,sizeof(*pidt)) )
145  {
146  DPRINT((11,"TakeIdtSnapShot(): vector %u valid\n",i));
147  idt_snapshot[i] = *pidt++;
148  }
149  }
150 }
151 
152 //*************************************************************************
153 // RestoreIdt()
154 //
155 //*************************************************************************
156 void RestoreIdt(void)
157 {
158  ULONG idt[2],i;
159  struct IdtEntry* pidt;
160 
161  __asm__("sidt %0":"=m" (idt));
162 
163  // get pointer to idte for int 3
164  pidt=((struct IdtEntry*)((idt[1]<<16)|((idt[0]>>16)&0x0000FFFF)));
165 
166  for(i=0;i<256;i++)
167  {
168  DPRINT((11,"TakeIdtSnapShot(): restoring vector %u\n",i));
169  if(IsRangeValid((ULONG)pidt,sizeof(*pidt)) )
170  {
171  DPRINT((11,"TakeIdtSnapShot(): vector %u valid\n",i));
172  *pidt++ = idt_snapshot[i];
173  }
174  }
175 }
176 
177 // EOF
void RestoreIdt(void)
Definition: hooks.c:156
void TakeIdtSnapshot(void)
Definition: hooks.c:131
void DeinstallHooks(void)
IDTENTRY idt_snapshot[256]
Definition: hooks.c:55
ULONG SetGlobalInt(ULONG dwInt, ULONG NewIntHandler)
Definition: hooks.c:95
#define LEAVE_FUNC()
Definition: debug.h:43
USHORT SegSel
Definition: hooks.h:45
#define save_flags(x)
Definition: utils.h:285
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
void DPRINT(...)
Definition: polytest.cpp:61
Definition: hooks.h:42
void MaskIrqs(void)
Definition: hooks.c:68
BOOLEAN IsRangeValid(ULONG Addr, ULONG Length)
Definition: utils.c:735
RECT cli
Definition: sndrec32.cpp:79
USHORT HiOffset
Definition: hooks.h:47
static DWORD OldIntHandler
Definition: mouse32.c:71
unsigned short USHORT
Definition: pedump.c:61
USHORT LoOffset
Definition: hooks.h:44
IDTENTRY oldidt[256]
Definition: hooks.c:53
#define restore_flags(x)
Definition: utils.h:286
ULONG ulOldFlags
Definition: hooks.c:58
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
void UnmaskIrqs(void)
Definition: hooks.c:82