Esempio n. 1
0
void Win32SyncManager::Init(Task it){
	initializedFlag = true;
	syncVarIdManager->Init();

	initTask = it;
	timerHandle = NULL;
	
	tlsCurrentTaskId = TlsAlloc();

	Semaphore initSem;
	initSem.Init();
	syncVarIdManager->RegisterThreadSemaphore(initTask, initSem);
	TlsSetValue(tlsCurrentTaskId, (LPVOID)initTask);
	runningTid = initTask;
	//joinableThreads = new std::set<Task>();
	joinableThreads = new BitVector();

#ifndef UNDER_CE
	signal(SIGABRT, ExitSignalHandler);
#endif
	//_CrtSetReportHook(crtReportHook);
	if(!IsDebuggerPresent() && Chess::GetOptions().nopopups){
		_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
		_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
		_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
		_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
	}


	//ChessRegisterMonitor(new StackTraceMonitor());

	Reset();
}
Esempio n. 2
0
uintptr_t __cdecl __wrapper_beginthreadex(void * _Security,
									 unsigned _StackSize,
									 unsigned (__stdcall * _StartAddress) (void *),
									 void * _ArgList, 
									 unsigned _InitFlag,
									 unsigned * _ThrdAddr)
{
	if(!ChessWrapperSentry::Wrap("beginthreadex")){
		return Real_beginthreadex(_Security, _StackSize, _StartAddress, _ArgList, _InitFlag, _ThrdAddr);
	}
	ChessWrapperSentry sentry;

	uintptr_t retVal;

	struct ThreadRoutineArg* threadArgs = (struct ThreadRoutineArg*) malloc(sizeof(struct ThreadRoutineArg));
	if (!threadArgs) {
		Chess::AbnormalExit(-1, "out of memory");
        return 0; //should never reach this
	}
	threadArgs->Function = (LPTHREAD_START_ROUTINE)_StartAddress;
	threadArgs->Context = _ArgList;

	Semaphore childSem;
	childSem.Init();

	threadArgs->selfSemaphore = childSem;

	retVal = _beginthreadex(_Security, _StackSize, (unsigned (__stdcall*)(void*))ThreadCreateWrapper, threadArgs, _InitFlag, _ThrdAddr);

	if (retVal != 0)
	{
		Task child;
		Chess::TaskFork(child);
		GetWin32SyncManager()->RegisterThreadSemaphore(child, childSem, TRUE);
		GetWin32SyncManager()->AddChildHandle(child, (HANDLE)retVal);
		if (_InitFlag != CREATE_SUSPENDED){
			Chess::ResumeTask(child);
		}
		else{
			// Chess::TaskFork() by default creates a suspended task
		}
	}
	else{
		threadArgs->selfSemaphore.Clear();
		free(threadArgs);
	}
	return retVal;
}