本文整理汇总了C++中NtCurrentTeb函数的典型用法代码示例。如果您正苦于以下问题:C++ NtCurrentTeb函数的具体用法?C++ NtCurrentTeb怎么用?C++ NtCurrentTeb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NtCurrentTeb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConvertThreadToFiberEx
/*
* @implemented
*/
LPVOID
WINAPI
ConvertThreadToFiberEx(LPVOID lpParameter,
DWORD dwFlags)
{
PTEB pTeb = NtCurrentTeb();
PFIBER pfCurFiber;
DPRINT1("Converting Thread to Fiber\n");
/* the current thread is already a fiber */
if(pTeb->HasFiberData && pTeb->NtTib.FiberData) return pTeb->NtTib.FiberData;
/* allocate the fiber */
pfCurFiber = (PFIBER)RtlAllocateHeap(GetProcessHeap(),
0,
sizeof(FIBER));
/* failure */
if (pfCurFiber == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
/* copy some contextual data from the thread to the fiber */
pfCurFiber->Parameter = lpParameter;
pfCurFiber->ExceptionList = pTeb->NtTib.ExceptionList;
pfCurFiber->StackBase = pTeb->NtTib.StackBase;
pfCurFiber->StackLimit = pTeb->NtTib.StackLimit;
pfCurFiber->DeallocationStack = pTeb->DeallocationStack;
pfCurFiber->FlsData = pTeb->FlsData;
pfCurFiber->GuaranteedStackBytes = pTeb->GuaranteedStackBytes;
pfCurFiber->ActivationContextStack = pTeb->ActivationContextStackPointer;
pfCurFiber->Context.ContextFlags = CONTEXT_FULL;
/* Save FPU State if requsted */
if (dwFlags & FIBER_FLAG_FLOAT_SWITCH)
{
pfCurFiber->Context.ContextFlags |= CONTEXT_FLOATING_POINT;
}
/* associate the fiber to the current thread */
pTeb->NtTib.FiberData = pfCurFiber;
pTeb->HasFiberData = TRUE;
/* success */
return (LPVOID)pfCurFiber;
}
示例2: debug_IsStackPointer
bool debug_IsStackPointer(void* p)
{
uintptr_t addr = (uintptr_t)p;
// totally invalid pointer
if(debug_IsPointerBogus(p))
return false;
// not aligned
if(addr % sizeof(void*))
return false;
// out of bounds (note: IA-32 stack grows downwards)
NT_TIB* tib = (NT_TIB*)NtCurrentTeb();
if(!(tib->StackLimit < p && p < tib->StackBase))
return false;
return true;
}
示例3: NE_InitDLL
/***********************************************************************
* NE_InitDLL
*
* Call the DLL initialization code
*/
static BOOL NE_InitDLL( NE_MODULE *pModule )
{
SEGTABLEENTRY *pSegTable;
WORD hInst, ds, heap;
CONTEXT context;
pSegTable = NE_SEG_TABLE( pModule );
if (!(pModule->ne_flags & NE_FFLAGS_LIBMODULE) ||
(pModule->ne_flags & NE_FFLAGS_WIN32)) return TRUE; /*not a library*/
/* Call USER signal handler for Win3.1 compatibility. */
NE_CallUserSignalProc( pModule->self, USIG16_DLL_LOAD );
if (!SELECTOROF(pModule->ne_csip)) return TRUE; /* no initialization code */
/* Registers at initialization must be:
* cx heap size
* di library instance
* ds data segment if any
* es:si command line (always 0)
*/
memset( &context, 0, sizeof(context) );
NE_GetDLLInitParams( pModule, &hInst, &ds, &heap );
context.Ecx = heap;
context.Edi = hInst;
context.SegDs = ds;
context.SegEs = ds; /* who knows ... */
context.SegFs = wine_get_fs();
context.SegGs = wine_get_gs();
context.SegCs = SEL(pSegTable[SELECTOROF(pModule->ne_csip)-1].hSeg);
context.Eip = OFFSETOF(pModule->ne_csip);
context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp);
pModule->ne_csip = 0; /* Don't initialize it twice */
TRACE_(dll)("Calling LibMain for %.*s, cs:ip=%04x:%04x ds=%04x di=%04x cx=%04x\n",
*((BYTE*)pModule + pModule->ne_restab),
(char *)pModule + pModule->ne_restab + 1,
context.SegCs, context.Eip, context.SegDs,
LOWORD(context.Edi), LOWORD(context.Ecx) );
WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)&context );
return TRUE;
}
示例4: SetGraphicsMode
/*
* @unimplemented
*/
int
WINAPI
SetGraphicsMode(
_In_ HDC hdc,
_In_ int iMode)
{
INT iOldMode;
PDC_ATTR pdcattr;
/* Check parameters */
if ((iMode < GM_COMPATIBLE) || (iMode > GM_ADVANCED))
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
/* Get the DC attribute */
pdcattr = GdiGetDcAttr(hdc);
if (pdcattr == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
/* Check for trivial case */
if (iMode == pdcattr->iGraphicsMode)
return iMode;
if (NtCurrentTeb()->GdiTebBatch.HDC == hdc)
{
if (pdcattr->ulDirty_ & DC_MODE_DIRTY)
{
NtGdiFlush(); // Sync up pdcattr from Kernel space.
pdcattr->ulDirty_ &= ~(DC_MODE_DIRTY|DC_FONTTEXT_DIRTY);
}
}
/* One would think that setting the graphics mode to GM_COMPATIBLE
* would also reset the world transformation matrix to the unity
* matrix. However, in Windows, this is not the case. This doesn't
* make a lot of sense to me, but that's the way it is.
*/
iOldMode = pdcattr->iGraphicsMode;
pdcattr->iGraphicsMode = iMode;
return iOldMode;
}
示例5: __except_validate_context_record
void
__except_validate_context_record (
_In_ PCONTEXT ContextRecord
)
/*++
Routine Description:
This function validates a context record for exception handling support.
Arguments:
ContextRecord - Supplies a pointer to the context record to validate.
Return Value:
None. If the context record was not valid, a fast fail event is raised if
CFG was enforced.
--*/
{
PVOID StackPointer;
PNT_TIB Tib;
//
// If guard ICall checks are enforced, then validate the stack extents of
// the context record and raise a fast fail exception if the extents are
// invalid. If checks are not enforced or the jump buffer was valid, then
// return.
//
if (_guard_icall_checks_enforced()) {
Tib = (PNT_TIB)NtCurrentTeb();
//
// HYB-TODO: Validate both chpe and guest context.
//
StackPointer = (PVOID)CONTEXT_TO_STACK_POINTER(ContextRecord);
if ((StackPointer < Tib->StackLimit) ||
(StackPointer > Tib->StackBase)) {
__fastfail(FAST_FAIL_INVALID_SET_OF_CONTEXT);
}
}
}
示例6: SystemHeapInfo16
/***********************************************************************
* SystemHeapInfo (TOOLHELP.71)
*/
BOOL16 WINAPI SystemHeapInfo16( SYSHEAPINFO *pHeapInfo )
{
STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
HANDLE16 oldDS = stack16->ds;
WORD user = LoadLibrary16( "USER.EXE" );
WORD gdi = LoadLibrary16( "GDI.EXE" );
stack16->ds = user;
pHeapInfo->wUserFreePercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
stack16->ds = gdi;
pHeapInfo->wGDIFreePercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
stack16->ds = oldDS;
pHeapInfo->hUserSegment = user;
pHeapInfo->hGDISegment = gdi;
FreeLibrary16( user );
FreeLibrary16( gdi );
return TRUE;
}
示例7: NE_CallDllEntryPoint
static void NE_CallDllEntryPoint( NE_MODULE *pModule, DWORD dwReason )
{
WORD hInst, ds, heap;
FARPROC16 entryPoint;
if (!(pModule->ne_flags & NE_FFLAGS_LIBMODULE)) return;
if (!(pModule->ne_flags & NE_FFLAGS_BUILTIN) && pModule->ne_expver < 0x0400) return;
if (!(entryPoint = GetProcAddress16( pModule->self, "DllEntryPoint" ))) return;
NE_GetDLLInitParams( pModule, &hInst, &ds, &heap );
TRACE_(dll)( "Calling %s DllEntryPoint, cs:ip=%04x:%04x\n",
NE_MODULE_NAME( pModule ),
SELECTOROF(entryPoint), OFFSETOF(entryPoint) );
if ( pModule->ne_flags & NE_FFLAGS_BUILTIN )
{
WinNEEntryProc entryProc = (WinNEEntryProc)((ENTRYPOINT16 *)MapSL( (SEGPTR)entryPoint ))->target;
entryProc( dwReason, hInst, ds, heap, 0, 0 );
}
else
{
CONTEXT context;
WORD args[8];
memset( &context, 0, sizeof(context) );
context.SegDs = ds;
context.SegEs = ds; /* who knows ... */
context.SegFs = wine_get_fs();
context.SegGs = wine_get_gs();
context.SegCs = HIWORD(entryPoint);
context.Eip = LOWORD(entryPoint);
context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp);
args[7] = HIWORD(dwReason);
args[6] = LOWORD(dwReason);
args[5] = hInst;
args[4] = ds;
args[3] = heap;
args[2] = 0; /* HIWORD(dwReserved1) */
args[1] = 0; /* LOWORD(dwReserved1) */
args[0] = 0; /* wReserved2 */
WOWCallback16Ex( 0, WCB16_REGS, sizeof(args), args, (DWORD *)&context );
}
}
示例8: CreateMutexA
HANDLE
APIENTRY
CreateMutexA(
LPSECURITY_ATTRIBUTES lpMutexAttributes,
BOOL bInitialOwner,
LPCSTR lpName
)
/*++
Routine Description:
ANSI thunk to CreateMutexW
--*/
{
PUNICODE_STRING Unicode;
ANSI_STRING AnsiString;
NTSTATUS Status;
LPCWSTR NameBuffer;
NameBuffer = NULL;
if ( ARGUMENT_PRESENT(lpName) ) {
Unicode = &NtCurrentTeb()->StaticUnicodeString;
RtlInitAnsiString(&AnsiString,lpName);
Status = RtlAnsiStringToUnicodeString(Unicode,&AnsiString,FALSE);
if ( !NT_SUCCESS(Status) ) {
if ( Status == STATUS_BUFFER_OVERFLOW ) {
SetLastError(ERROR_FILENAME_EXCED_RANGE);
}
else {
BaseSetLastNTError(Status);
}
return NULL;
}
NameBuffer = (LPCWSTR)Unicode->Buffer;
}
return CreateMutexW(
lpMutexAttributes,
bInitialOwner,
NameBuffer
);
}
示例9: OpenFileMappingA
HANDLE
APIENTRY
OpenFileMappingA(
DWORD dwDesiredAccess,
BOOL bInheritHandle,
LPCSTR lpName
)
/*++
Routine Description:
ANSI thunk to OpenFileMappingW
--*/
{
PUNICODE_STRING Unicode;
ANSI_STRING AnsiString;
NTSTATUS Status;
if ( ARGUMENT_PRESENT(lpName) ) {
Unicode = &NtCurrentTeb()->StaticUnicodeString;
RtlInitAnsiString(&AnsiString,lpName);
Status = RtlAnsiStringToUnicodeString(Unicode,&AnsiString,FALSE);
if ( !NT_SUCCESS(Status) ) {
if ( Status == STATUS_BUFFER_OVERFLOW ) {
SetLastError(ERROR_FILENAME_EXCED_RANGE);
}
else {
BaseSetLastNTError(Status);
}
return NULL;
}
}
else {
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
return NULL;
}
return OpenFileMappingW(
dwDesiredAccess,
bInheritHandle,
(LPCWSTR)Unicode->Buffer
);
}
示例10: UserDbgAssertThreadInfo
void UserDbgAssertThreadInfo(BOOL showCaller)
{
PTEB Teb;
PPROCESSINFO ppi;
PCLIENTINFO pci;
PTHREADINFO pti;
ppi = PsGetCurrentProcessWin32Process();
pti = PsGetCurrentThreadWin32Thread();
Teb = NtCurrentTeb();
pci = GetWin32ClientInfo();
ASSERT(Teb);
ASSERT(pti);
ASSERT(pti->ppi == ppi);
ASSERT(pti->pClientInfo == pci);
ASSERT(Teb->Win32ThreadInfo == pti);
ASSERT(pci->ppi == ppi);
ASSERT(pci->fsHooks == pti->fsHooks);
ASSERT(pci->ulClientDelta == DesktopHeapGetUserDelta());
if (pti->pcti && pci->pDeskInfo)
ASSERT(pci->pClientThreadInfo == (PVOID)((ULONG_PTR)pti->pcti - pci->ulClientDelta));
if (pti->pcti && IsListEmpty(&pti->SentMessagesListHead))
ASSERT((pti->pcti->fsChangeBits & QS_SENDMESSAGE) == 0);
if (pti->KeyboardLayout)
ASSERT(pci->hKL == pti->KeyboardLayout->hkl);
if(pti->rpdesk != NULL)
ASSERT(pti->pDeskInfo == pti->rpdesk->pDeskInfo);
/*too bad we still get this assertion*/
// Why? Not all flags are passed to the user and doing so could crash the system........
/* ASSERT(pci->dwTIFlags == pti->TIF_flags); */
/* if(pci->dwTIFlags != pti->TIF_flags)
{
ERR("pci->dwTIFlags(0x%x) doesn't match pti->TIF_flags(0x%x)\n", pci->dwTIFlags, pti->TIF_flags);
if(showCaller)
{
DbgPrint("Caller:\n");
KeRosDumpStackFrames(NULL, 10);
}
pci->dwTIFlags = pti->TIF_flags;
}
*/
}
示例11: SetROP2
/*
* @implemented
*/
int
WINAPI
SetROP2(HDC hdc,
int fnDrawMode)
{
PDC_ATTR Dc_Attr;
INT Old_ROP2;
#if 0
// Handle something other than a normal dc object.
if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
{
if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
return MFDRV_SetROP2( hdc, fnDrawMode);
else
{
PLDC pLDC = GdiGetLDC(hdc);
if ( !pLDC )
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (pLDC->iType == LDC_EMFLDC)
{
return EMFDRV_SetROP2(( hdc, fnDrawMode);
}
return FALSE;
}
}
#endif
if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
if (NtCurrentTeb()->GdiTebBatch.HDC == hdc)
{
if (Dc_Attr->ulDirty_ & DC_MODE_DIRTY)
{
NtGdiFlush();
Dc_Attr->ulDirty_ &= ~DC_MODE_DIRTY;
}
}
Old_ROP2 = Dc_Attr->jROP2;
Dc_Attr->jROP2 = fnDrawMode;
return Old_ROP2;
}
示例12: NE_InitDLL
/***********************************************************************
* NE_InitDLL
*
* Call the DLL initialization code
*/
static BOOL NE_InitDLL( NE_MODULE *pModule )
{
SEGTABLEENTRY *pSegTable;
WORD hInst, ds, heap;
CONTEXT86 context;
pSegTable = NE_SEG_TABLE( pModule );
if (!(pModule->flags & NE_FFLAGS_LIBMODULE) ||
(pModule->flags & NE_FFLAGS_WIN32)) return TRUE; /*not a library*/
/* Call USER signal handler for Win3.1 compatibility. */
TASK_CallTaskSignalProc( USIG16_DLL_LOAD, pModule->self );
if (!pModule->cs) return TRUE; /* no initialization code */
/* Registers at initialization must be:
* cx heap size
* di library instance
* ds data segment if any
* es:si command line (always 0)
*/
memset( &context, 0, sizeof(context) );
NE_GetDLLInitParams( pModule, &hInst, &ds, &heap );
context.Ecx = heap;
context.Edi = hInst;
context.SegDs = ds;
context.SegEs = ds; /* who knows ... */
context.SegCs = SEL(pSegTable[pModule->cs-1].hSeg);
context.Eip = pModule->ip;
context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + (WORD)&((STACK16FRAME*)0)->bp;
pModule->cs = 0; /* Don't initialize it twice */
TRACE_(dll)("Calling LibMain, cs:ip=%04lx:%04lx ds=%04lx di=%04x cx=%04x\n",
context.SegCs, context.Eip, context.SegDs,
LOWORD(context.Edi), LOWORD(context.Ecx) );
wine_call_to_16_regs_short( &context, 0 );
return TRUE;
}
示例13: NE_CallDllEntryPoint
static void NE_CallDllEntryPoint( NE_MODULE *pModule, DWORD dwReason )
{
WORD hInst, ds, heap;
FARPROC16 entryPoint;
if (!(pModule->flags & NE_FFLAGS_LIBMODULE)) return;
if (!(pModule->flags & NE_FFLAGS_BUILTIN) && pModule->expected_version < 0x0400) return;
if (!(entryPoint = GetProcAddress16( pModule->self, "DllEntryPoint" ))) return;
NE_GetDLLInitParams( pModule, &hInst, &ds, &heap );
TRACE_(dll)( "Calling %s DllEntryPoint, cs:ip=%04x:%04x\n",
NE_MODULE_NAME( pModule ),
SELECTOROF(entryPoint), OFFSETOF(entryPoint) );
if ( pModule->flags & NE_FFLAGS_BUILTIN )
{
WinNEEntryProc entryProc = (WinNEEntryProc)((ENTRYPOINT16 *)MapSL( (SEGPTR)entryPoint ))->target;
entryProc( dwReason, hInst, ds, heap, 0, 0 );
}
else
{
LPBYTE stack = (LPBYTE)CURRENT_STACK16;
CONTEXT86 context;
memset( &context, 0, sizeof(context) );
context.SegDs = ds;
context.SegEs = ds; /* who knows ... */
context.SegCs = HIWORD(entryPoint);
context.Eip = LOWORD(entryPoint);
context.Ebp = OFFSETOF( NtCurrentTeb()->WOW32Reserved )
+ (WORD)&((STACK16FRAME*)0)->bp;
*(DWORD *)(stack - 4) = dwReason; /* dwReason */
*(WORD *) (stack - 6) = hInst; /* hInst */
*(WORD *) (stack - 8) = ds; /* wDS */
*(WORD *) (stack - 10) = heap; /* wHeapSize */
*(DWORD *)(stack - 14) = 0; /* dwReserved1 */
*(WORD *) (stack - 16) = 0; /* wReserved2 */
wine_call_to_16_regs_short( &context, 16 );
}
}
示例14: exit_thread
/***********************************************************************
* exit_thread
*/
void exit_thread( int status )
{
static void *prev_teb;
TEB *teb;
if (status) /* send the exit code to the server (0 is already the default) */
{
SERVER_START_REQ( terminate_thread )
{
req->handle = wine_server_obj_handle( GetCurrentThread() );
req->exit_code = status;
wine_server_call( req );
}
SERVER_END_REQ;
}
if (interlocked_xchg_add( &nb_threads, -1 ) <= 1)
{
LdrShutdownProcess();
exit( status );
}
LdrShutdownThread();
RtlFreeThreadActivationContextStack();
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
if ((teb = interlocked_xchg_ptr( &prev_teb, NtCurrentTeb() )))
{
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SpareBytes1;
if (thread_data->pthread_id)
{
pthread_join( thread_data->pthread_id, NULL );
signal_free_thread( teb );
}
}
close( ntdll_get_thread_data()->wait_fd[0] );
close( ntdll_get_thread_data()->wait_fd[1] );
close( ntdll_get_thread_data()->reply_fd );
close( ntdll_get_thread_data()->request_fd );
pthread_exit( UIntToPtr(status) );
}
示例15: FlsSetValue
/*
* @implemented
*/
BOOL
WINAPI
FlsSetValue(DWORD dwFlsIndex, PVOID lpFlsData)
{
PVOID *ppFlsSlots;
TEB *pTeb = NtCurrentTeb();
if(dwFlsIndex >= 128) goto l_InvalidParam;
ppFlsSlots = pTeb->FlsData;
if (ppFlsSlots == NULL)
{
PEB *pPeb = pTeb->ProcessEnvironmentBlock;
ppFlsSlots = RtlAllocateHeap(pPeb->ProcessHeap,
HEAP_ZERO_MEMORY,
(128 + 2) * sizeof(PVOID));
if(ppFlsSlots == NULL) goto l_OutOfMemory;
pTeb->FlsData = ppFlsSlots;
RtlAcquirePebLock();
/* TODO: initialization */
RtlReleasePebLock();
}
ppFlsSlots[dwFlsIndex + 2] = lpFlsData;
return TRUE;
l_OutOfMemory:
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto l_Fail;
l_InvalidParam:
SetLastError(ERROR_INVALID_PARAMETER);
l_Fail:
return FALSE;
}