kernel.h
来自「WinCE5.0部分核心源码」· C头文件 代码 · 共 1,528 行 · 第 1/4 页
H
1,528 行
WORD refcnt[MAX_PROCESSES]; /* Reference count per process*/
LPVOID BasePtr; /* Base pointer of dll load (not 0 based) */
DWORD DbgFlags; /* Debug flags */
LPDBGPARAM ZonePtr; /* Debug zone pointer */
ulong startip; /* 0 based entrypoint */
openexe_t oe; /* Pointer to executable file handle */
e32_lite e32; /* E32 header */
o32_lite *o32_ptr; /* O32 chain ptr */
DWORD dwNoNotify; /* 1 bit per process, set if notifications disabled */
WORD wFlags;
BYTE bTrustLevel;
BYTE bPadding;
PMODULE pmodResource; /* module that contains the resources */
DWORD rwLow; /* base address of RW section for ROM DLL */
DWORD rwHigh; /* high address RW section for ROM DLL */
PGPOOL_Q pgqueue; /* list of the page owned by the module */
LPVOID pShimInfo; /* pointer to shim information */
} Module;
// List of all modules
#define pModList ((PMODULE)KInfoTable[KINX_MODULES])
#define HasModRefProcPtr(pMod,pProc) ((pMod)->refcnt[(pProc)->procnum] != 0)
#define HasModRefProcIndex(pMod,iProc) ((pMod)->refcnt[(iProc)] != 0)
#define AllowThreadMessage(pMod,pProc) (!((pMod)->dwNoNotify & (1 << (pProc)->procnum)))
// Module code is now fixed-up to slot 1 (treated as an ABS address)
#define MODULE_SECTION 1
#define MODULE_BASE_ADDRESS (MODULE_SECTION << VA_SECTION)
#define MODULE_SECTION_END (2 << VA_SECTION)
#define IsModCodeAddr(addr) (((DWORD) (addr) >> VA_SECTION) == MODULE_SECTION)
typedef struct FSMAP *LPFSMAP;
typedef struct FSMAP {
HANDLE hNext; /* Next map in list */
HANDLE hFile; /* File, or INVALID_HANDLE_VALUE for just vm */
LPBYTE pBase; /* pointer to start of kernel mapped region */
LPBYTE pDirty; /* non-null if r/w real file, points to dirty bitmap */
DWORD length; /* length of mapped region */
DWORD filelen; /* length of file if hFile != INVALID_HANDLE_VALUE */
DWORD reslen; /* length of reservation */
Name* name; /* points to name of event */
CLEANEVENT *lpmlist; /* List of mappings */
DWORD dwDirty; /* Count of dirty pages */
BYTE bRestart; /* Has been flushed */
BYTE bNoAutoFlush; /* Disallow automatic flushing */
BYTE bDirectROM; /* File mapped directly from ROM */
BYTE bFlushFlags; /* Flush flags */
PGPOOL_Q pgqueue; /* list of the page owned by the mapfile */
} FSMAP;
// Lowest DLL load address
#define DllLoadBase KInfoTable[KINX_DLL_LOW]
#define DBG_IS_DEBUGGER 0x00000001
#define DBG_SYMBOLS_LOADED 0x80000000
#define PAGEALIGN_UP(X) (((X)+(PAGE_SIZE-1))&~(PAGE_SIZE-1))
#define PAGEALIGN_DOWN(X) ((X)&~(PAGE_SIZE-1))
#define STACK_RESERVE 15
#define MIN_PROCESS_PAGES STACK_RESERVE
// LOG_MAGIC, mem_t, fslogentry_t, and fslog_t MUST be kept in sync with filesys.h version
#define LOG_MAGIC 0x4d494b45
typedef struct mem_t {
DWORD startptr;
DWORD length;
DWORD extension;
} mem_t;
typedef struct fslogentry_t {
DWORD type;
DWORD d1, d2, d3;
} fslogentry_t;
typedef struct fshash_t {
DWORD hashdata[4];
} fshash_t;
#define CURRENT_FSLOG_VERSION 0x400
// MUST be kept in sync with data structure in coreos\filesys\filesys.h
#define MAX_MEMORY_SECTIONS 16
#pragma warning(disable:4200) // nonstandard extensions warning
typedef struct fslog_t {
DWORD version; // version of this structure, must stay as first DWORD
DWORD magic1; // LOG_MAGIC if memory tables valid
DWORD magic2; // LOG_MAGIC if heap initialized
union {
struct { // SystemHeap contains this data
mem_t fsmemblk[MAX_MEMORY_SECTIONS]; // Memory blocks to use for file system
LPBYTE pFSList;
LPBYTE pKList;
};
struct { // All other heaps contain this data
CEGUID guid;
DWORD dwRestoreFlags;
DWORD dwRestoreStart;
DWORD dwRestoreSize;
fshash_t ROMSignature; // Hives only: signature of the hive in ROM
};
};
fshash_t pwhash; // hashed password (stored in SystemHeap or system hive)
DWORD virtbase; // VirtBase when last booted
DWORD entries; // number of entries in recovery log
DWORD hDbaseRoot; // handle to first dbase, else INVALID_HDB
DWORD hReg; // Handle to registry header, else INVALID_HREG
DWORD dwReplInfo; // Persistent replication information
DWORD flags; // file system flags. High 24 bits are dbase LCID
fslogentry_t log[]; // log entries
} fslog_t;
// OID macros from filesys - keep in sync with macros in filesys.h
#define SYSTEM_INROM 0x1
#define SYSTEM_FROM_OID(oid) ((oid) >> 28)
#define IS_ROMFILE_OID(oid) (SYSTEM_FROM_OID(oid) == SYSTEM_INROM)
#define ROMFILE_FROM_OID(oid, type, index) \
((type = ((oid) >> 12) & 0xf), (index = ((oid) & 0x00000fff)))
#pragma warning(default:4200) // nonstandard extensions warning
LPVOID AllocMem(ulong poolnum);
VOID FreeMem(LPVOID pMem, ulong poolnum);
LPName AllocName(DWORD dwLen);
#define FreeName(lpn) FreeMem(lpn,lpn->wPool);
PHYSICAL_ADDRESS GetHeldPage(void);
PHYSICAL_ADDRESS GetReservedPage(void);
PHYSICAL_ADDRESS GetContiguousPages(DWORD dwPages, DWORD dwAlignment, DWORD dwFlags);
BOOL HoldPages(int cpNeed, BOOL bForce);
void DupPhysPage(PHYSICAL_ADDRESS paPFN);
void FreePhysPage(PHYSICAL_ADDRESS paPFN);
LPVOID InitNKSection(void);
BOOL AutoCommit(ulong addr);
DWORD DemandCommit(DWORD, PTHREAD);
#define DCMT_FAILED 0 // demand commit failed
#define DCMT_NEW 1 // committed a new page
#define DCMT_OLD 2 // page already commited
void NKGetStackLimits (PTHREAD pth, LPDWORD pLL, LPDWORD pHL);
void GuardCommit(ulong addr);
BOOL ProcessPageFault(BOOL bWrite, ulong addr);
void FreeSection(PSECTION pscn);
PSECTION GetSection(void);
LPVOID GetHelperStack(void);
void FreeHelperStack(LPVOID);
BOOL CreateMapperSection(DWORD dwBase, BOOL fAddProtect);
void DeleteMapperSection(DWORD dwBase);
void CloseMappedFileHandles();
void FreeIntrFromEvent(LPEVENT lpe);
void EnterPhysCS(void);
BOOL ScavengeStacks(int cNeed);
void CreateNewProc(ulong nextfunc, ulong param);
void KernelInit2(void);
void AlarmThread(LPVOID param);
void RunApps(ulong param);
extern LPCWSTR FindModuleNameAndOffset (DWORD dwPC, LPDWORD pdwOffset);
#if x86
void InitNPXHPHandler(LPVOID);
void InitializeEmx87(void);
void InitializeFPU(void);
extern DWORD dwFPType;
#endif
/** Return values from AutoCommit(...): */
#define AUTO_COMMIT_RESCHED 0
#define AUTO_COMMIT_HANDLED 1
#define AUTO_COMMIT_FAULT 2
void SetCPUASID(PTHREAD pth);
#ifdef SHx
void SetCPUGlobals(void);
#endif
LPVOID VerifyAccess(LPVOID pvAddr, DWORD dwFlags, ACCESSKEY aky);
BOOL IsAccessOK(void *addr, ACCESSKEY aky);
void KUnicodeToAscii(LPCHAR, LPCWSTR, int);
void KAsciiToUnicode(LPWSTR wchptr, LPBYTE chptr, int maxlen);
LPVOID GetOneProcAddress(HANDLE, LPCVOID, BOOL);
PMODULE LoadOneLibraryW (LPCWSTR lpszFileName, DWORD fLbFlags, WORD dwFlags);
VOID FreeAllProcLibraries(PPROCESS);
PVOID PDataFromPC(ULONG pc, PPROCESS pProc, PULONG pSize);
LPVOID SC_GetProcAddressW(HANDLE hInst, LPWSTR lpszProc);
LPVOID SC_GetProcAddressA(HANDLE hInst, LPCSTR lpszProc);
BOOL SC_DisableThreadLibraryCalls(PMODULE hLibModule);
LPWSTR SC_GetCommandLineW(VOID);
PFNVOID DBG_CallCheck(PTHREAD pth, DWORD dwJumpAddress, PCONTEXT pCtx);
#define DBG_ReturnCheck(pth) ((pth)->pcstkTop ? (pth)->pcstkTop->retAddr : 0)
BOOL UserDbgTrap(EXCEPTION_RECORD *er, PCONTEXT pctx, BOOL bFirst);
void SurrenderCritSecs(void);
BOOL SetThreadBasePrio(HANDLE hth, DWORD nPriority);
HANDLE EventModIntr(LPEVENT lpe, DWORD type);
VOID MakeRunIfNeeded(HANDLE hth);
extern void (*TBFf)(LPVOID, ulong);
extern void (*MTBFf)(LPVOID, ulong, ulong, ulong, ulong);
extern void (*CTBFf)(LPVOID, ulong, ulong, ulong, ulong);
extern BOOL (*KSystemTimeToFileTime)(LPSYSTEMTIME, LPFILETIME);
extern LONG (*KCompareFileTime)(LPFILETIME, LPFILETIME);
extern BOOL (*KFileTimeToSystemTime)(const FILETIME *, LPSYSTEMTIME);
extern BOOL (*KLocalFileTimeToFileTime)(const FILETIME *, LPFILETIME);
extern void (*pPSLNotify)(DWORD, DWORD, DWORD);
extern void (*pSignalStarted)(DWORD);
extern BOOL (*pGetHeapSnapshot)(THSNAP *pSnap, BOOL bMainOnly, LPVOID *pDataPtr, HANDLE hProc);
#ifdef IN_KERNEL
extern ROMHDR * const volatile pTOC;
#endif
void KernelRelocate(ROMHDR *const pTOC);
void KernelFindMemory(void);
BOOL FindROMFile(DWORD dwType, DWORD dwFileIndex, LPVOID* ppAddr, DWORD* pLen);
extern ROMChain_t *ROMChain;
DWORD CECompress(LPBYTE lpbSrc, DWORD cbSrc, LPBYTE lpbDest, DWORD cbDest, WORD wStep, DWORD dwPagesize);
DWORD CEDecompress(LPBYTE lpbSrc, DWORD cbSrc, LPBYTE lpbDest, DWORD cbDest, DWORD dwSkip, WORD wStep, DWORD dwPagesize);
DWORD CEDecompressROM(LPBYTE lpbSrc, DWORD cbSrc, LPBYTE lpbDest, DWORD cbDest, DWORD dwSkip, WORD wStep, DWORD dwPagesize);
extern BOOL g_fCompressionSupported;
typedef struct LSInfo_t {
PTHREAD pHelper;// must be first
HTHREAD hth; // hthread to start
DWORD startip; // starting ip after switch
DWORD flags; // creation flags
LPBYTE pCurSP; // pointer to current stack top (cmdline and prgname on stack already)
LPBYTE lpOldStack; // pointer to old stack
HANDLE hEvent; // event to signal
} LSInfo_t;
extern HANDLE hAlarmThreadWakeup;
DWORD ThreadSuspend(PTHREAD hTh, BOOL fLateSuspend);
void BlockWithHelper(FARPROC pFunc, FARPROC pHelpFunc, LPVOID param);
void BlockWithHelperAlloc(FARPROC pFunc, FARPROC pHelpFunc, LPVOID param);
int ropen(WCHAR *name, int mode);
int rread(int fd, char *buf, int cnt);
int rreadseek(int fd, char *buf, int cnt, int off);
int rlseek(int fd, int off, int mode);
int rclose(int fd);
int rwrite(int fd, char *buf, int cnt);
void kstrcpyW(LPWSTR p1, LPCWSTR p2);
unsigned int strlenW(LPCWSTR str);
unsigned int strlen(const char *str);
int strcmpiAandW(LPCHAR lpa, LPCWSTR lpu);
int kstrcmpi(LPCWSTR str1, LPCWSTR str2);
int strcmpW(LPCWSTR lpu1, LPCWSTR lpu2);
int strcmp(const char *lpc1, const char *lpc2);
LPVOID memset(LPVOID dest, int c, unsigned int count);
LPVOID memcpy(LPVOID dest, const void *src, unsigned int count);
#if HARDWARE_PT_PER_PROC
void InvalidateRange(PVOID, ULONG);
#else
// need to invalidate the whole TLB since there might be aliasing somewhere
#define InvalidateRange(x, y) OEMCacheRangeFlush (0, 0, CACHE_SYNC_FLUSH_TLB)
#endif
#if defined(WIN32_CALL) && !defined(KEEP_SYSCALLS)
#undef InputDebugCharW
int WINAPI InputDebugCharW(void);
#undef OutputDebugStringW
VOID WINAPI OutputDebugStringW(LPCWSTR str);
#undef NKvDbgPrintfW
VOID NKvDbgPrintfW(LPCWSTR lpszFmt, CONST VOID * lpParms);
#endif
void DumpStringToSerial(LPCWSTR);
HANDLE DoCreateThread(LPVOID lpStack, DWORD cbStack, LPVOID lpStart, LPVOID param, DWORD flags, LPDWORD lpthid, ulong mode, WORD prio);
LPVOID CreateSection(LPVOID lpvAddr, BOOL fInitKPage);
VOID DeleteSection(LPVOID lpvSect);
LPVOID HugeVirtualReserve(DWORD dwSize, DWORD dwFlags);
BOOL HugeVirtualRelease(LPVOID pMem);
void InitMUILanguages(void);
int NKwvsprintfW(LPWSTR lpOut, LPCWSTR lpFmt, CONST VOID *lpParms, int maxchars);
// NOTE: MDAllocMemBlock MUST Initialize memblock entries
// Caller of MDAllocMemBlock will NOT memset it to 0,
// or it'll zero'd the aPages pointer for CPUs using
// hardware page table (x86/ARM)
//
MEMBLOCK *MDAllocMemBlock (DWORD dwBase, DWORD ixBlock);
void MDFreeMemBlock (MEMBLOCK * pmb);
BOOL DoThreadSetContext(HANDLE hTh, const CONTEXT *lpContext);
BOOL DoThreadGetContext(HANDLE hTh, LPCONTEXT lpContext);
BOOL ChangeMapFlushing(LPCVOID lpBaseAddress, DWORD dwFlags);
DWORD DoGetModuleFileName (HMODULE hModule, LPWSTR lpFilename, DWORD nSize);
//
// watchdog support
//
BOOL InitWatchDog (void);
BOOL WDDelete (HANDLE hWDog);
DWORD WatchDogAPI (DWORD apiCode, PCWDAPIStruct pwdas);
extern fslog_t *LogPtr;
#ifdef IN_KERNEL
#ifdef __cplusplus
extern "C" {
#endif
// Function to switch process to kernel and back
void SwitchToKernel (PCALLSTACK pcstk);
void SwitchBack (void);
#ifdef __cplusplus
}
#endif
#define SetNKCallOut(pth) (KTHRDINFO(pth) |= UTLS_NKCALLOUT)
#define ClearNKCallOut(pth) (KTHRDINFO(pth) &= ~UTLS_NKCALLOUT)
DWORD PerformCallBack4Int(CALLBACKINFO *pcbi, ...);
#undef ResumeThread
#define ResumeThread SC_ThreadResume
#undef SuspendThread
#define SuspendThread SC_ThreadSuspend
#undef GetTickCount
#define GetTickCount SC_GetTickCount
#undef CreateFileForMappingW
#define CreateFileForMappingW SC_CreateFileForMapping
#undef CreateFileMapping
#define CreateFileMapping SC_CreateFileMapping
#undef MapViewOfFile
#define MapViewOfFile SC_MapViewOfFile
#undef UnmapViewOfFile
#define UnmapViewOfFile SC_UnmapViewOfFile
#undef VirtualAlloc
#define VirtualAlloc SC_VirtualAlloc
#undef VirtualQuery
#define VirtualQuery SC_VirtualQuery
#undef VirtualProtect
#define VirtualProtect SC_VirtualProtect
#undef VirtualCopy
#define VirtualCopy DoVirtualCopy
#undef VirtualSetAttributes
#define VirtualSetAttributes NKVirtualSetAttributes
#undef LockPages
#define LockPages DoLockPages
#undef UnlockPages
#define UnlockPages DoUnlockPages
#undef AllocPhysMem
#define AllocPhysMem SC_AllocPhysMem
#undef FreePhysMem
#define FreePhysMem SC_FreePhysMem
#undef VirtualFree
#define VirtualFree SC_VirtualFree
#undef SetThreadPriority // don't use - confusing with two sets of prio numbers
#undef TakeCritSec
#define TakeCritSec SC_TakeCritSec
#undef LeaveCritSec
#define LeaveCritSec SC_LeaveCritSec
#undef CreateCrit
#define CreateCrit SC_CreateCrit
#undef GetProcAddressA
#define GetProcAddressA SC_GetProcAddressA
#undef GetProcAddressW
#define GetProcAddressW SC_GetProcAddressW
#undef CreateProcessW
#define CreateProcessW SC_CreateProc
#undef WaitForMultipleObjects
#define WaitForMultipleObjects SC_WaitForMultiple
#undef CreateEventW
#define CreateEventW SC_CreateEvent
#undef OpenEventW
#define OpenEventW SC_OpenEvent
#undef EventModify
#define EventModify SC_EventModify
#undef Sleep
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?