?? apis.c
字號:
/* Copyright (c) 1995-2000 Microsoft Corporation. All rights reserved. */
#include "windows.h"
#include "nkintr.h"
#include "bldver.h"
#include "osver.h"
#include "kernel.h"
#undef bIntrIndexHigh
#undef bIntrNumber
DWORD IsExiting;
#include "cscode.c"
/*
@doc BOTH EXTERNAL
@func BOOL | IsAPIReady | Tells whether the specified API set has been registered
@parm DWORD | hAPI | The predefined system handle of the desired API set (from syscall.h)
@comm During system initialization, some of the components may rely on other
components that are not yet loaded. IsAPIReady can be used to check
if the desired API set is available and thus avoid taking an exception.
*/
BOOL
IsAPIReady(
DWORD hAPI
)
{
if (hAPI > NUM_SYS_HANDLES)
return FALSE;
return (UserKInfo[KINX_API_MASK] & (1 << hAPI)) != 0;
}
#if defined(x86) || defined(PPC)
void DoPslFuncCall(DWORD flags, DWORD proc, DWORD thread, DWORD index) {
IMPLICIT_DECL(void, index, 0, (DWORD,DWORD,DWORD))(flags,proc,thread);
}
#endif
void PSLNotify(DWORD flags, DWORD proc, DWORD thread) {
DWORD loop = NUM_SYS_HANDLES;
while (--loop >= SH_LAST_NOTIFY)
if (UserKInfo[KINX_API_MASK] & (1 << loop)) {
#if defined(x86) || defined(PPC)
DoPslFuncCall(flags,proc,thread,loop);
#else
IMPLICIT_DECL(void, loop, 0, (DWORD,DWORD,DWORD))(flags,proc,thread);
#endif
}
}
// @func int | GetAPIAddress | Find API function address
// @rdesc Returns the function address of the requested API (0 if not valid)
// @parm int | setId | API Set index (via QueryAPISetID)
// @parm int | iMethod | method # within the API Set
// @comm Returns the kernel trap address used to invoke the given method within
// the given API Set.
FARPROC GetAPIAddress(int setId, int iMethod)
{
if (!IsAPIReady((DWORD)setId) || (iMethod > METHOD_MASK))
return 0;
return (FARPROC)IMPLICIT_CALL((DWORD)setId, (DWORD)iMethod);
}
/* Support functions which do simple things and then (usually) trap into the kernel */
/* Zero's out critical section info */
/*
@doc BOTH EXTERNAL
@func BOOL | GetVersionEx | Returns version information for the OS.
@parm LPOSVERSIONINFO | lpver | address of structure to fill in.
@comm Follows the Win32 reference description without restrictions or modifications.
*/
BOOL GetVersionEx(LPOSVERSIONINFO lpver) {
DEBUGCHK(lpver->dwOSVersionInfoSize >= sizeof(OSVERSIONINFO));
lpver->dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
lpver->dwMajorVersion = CE_VERSION_MAJOR;
lpver->dwMinorVersion = CE_VERSION_MINOR;
lpver->dwBuildNumber = CE_BUILD_VER;
lpver->dwPlatformId = VER_PLATFORM_WIN32_CE;
lpver->szCSDVersion[0] = '\0';
return TRUE;
}
extern BOOL xxx_SystemParametersInfo_GWE(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni);
BOOL SystemParametersInfoW(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni) {
BOOL retval = FALSE;
DWORD bytesused;
switch (uiAction) {
case SPI_GETPLATFORMTYPE:
case SPI_GETOEMINFO:
__try {
retval = KernelIoControl(IOCTL_HAL_GET_DEVICE_INFO,&uiAction,4,pvParam,uiParam,&bytesused);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
;
}
break;
default:
if (IsAPIReady(SH_WMGR))
retval = xxx_SystemParametersInfo_GWE(uiAction, uiParam, pvParam, fWinIni);
break;
}
return retval;
}
/* Alloc memory for stack, and then create thread (via kernel call) */
/*
@doc BOTH EXTERNAL
@func HANDLE | CreateThread | Creates a thread to execute within the address space of
the calling process.
@parm LPSECURITY_ATTRIBUTES | lpThreadAttributes | address of thread (<p must be NULL>.)
security attributes.
@parm DWORD | dwStackSize | initial thread stack size, in bytes. (<p must be 0>)
@parm LPTHREAD_START_ROUTINE | lpStartAddress | address of thread function
@parm LPVOID | lpParameter | argument for new thread
@parm DWORD | dwCreationFlags | creation flags
@parm LPDWORD | lpThreadId | address of returned thread identifier
@comm Follows the Win32 reference description with these restrictions:
Certain parameters must be set as indicated above.
*/
/* Create a process. Also creates an event to block on to synchronize the actual
loading of the process so we can get the return value correctly */
/*
@doc BOTH EXTERNAL
@func BOOL | CreateProcess | Creates a new process and its primary thread.
The new process executes the specified executable file.
@parm LPCTSTR | lpApplicationName | pointer to name of executable module
@parm LPTSTR | lpCommandLine | pointer to command line string
@parm LPSECURITY_ATTRIBUTES | lpProcessAttributes | <p Must be NULL> Pointer to process security attributes
@parm LPSECURITY_ATTRIBUTES | lpThreadAttributes | <p Must be NULL> Pointer to thread security attributes
@parm BOOL | bInheritHandles | <p Must be FALSE> Handle inheritance flag
@parm DWORD | dwCreationFlags | creation flag. <p See restrictions below>
@parm LPVOID | lpEnvironment | <p Must be NULL> Pointer to new environment block
@parm LPCTSTR | lpCurrentDirectory | <p Must be NULL> Pointer to current directory name
@parm LPSTARTUPINFO | lpStartupInfo | <p Must be NULL> Pointer to STARTUPINFO
@parm LPPROCESS_INFORMATION | lpProcessInformation | pointer to PROCESS_INFORMATION
@comm Follows the Win32 reference description with these restrictions:
Certain parameters must be set as indicated above.
The loader does not search a path. Only the following <p dwCreationFlags> parameters are
supported: CREATE_SUSPENDED. The command line cannot contain parameters and the parameter
list cannot contain the name of the executable as the first element. The parameters and
command line must be in the two variables, not combined in either one.
*/
/*
@doc BOTH EXTERNAL
@func BOOL | TerminateProcess | Terminates a process
@parm HANDLE | hProc | handle of process (ProcessID)
@parm DWORD | dwRetVal | return value of process (ignored)
@comm You cannot terminate a PSL.
You may not be able to terminate a process wedged inside a PSL.
*/
// To be called by init.exe when it's done.
VOID WINAPI SystemStarted(void) {
ERRORMSG(CeGetCurrentTrust() != OEM_CERTIFY_TRUST,(L"SystemStarted failed due to insufficient trust\r\n"));
if (CeGetCurrentTrust() == OEM_CERTIFY_TRUST)
PSLNotify(DLL_SYSTEM_STARTED,0,0);
}
VOID WINAPI SystemMemoryLow(void) {
PSLNotify(DLL_MEMORY_LOW,0,0);
}
/* Terminate thread routine */
/*
@doc BOTH EXTERNAL
@func VOID | ExitThread | Ends a thread.
@parm DWORD | dwExitCode | exit code for this thread
@comm Follows the Win32 reference description with the following restriction:
If the primary thread calls ExitThread, the application will exit
*/
VOID WINAPI ExitThread(DWORD dwExitCode) {
DWORD i = 0;
SetLastError(dwExitCode);
CloseProcOE(2);
if (IsPrimaryThread()) {
IsExiting = 1;
KillAllOtherThreads();
while (OtherThreadsRunning()) {
if (i < 2) {
if (++i == 2)
PSLNotify(DLL_PROCESS_EXITING,GetCurrentProcessId(),GetCurrentThreadId());
}
KillAllOtherThreads();
if (i > 1)
Sleep(250*(i-1));
}
ProcessDetachAllDLLs();
PSLNotify(DLL_PROCESS_DETACH,GetCurrentProcessId(),GetCurrentThreadId());
DebugNotify(DLL_PROCESS_DETACH,dwExitCode);
CloseProcOE(1);
CloseAllHandles();
} else {
if (!IsExiting) {
ThreadDetachAllDLLs();
PSLNotify(DLL_THREAD_DETACH,GetCurrentProcessId(),GetCurrentThreadId());
DebugNotify(DLL_THREAD_DETACH,dwExitCode);
}
CloseProcOE(0);
}
NKTerminateThread(dwExitCode);
}
/* Thread local storage routines (just like Win32) */
/*
@doc BOTH EXTERNAL
@func LPVOID | TlsGetValue | Retrieves the value in the calling thread's thread local
storage (TLS) slot for a specified TLS index. Each thread of a process has its own slot
for each TLS index.
@parm DWORD | dwTlsIndex | TLS index to retrieve value for
@comm Follows the Win32 reference description without restrictions or modifications.
*/
LPVOID WINAPI TlsGetValue(DWORD slot) {
LPDWORD tlsptr;
if (tlsptr = UTlsPtr())
return (LPVOID)tlsptr[slot];
return 0;
}
/*
@doc BOTH EXTERNAL
@func BOOL | TlsSetValue | Stores a value in the calling thread's thread local storage
(TLS) slot for a specified TLS index. Each thread of a process has its own slot for each
TLS index.
@parm DWORD | dwTlsIndex | TLS index to set value for
@parm LPVOID | lpvTlsValue | value to be stored
@comm Follows the Win32 reference description without restrictions or modifications.
*/
BOOL WINAPI TlsSetValue(DWORD slot, LPVOID value) {
LPDWORD tlsptr;
if (tlsptr = UTlsPtr()) {
tlsptr[slot] = (DWORD)value;
return TRUE;
}
return FALSE;
}
BOOL IsProcessDying() {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -