📄 hooks.c
字号:
/****************************************************************************** * * Copyright (c) 2003 Gerhard W. Gruber * * PROJECT: pICE * $Source: /cvsroot/pice/pice/module/hooks.c,v $ * $Revision: 1.5 $ * $Date: 2004/02/17 23:07:36 $ * $Author: lightweave $ * $Name: $ * * $Log: hooks.c,v $ * Revision 1.5 2004/02/17 23:07:36 lightweave * * Improved the DEBUG facillity and replaced the configuration handler with a * new code which now can read MS Windows INI style files. See CHANGES.txt for * more details. * Also added a macro which prevents compiling for kernels before 2.4.19. * * Revision 1.4 2003/06/18 22:00:22 lightweave * DEBUG and DEBUG_SERIAL added * * *****************************************************************************/static char *ident = "$Header: /cvsroot/pice/pice/module/hooks.c,v 1.5 2004/02/17 23:07:36 lightweave Exp $";/*++Copyright (c) 1998-2001 Klaus P. GerlicherModule Name: hooks.cAbstract: hooking of interruptsEnvironment: Kernel mode onlyAuthor: Klaus P. GerlicherRevision History: 16-Jul-1998: created 15-Nov-2000: general cleanup of source filesCopyright notice: This file may be distributed under the terms of the GNU Public License.--*/////////////////////////////////////////////////////// INCLUDES////#include "remods.h"#include <asm/io.h>#include "precomp.h"////////////////////////////////////////////////////// PROTOTYPES////////////////////////////////////////////////////////// DEFINES////////////////////////////////////////////////////////// GLOBALS////// processor flag for interrupt suspensionULONG g_ulFlags;////////////////////////////////////////////////////// PROCEDURES//////*************************************************************************// EnterCritical()////*************************************************************************void EnterCritical(void) { ENTER_FUNC(); save_flags(g_ulFlags); cli(); LEAVE_FUNC();} //*************************************************************************// LeaveCritical()////*************************************************************************void LeaveCritical(void) { ENTER_FUNC(); restore_flags(g_ulFlags); LEAVE_FUNC();} //*************************************************************************// AtomicSet8Byte()////*************************************************************************static inline void AtomicSet8Byte(unsigned long long * ptr, unsigned int low, unsigned int high){ __asm__ __volatile__ ( "\n1:\t" "movl (%0), %%eax\n\t" "movl 4(%0), %%edx\n\t" "cmpxchg8b (%0)\n\t" "jnz 1b" : /* no outputs */ : "D"(ptr), "b"(low), "c"(high) : "ax","dx","memory");}//*************************************************************************// HookInterruptVector()////*************************************************************************void HookInterruptVector(ULONG dwInt,PVOID NewIntHandler,PVOID* pOldIntHandler){ PIDT pIdt; PULONG pTempIdt; IDT tempIdtEntry; ENTER_FUNC(); // get linear location of IDT pIdt = GetIDTPtr(); // get pointer to idte for interrupt pIdt += dwInt; // return old handler's address if requested // must do this before setting new handler because INT might // be triggered even before we return from here and will jump into // nirvana while leaving DebuggerEntry if(pOldIntHandler) { *pOldIntHandler = (PVOID)((pIdt->Offset_31_16<<16) | (pIdt->Offset_15_0&0x0000FFFF)); DPRINT(PICE_DEBUG, DBT_HOOKS, DBL_INFO, "old INT(%02x) handler = %04x:%p\n", dwInt, pIdt->Selector, *pOldIntHandler); } // set new handler address tempIdtEntry = *pIdt; tempIdtEntry.Offset_31_16 =(USHORT)(((ULONG)NewIntHandler)>>16); tempIdtEntry.Offset_15_0 =(USHORT)(((ULONG)NewIntHandler)&0x0000FFFF);#if LINUX_VERSION_CODE < 0x020409 if(pOldIntHandler) tempIdtEntry.DescType = 0x0E; // interrupt gate else tempIdtEntry.DescType = 0x0F; // trap gate#endif // LINUX_VERSION_CODE pTempIdt = (PULONG)&tempIdtEntry; // now store the 8byte IDT descriptor in one atomic operation AtomicSet8Byte((unsigned long long*)pIdt, pTempIdt[0], pTempIdt[1]); // flush chip caches#ifdef CONFIG_SMP FlushCacheAndTLBAllCpus();#else // CONFIG_SMP FlushCacheAndTLB();#endif // CONFIG_SMP DPRINT(PICE_DEBUG, DBT_HOOKS, DBL_INFO, "new INT(%02x) handler = %04x:%x\n", dwInt, pIdt->Selector, (pIdt->Offset_31_16<<16)|(pIdt->Offset_15_0&0x0000FFFF)); LEAVE_FUNC();}// EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -