本文整理汇总了C++中OpenThread函数的典型用法代码示例。如果您正苦于以下问题:C++ OpenThread函数的具体用法?C++ OpenThread怎么用?C++ OpenThread使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OpenThread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Freeze
//-------------------------------------------------------------------------
static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
{
pThreads->pItems = NULL;
pThreads->capacity = 0;
pThreads->size = 0;
EnumerateThreads(pThreads);
if (pThreads->pItems != NULL)
{
UINT i;
for (i = 0; i < pThreads->size; ++i)
{
HANDLE hThread = OpenThread(MH_THREAD_ACCESS, FALSE, pThreads->pItems[i]);
if (hThread != NULL)
{
SuspendThread(hThread);
ProcessThreadIPs(hThread, pos, action);
CloseHandle(hThread);
}
}
}
}
示例2: OpenThread
VOID * SocketExtension::GetExtensionFunction(SOCKET s, GUID * clasid)
{
if (clasid == NULL || s == INVALID_SOCKET)
{
return NULL;
}
VOID* func = { 0 };
DWORD size = 0;
//
WSATHREADID threadid;
threadid.ThreadHandle = OpenThread(THREAD_ALL_ACCESS, FALSE, GetCurrentThreadId());
threadid.Reserved = NULL;
INT error = 0;
if (LayeredServiceProvider_Current.NextProcTable.lpWSPIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, clasid,
sizeof(GUID), &func, sizeof(VOID*), &size, NULL, NULL, &threadid, &error) == SOCKET_ERROR)
{
CloseHandle(threadid.ThreadHandle);
return NULL;
}
CloseHandle(threadid.ThreadHandle);
return func;
}
示例3: OpenThread
/**返回当前线程创建到退出消耗的CPU时间
*/
void mvg::synch::getCurrentThreadTimes(
time_t &creationTime,
time_t &exitTime,
double &cpuTime)
{
MVG_START
FILETIME timCreat, timExit, timKernel, timUser;
uint64_t t;
HANDLE threadHandle;
// 根据ID得到当前线程的handle
threadHandle = OpenThread(READ_CONTROL | THREAD_QUERY_INFORMATION, FALSE, GetCurrentThreadId()); // threadId);
if (!threadHandle) THROW_EXCEPTION("Cannot open the thread with the given 'threadId'");
if (!GetThreadTimes(threadHandle, &timCreat, &timExit, &timKernel, &timUser))
{
CloseHandle(threadHandle);
THROW_EXCEPTION("Error accessing thread times!");
}
CloseHandle(threadHandle);
t = (((uint64_t)timCreat.dwHighDateTime) << 32) | timCreat.dwLowDateTime;
creationTime = (t - 116444736000000000ULL) / 10000000;
t = (((uint64_t)timExit.dwHighDateTime) << 32) | timExit.dwLowDateTime;
exitTime = (t - 116444736000000000ULL) / 10000000;
// CPU时间是用户+内核
int64_t t1 = (((uint64_t)timKernel.dwHighDateTime) << 32) | timKernel.dwLowDateTime;
int64_t t2 = (((uint64_t)timUser.dwHighDateTime) << 32) | timUser.dwLowDateTime;
cpuTime = ((double)(t1 + t2)) * 100e-9; // FILETIME counts intervals of 100ns
MVG_END
}
示例4: GetThreadTeb
_TEB* GetThreadTeb(DWORD tid)
{
NTSTATUS ntStatus;
if (NtQueryInformationThread == NULL)
NtQueryInformationThread = (pNtQIT)GetProcAddress(GetModuleHandle("ntdll.dll"),
"NtQueryInformationThread");
if (NtQueryInformationThread == NULL) {
MyTrace("%s(): cannot found NtQueryInformationThread()", __FUNCTION__);
return 0;
}
HANDLE hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, tid);
UINT32 ThreadBasicInformation = 0;
THREAD_BASIC_INFORMATION bi;
ntStatus = NtQueryInformationThread(hThread, ThreadBasicInformation, &bi, sizeof(bi), NULL);
XDbgCloseHandle(hThread);
if (ntStatus != 0)
return 0;
return (_TEB*)bi.TebBaseAddress;
}
示例5: _CancelThread
void _CancelThread(pthread_t tid, int exitcode) {
#ifdef _WIN32
/*
* IMPORTANT TODO:
* TerminateThread() should NOT be used!!
* Termination with this function is abrupt and could severely damage the application
* (it could hold a critical section within a system library, for instance)
* Under Windows 2000, XP, and Server 2003, the stack isn't freed resulting in a leak.
*
* GET PROPER EXITING EVENT CODE IN HERE ASAP!
*
*/
HANDLE hThread;
hThread = OpenThread(THREAD_TERMINATE, 0, tid);
if (hThread) {
TerminateThread(hThread, exitcode);
CloseHandle(hThread);
}
#else
pthread_cancel(tid);
#endif
}
示例6: OpenThread
BOOL DarunGrim::CreateIDACommandProcessorThread()
{
if (IDACommandProcessorThreadId > 0)
{
HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, IDACommandProcessorThreadId);
if (hThread)
{
CloseHandle(hThread);
}
else
{
IDACommandProcessorThreadId = -1;
}
}
if (IDACommandProcessorThreadId == -1)
{
CreateThread(NULL, 0, IDACommandProcessorThread, (PVOID)this, 0, &IDACommandProcessorThreadId);
return TRUE;
}
return FALSE;
}
示例7: w32_thread_open
w32_thread_t w32_thread_open( uint32_t desired_access,
gboolean inherit_handle,
uint32_t thread_id
)
{
w32_thread_t ret_handle;
if ( thread_id != 0 )
return INVALID_HANDLE_VALUE;
/*
* desired_access には少なくとも STANDARD_RIGHTS_REQUIRED が含まれていなければならない。
*/
ret_handle = OpenThread( desired_access,
inherit_handle,
thread_id
);
if ( ret_handle == NULL )
return INVALID_HANDLE_VALUE;
return ret_handle;
}
示例8: StartVMSessionPatching
HTHREAD StartVMSessionPatching(unsigned PID)
{
#ifndef _WIN64
if (IsRundll64Required(PID))
{
DWORD dwID = (DWORD)Call64BitKDCLIENT(kStartVMSessionPatching, PID);
EnableDebugPrivilege();
if(!dwID)
return 0;
else if (dwID == -1)
return INVALID_HANDLE_VALUE;
else
{
HANDLE h = OpenThread(THREAD_ALL_ACCESS, FALSE, dwID);
if (!h || (h == INVALID_HANDLE_VALUE)) //Thread already finished
return 0;
return h;
}
}
#endif
return StartPatcherThread(PID);
}
示例9: request_sys_process_thread_open
/*
* Opens a thread with the supplied identifier using the supplied permissions
* and returns a HANDLE to the requestor
*
* req: TLV_TYPE_THREAD_ID - The thread identifier to open
* req: TLV_TYPE_THREAD_PERMS - Thre thread permissions to open with
*/
DWORD request_sys_process_thread_open(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
HANDLE handle = NULL;
DWORD result = ERROR_SUCCESS;
DWORD threadId;
DWORD perms;
// Get the parameters
threadId = packet_get_tlv_value_uint(packet, TLV_TYPE_THREAD_ID);
perms = packet_get_tlv_value_uint(packet, TLV_TYPE_THREAD_PERMS);
do
{
// Validate parameters
if (!threadId)
{
result = ERROR_INVALID_PARAMETER;
break;
}
// Open the thread
if (!(handle = OpenThread(perms, FALSE, threadId)))
{
result = GetLastError();
break;
}
// Add the handle to the response packet
packet_add_tlv_uint(response, TLV_TYPE_THREAD_HANDLE,
(DWORD)handle);
} while (0);
packet_transmit_response(result, remote, response);
return ERROR_SUCCESS;
}
示例10: CreateToolhelp32Snapshot
//////////////////////////////////////////////////////////////////////////
//
// ¸ðµç ¾²·¹µå¸¦ °¡µ¿½ÃŲ´Ù
//
//////////////////////////////////////////////////////////////////////////
void CRawHookMgr::ResumeAllThread()
{
// ¸ðµç ¾²·¹µåµéÀÇ ½º³À¼¦À» ¸¸µì´Ï´Ù.
HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
if(hThreadSnap == INVALID_HANDLE_VALUE) return;
THREADENTRY32 te32;
memset(&te32, 0,sizeof(THREADENTRY32));
te32.dwSize = sizeof(THREADENTRY32);
// ÇöÀç ÇÁ·Î¼¼½ºID¿Í ¾²·¹µåID
DWORD dwCurPID = GetCurrentProcessId();
DWORD dwCurTID = GetCurrentThreadId();
// ¾²·¹µå ¼øȸ
BOOL bNext = Thread32First(hThreadSnap, &te32);
while(bNext)
{
if( te32.th32OwnerProcessID == dwCurPID && te32.th32ThreadID != dwCurTID )
{
// ¾²·¹µå Á¤Áö
HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te32.th32ThreadID);
if(hThread)
{
ResumeThread(hThread);
//CloseHandle(hThread);
}
}
bNext = Thread32Next(hThreadSnap, &te32);
}
CloseHandle (hThreadSnap);
m_bIsAllThreadSuspended = FALSE;
}
示例11: assert
void ScopedThreadExclusive::Freeze(
const std::vector<DWORD>& threads, const std::vector<uintptr_t>& oldIPs, const std::vector<uintptr_t>& newIPs)
{
assert(("ScopedThreadExclusive::freeze", (oldIPs.size() == newIPs.size())));
static const DWORD ThreadAccess
= THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION | THREAD_SET_CONTEXT;
for (size_t i = 0, count = threads.size(); i < count; ++i)
{
DWORD tid = threads[i];
ScopedHandle hThread = OpenThread(ThreadAccess, FALSE, tid);
SuspendThread(hThread);
// 書き換え範囲内でスレッドが停止した場合は、トランポリン関数に制御を移す
CONTEXT c = { 0 };
c.ContextFlags = CONTEXT_CONTROL;
if (!GetThreadContext(hThread, &c))
{
return;
}
#if defined _M_X64
DWORD64& ip = c.Rip;
#elif defined _M_IX86
DWORD& ip = c.Eip;
#endif
for (size_t i = 0; i < oldIPs.size(); ++i)
{
if (ip == oldIPs[ i ])
{
ip = newIPs[ i ];
SetThreadContext(hThread, &c);
break;
}
}
}
}
示例12: SafeRelease
MetroWindow::~MetroWindow()
{
SafeRelease(&m_pDirect2dFactory);
SafeRelease(&m_pRenderTarget);
SafeRelease(&m_pMinButtonActiveBrush);
SafeRelease(&m_pMetroButtonNsBrush);
SafeRelease(&m_pMetroButtonLsBrush);
SafeRelease(&m_pLightWhiteBrush);
SafeRelease(&m_EdgeViewBrush);
SafeRelease(&m_pCloseButtonClickBrush);
SafeRelease(&m_pControlTextBrush);
SafeRelease(&m_pDWriteTypography);
SafeRelease(&m_pIDWriteFactory);
SafeRelease(&m_pITextFormatTitle);
SafeRelease(&m_pITextFormatContent);
HANDLE hThread = OpenThread(DELETE, FALSE, this->iseThreadID);
if (hThread)
{
TerminateThread(hThread, 0);
CloseHandle(hThread);
}
}
示例13: thresume
void thresume(DWORD processId)
{
HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
THREADENTRY32 threadEntry;
threadEntry.dwSize = sizeof(THREADENTRY32);
Thread32First(hThreadSnapshot, &threadEntry);
do
{
if (threadEntry.th32OwnerProcessID == processId)
{
HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE,
threadEntry.th32ThreadID);
ResumeThread(hThread);
//SuspendThread(hThread);
CloseHandle(hThread);
}
} while (Thread32Next(hThreadSnapshot, &threadEntry));
CloseHandle(hThreadSnapshot);
}
示例14: Startup
void
Startup()
{
// The hang detector only runs in chrome processes. If you change this,
// you must also deal with the threadsafety of AnnotateCrashReport in
// non-chrome processes!
if (GoannaProcessType_Default != XRE_GetProcessType()) {
return;
}
MOZ_ASSERT(!gMonitor, "Hang monitor already initialized");
gMonitor = new Monitor("HangMonitor");
Preferences::RegisterCallback(PrefChanged, kHangMonitorPrefName, nullptr);
PrefChanged(nullptr, nullptr);
#ifdef REPORT_CHROME_HANGS
Preferences::RegisterCallback(PrefChanged, kTelemetryPrefName, nullptr);
winMainThreadHandle =
OpenThread(THREAD_ALL_ACCESS, FALSE, GetCurrentThreadId());
if (!winMainThreadHandle) {
return;
}
gAnnotators = new std::set<Annotator*>();
#endif
// Don't actually start measuring hangs until we hit the main event loop.
// This potentially misses a small class of really early startup hangs,
// but avoids dealing with some xpcshell tests and other situations which
// start XPCOM but don't ever start the event loop.
Suspend();
gThread = PR_CreateThread(PR_USER_THREAD,
ThreadMain,
nullptr, PR_PRIORITY_LOW, PR_GLOBAL_THREAD,
PR_JOINABLE_THREAD, 0);
}
示例15: GetThreadCallStack
BOOL GetThreadCallStack(DWORD thread_id, LLSD& info)
{
if(GetCurrentThreadId() == thread_id)
{
// Early exit for the current thread.
// Suspending the current thread would be a bad idea.
// Plus you can't retrieve a valid current thread context.
return false;
}
HANDLE thread_handle = INVALID_HANDLE_VALUE;
thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE, thread_id);
if(INVALID_HANDLE_VALUE == thread_handle)
{
return FALSE;
}
BOOL result = false;
if(-1 != SuspendThread(thread_handle))
{
CONTEXT context_struct;
context_struct.ContextFlags = CONTEXT_FULL;
if(GetThreadContext(thread_handle, &context_struct))
{
Get_Call_Stack(NULL, &context_struct, info);
result = true;
}
ResumeThread(thread_handle);
}
else
{
// Couldn't suspend thread.
}
CloseHandle(thread_handle);
return result;
}