📄 kwin32.c
字号:
sizeof(OsAxsDataBlock),
VERSION_OSAXS_KERN_POINTERS_1,
0,
(DWORD)&KData,
(DWORD)&ProcArray[0],
(DWORD)&pvHDNotifyExdi,
(DWORD)&g_pHdEvent,
(DWORD)&pdwHDTaintedModuleCount,
(DWORD)&g_ulHDEventFilter,
(DWORD)&MD_CBRtn, // Needs to be dereferenced manually
(DWORD)&SystemAPISets[0],
(DWORD)&MemoryInfo,
(DWORD)&pTOC
};
void HDCleanup ()
{
g_pHdInit = NULL;
HDException = FakeHDException;
HDPageIn = FakeHDPageIn;
HDModLoad = FakeHDModLoad;
HDModUnload = FakeHDModUnload;
pvHDNotifyExdi = NULL;
pdwHDTaintedModuleCount = NULL;
HDConnectClient = NULL;
g_pHdEvent = NULL;
s_fHdConnected = FALSE;
}
BOOL SC_ConnectHdstub (void *pvUnused)
{
BOOL fRet;
HDSTUB_INIT hd = {
sizeof(HDSTUB_INIT),
InitializeCriticalSection,
DeleteCriticalSection,
EnterCriticalSection,
LeaveCriticalSection,
INTERRUPTS_ENABLE,
#ifdef MIPS
InterlockedDecrement,
InterlockedIncrement,
#endif
#ifdef ARM
InSysCall,
#endif
HDCleanup,
pKITLIoCtl,
NKwvsprintfW,
&KData,
&g_ulHDEventFilter,
HwTrap,
SC_CacheRangeFlush,
};
TRUSTED_API (L"SC_ConnectHdstub", FALSE);
if (!s_fHdConnected)
{
CALLSTACK *pcstk = NULL, cstk;
if (ProcArray != pCurProc) {
SwitchToKernel (pcstk = &cstk);
}
fRet = g_pHdInit && g_pHdInit (&hd);
if (pcstk) {
SwitchBack ();
}
if (fRet) {
HDException = hd.pfnException;
HDPageIn = hd.pfnVmPageIn;
HDModLoad = hd.pfnModLoad;
HDModUnload = hd.pfnModUnload;
pdwHDTaintedModuleCount = hd.pdwTaintedModuleCount;
g_pHdEvent = hd.pEvent;
HDConnectClient = hd.pfnConnectClient;
s_fHdConnected = TRUE;
// Update the signature block so that OsAccess on host side can find it.
OsAxsDataBlock_2.fHdstubLoaded = TRUE;
}
}
else
{
DEBUGMSG(ZONE_DEBUGGER, (TEXT(" Nk!SC_ConnectHdstub: HD is already connected, ignoring connect request\r\n")));
fRet = TRUE;
}
return fRet;
}
//------------------------------------------------------------------------------
// OsAxs common Interface
//------------------------------------------------------------------------------
BOOL s_fOsAxsT0Connected = FALSE;
BOOL (*g_pOsAxsT0Init) (struct _HDSTUB_DATA *, void *);
BOOL s_fOsAxsT1Connected = FALSE;
void OsaxsT0Cleanup ()
{
g_pOsAxsT0Init = NULL;
s_fOsAxsT0Connected = FALSE;
}
static BOOL ConnectOsAxs(BOOL (*pInitFunc)(struct _HDSTUB_DATA *, void *))
{
BOOL fRet;
OSAXS_DATA osaxs = {
sizeof (OSAXS_DATA),
&KData,
&VAcs,
&NullSection,
&NKSection,
&hCoreDll,
&pCaptureDumpFileOnDevice,
SystemAPISets,
ProcArray,
pTOC,
LogPtr,
pKDIoControl,
NKKernelLibIoControl,
GetObjectPtrByType,
SC_CacheRangeFlush,
kdpIsROM,
DbgVerify,
DoThreadGetContext,
NKGetThreadCallStack,
SC_EventModify,
SC_GetSystemInfo,
SC_GetLastError,
SC_SetLastError,
INTERRUPTS_ENABLE,
#if defined(MIPS)
InterlockedDecrement,
InterlockedIncrement,
#endif
#ifdef x86
_except_handler3,
__abnormal_termination,
#else
__C_specific_handler,
#endif
MD_CBRtn,
NULL, // OEMGetRegDesc,
NULL, // OEMReadRegs,
NULL, // OEMWriteRegs
KCall,
NULL,
NULL,
NULL,
NULL,
pKITLIoCtl,
NKwvsprintfW
};
CALLSTACK *pcstk = NULL, cstk;
if (ProcArray != pCurProc) {
SwitchToKernel (pcstk = &cstk);
}
#if defined (SHx) && !defined (SH4) && !defined (SH3e)
osaxs.DSPFlushContext = DSPFlushContext;
#endif
#if defined (SH4) || defined (ARM) || defined (MIPS_HAS_FPU) || defined (x86)
osaxs.FPUFlushContext = FPUFlushContext;
#endif
#ifdef x86
osaxs.ppCurFPUOwner = &g_CurFPUOwner;
osaxs.pdwProcessorFeatures = &ProcessorFeatures;
#endif
fRet = pInitFunc && HDConnectClient &&
HDConnectClient ((HDSTUB_CLINIT_FUNC)pInitFunc, &osaxs);
if (pcstk) {
SwitchBack ();
}
return fRet;
}
BOOL SC_ConnectOsAxsT0(void *pvUnused)
{
BOOL fRet = FALSE;
TRUSTED_API (L"SC_ConnectOsAxsT0", FALSE);
if (!s_fOsAxsT0Connected)
{
fRet = ConnectOsAxs(g_pOsAxsT0Init);
if (fRet)
{
s_fOsAxsT0Connected = TRUE;
}
}
else
{
DEBUGMSG(ZONE_DEBUGGER, (TEXT(" Nk!SC_ConnectOsAxsT0: OsAxsT0 is already attached, ignoring connect request.\r\n")));
fRet = TRUE;
}
return fRet;
}
//------------------------------------------------------------------------------
// OsAxsT1 Interface
//------------------------------------------------------------------------------
BOOL (*g_pOsAxsT1Init)(struct _HDSTUB_DATA *, void *);
void OsaxsT1Cleanup()
{
g_pOsAxsT1Init = NULL;
s_fOsAxsT1Connected = FALSE;
}
BOOL SC_ConnectOsAxsT1(void *pvUnused)
{
BOOL fRet = FALSE;
TRUSTED_API (L"SC_ConnectOsAxsT1", FALSE);
if (!s_fOsAxsT1Connected)
{
CALLSTACK *pcstk = NULL, cstk;
if (ProcArray != pCurProc) {
SwitchToKernel (pcstk = &cstk);
}
fRet = ConnectOsAxs(g_pOsAxsT1Init);
if (pcstk) {
SwitchBack ();
}
if (fRet)
{
s_fOsAxsT1Connected = TRUE;
}
}
else
{
DEBUGMSG(ZONE_DEBUGGER, (TEXT(" Nk!SC_ConnectOsAxsT1: OsAxsT1 is already attached, ignoring connect request.\r\n")));
fRet = TRUE;
}
return fRet;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
KernelInit(void)
{
#ifdef DEBUG
lpWriteDebugStringFunc(TEXT("Windows CE KernelInit\r\n"));
#endif
/* setup the well known system API sets & API types */
SystemAPISets[SH_WIN32] = &cinfWin32;
SystemAPISets[SH_CURTHREAD] = &cinfThread;
SystemAPISets[SH_CURPROC] = &cinfProc;
SystemAPISets[SH_CURTOKEN] = &cinfToken;
SystemAPISets[HT_EVENT] = &cinfEvent;
SystemAPISets[HT_MUTEX] = &cinfMutex;
SystemAPISets[HT_SEMAPHORE] = &cinfSem;
SystemAPISets[HT_APISET] = &cinfAPISet;
SystemAPISets[HT_FILE] = &CinfFile;
SystemAPISets[HT_FIND] = &CinfFind;
SystemAPISets[HT_DBFILE] = &CinfDBFile;
SystemAPISets[HT_DBFIND] = &CinfDBFind;
SystemAPISets[HT_SOCKET] = &CinfSocket;
SystemAPISets[HT_FSMAP] = &cinfMap;
SystemAPISets[HT_WNETENUM] = &CinfWnetEnum;
KInfoTable[KINX_APISETS] = (DWORD)SystemAPISets;
HeapInit();
InitMemoryPool();
ProcInit();
SchedInit();
#ifdef DEBUG
lpWriteDebugStringFunc(TEXT("Scheduling the first thread.\r\n"));
#endif
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
KernelInit2(void)
{
HANDLE hKdLib;
ULONG nName;
LPCWSTR rgpszKdLibNames[] =
{
TEXT("kd.dll")
// more can be added in order of descending preference
};
fSysStarted = TRUE;
DEBUGMSG(1, (TEXT("KernelInit2: pCurThread=%8.8lx hCurThread=%8.8lx hCurProc=%8.8lx, KernelInit = %8.8lx\r\n"),
pCurThread, hCurThread, hCurProc, KernelInit));
#ifdef ARM
// Determine if ARM VFP hardware present (Will set vfpStat = 1)
DetectVFP ();
#endif
/* Bring up HdStub if present */
if (LoadKernelLibrary (TEXT ("hd.dll"))) {
if (g_pHdInit) {
DEBUGMSG(ZONE_DEBUGGER, (TEXT("Hdstub loaded\r\n")));
SC_ConnectHdstub ((void*)g_pHdInit);
}
}
/* Bring up OsAxsT0 if present */
if (LoadKernelLibrary (TEXT ("osaxst0.dll"))) {
if (g_pOsAxsT0Init) {
DEBUGMSG(ZONE_DEBUGGER, (TEXT("OsaxsT0 loaded\r\n")));
SC_ConnectOsAxsT0 (NULL);
}
}
/* Bring up OsAxsT1 if present */
if (LoadKernelLibrary (TEXT ("osaxst1.dll"))) {
if (g_pOsAxsT1Init) {
DEBUGMSG (ZONE_DEBUGGER, (TEXT("OsAxsT1 loaded\r\n")));
SC_ConnectOsAxsT1 (NULL);
}
}
/* initialize kernel debugger subsystem if present. */
for (nName = 0; nName < (sizeof(rgpszKdLibNames)/sizeof(LPCWSTR)); nName++) {
if (hKdLib = LoadKernelLibrary(rgpszKdLibNames[nName])) {
DEBUGMSG(ZONE_DEBUGGER, (TEXT("Debugger '%s' loaded\r\n"), rgpszKdLibNames[nName]));
if (g_pKdInit) {
SC_ConnectDebugger((VOID*)g_pKdInit);
} else {
ERRORMSG(1, (TEXT("'%s' is not a debugger DLL\r\n"), rgpszKdLibNames[nName]));
}
}
}
InitializeCriticalSection(&ODScs);
InitializeCriticalSection(&CompCS);
InitializeCriticalSection(&PhysCS);
InitializeCriticalSection(&VAcs);
InitializeCriticalSection(&LLcs);
InitializeCriticalSection(&ModListcs);
InitializeCriticalSection(&RFBcs);
InitializeCriticalSection(&MapCS);
InitializeCriticalSection(&NameCS);
InitializeCriticalSection(&WDcs);
InitializeCriticalSection(&EventCS);
InitializeCriticalSection(&MutexCS);
InitializeCriticalSection(&SemCS);
InitializeCriticalSection(&MapNameCS);
InitializeCriticalSection(&DbgApiCS);
InitializeCriticalSection(&PagerCS);
InitializeCriticalSection(&PageOutCS);
InitializeCriticalSection(&WriterCS);
InitializeCriticalSection(&IntChainCS);
InitializeCriticalSection(&DirtyPageCS);
// create the "Module section"
CreateSection ((LPVOID) MODULE_BASE_ADDRESS, FALSE);
CreateSection ((LPVOID) SHARED_BASE_ADDRESS, FALSE);
CreateSection ((LPVOID) RESOURCE_BASE_ADDRESS, FALSE);
DEBUGCHK (NULL_SECTION != SectionTable[MODULE_SECTION]);
DEBUGCHK (NULL_SECTION != SectionTable[SHARED_SECTION]);
DEBUGCHK (NULL_SECTION != SectionTable[RESOURCE_SECTION]);
// Load code-coverage buffer allocator from ROM if present
LoadKernelLibrary(TEXT("kcover.dll"));
// initialized profiler
ProfInit();
// Auto-load logger from ROM if present
LoadKernelLibrary(TEXT("CeLog.dll"));
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void SC_SetExceptionHandler(
PEXCEPTION_ROUTINE per
)
{
TRUSTED_API_VOID (L"SC_SetExceptionHandler");
pCurProc->pfnEH = per;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL
SC_Nop()
{
return TRUE;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL
SC_NotSupported()
{
KSetLastError(pCurThread,ERROR_NOT_SUPPORTED);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -