Пример #1
0
void FreeThreadData (
    IN  LPLOG_THREAD_DATA    pThisThread
)
{
    if (pThisThread->next != NULL) {
        // free the "downstream" entries
        FreeThreadData (pThisThread->next);
        pThisThread->next = NULL;
    }
    // now free this entry
    if (pThisThread->mszCounterList != NULL) {
        G_FREE (pThisThread->mszCounterList);
        pThisThread->mszCounterList = NULL;
    }

    if (pThisThread->hExitEvent != NULL) {
        CloseHandle (pThisThread->hExitEvent);
        pThisThread->hExitEvent = NULL;
    }

    if (pThisThread->hKeyQuery != NULL) {
        RegCloseKey (pThisThread->hKeyQuery);
        pThisThread->hKeyQuery = NULL;
    }

    G_FREE (pThisThread);
}
Пример #2
0
VThreadVariable<TYPE>::~VThreadVariable ()
{
  FreeThreadData();
#ifdef _VISION_POSIX
  pthread_key_delete(m_key);
#elif defined(_VISION_WIIU)
  VWiiUTLSFree(m_uiTLSIndex);
#else
  TlsFree(m_TLSindex);
  m_TLSindex = -1;
#endif
}
Пример #3
0
void WINAPI _export ShowInfoMenu(void)
{
  FarDialogItem DialogItems[1];
  memset(DialogItems,0,sizeof(DialogItems));
  DialogItems[0].Type=DI_LISTBOX; DialogItems[0].Flags=DIF_LISTWRAPMODE;
  ThreadData Thread={FALSE,NULL,NULL,NULL,PlgOpt.RefreshInterval};
  InitThreadData(&Thread);
  InfoMenuData params={{&Thread,0,{-1,-1},{L"",L""},INVALID_HANDLE_VALUE,false,InfoMenuDialogKeyProc,MACRO_INFO_MENU,true,false},0,NULL,true,true};
  CFarDialog dialog;
  dialog.Execute(Info.ModuleNumber,-1,-1,0,0,_T("InfoMenu"),DialogItems,sizeofa(DialogItems),0,0,InfoMenuProc,(LONG_PTR)&params);
  FreeThreadData(&Thread);
  free(params.id);
}
Пример #4
0
BOOL
WINAPI
DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
{
    OSVERSIONINFOW osvi;
    switch (dwReason)
    {
    case DLL_PROCESS_ATTACH://1
        /* initialize version info */
        //DPRINT1("Process Attach %d\n", nAttachCount);
        //DPRINT1("Process Attach\n");
        osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
        GetVersionExW( &osvi );
        _winver     = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
        _winmajor   = osvi.dwMajorVersion;
        _winminor   = osvi.dwMinorVersion;
        _osplatform = osvi.dwPlatformId;
        _osver      = osvi.dwBuildNumber;
        hHeap = HeapCreate(0, 100000, 0);
        if (hHeap == NULL)
            return FALSE;

        /* create tls stuff */
        if (!CreateThreadData())
            return FALSE;

        if (BlockEnvToEnvironA() < 0)
            return FALSE;

        if (BlockEnvToEnvironW() < 0)
        {
            FreeEnvironment(_environ);
            return FALSE;
        }

        _acmdln = _strdup(GetCommandLineA());
        _wcmdln = _wcsdup(GetCommandLineW());

        /* FIXME: more initializations... */

        /* Initialization of the WINE code */
        msvcrt_init_mt_locks();
        msvcrt_init_io();
        setlocale(0, "C");
        //_setmbcp(_MB_CP_LOCALE);

        TRACE("Attach done\n");
        break;

    case DLL_THREAD_ATTACH:
        break;

    case DLL_THREAD_DETACH:
        FreeThreadData(NULL);
        break;

    case DLL_PROCESS_DETACH:
        //DPRINT1("Detach %d\n", nAttachCount);
        //DPRINT("Detach\n");
        /* FIXME: more cleanup... */
        /* Deinit of the WINE code */
        msvcrt_free_io();
        msvcrt_free_mt_locks();

        _atexit_cleanup();


        /* destroy tls stuff */
        DestroyThreadData();

	if (__winitenv && __winitenv != _wenviron)
            FreeEnvironment((char**)__winitenv);
        if (_wenviron)
            FreeEnvironment((char**)_wenviron);

	if (__initenv && __initenv != _environ)
            FreeEnvironment(__initenv);
        if (_environ)
            FreeEnvironment(_environ);

        /* destroy heap */
        HeapDestroy(hHeap);

        TRACE("Detach done\n");
        break;
    }

    return TRUE;
}
Пример #5
0
 /// \brief Destructor. Deallocates entry from TLS.
 ~VThreadBuffer()
 {
   FreeThreadData();
   TDeallocate();
 }
Пример #6
0
void
PerfDataLogServiceStart (
    IN  DWORD   argc,
    IN  LPTSTR  *argv
)
{
    LONG                lStatus;
    HKEY                hKeyLogQueries;
    HKEY                hKeyThisLogQuery;
    DWORD               dwQueryIndex;
    TCHAR               szQueryNameBuffer[MAX_PATH];
    DWORD               dwQueryNameBufferSize;
    TCHAR               szQueryClassBuffer[MAX_PATH];
    DWORD               dwQueryClassBufferSize;
    LPLOG_THREAD_DATA   lpThreadData;
    HANDLE              hThread;
    LPTSTR              szStringArray[2];
    DWORD               dwThreadId;

    ssPerfLogStatus.dwServiceType       = SERVICE_WIN32_OWN_PROCESS;
    ssPerfLogStatus.dwCurrentState      = SERVICE_START_PENDING;
    ssPerfLogStatus.dwControlsAccepted  = SERVICE_ACCEPT_STOP |
//        SERVICE_ACCEPT_PAUSE_CONTINUE |
        SERVICE_ACCEPT_SHUTDOWN;
    ssPerfLogStatus.dwWin32ExitCode = 0;
    ssPerfLogStatus.dwServiceSpecificExitCode = 0;
    ssPerfLogStatus.dwCheckPoint = 0;
    ssPerfLogStatus.dwWaitHint = 0;

    hPerfLogStatus = RegisterServiceCtrlHandler (
        TEXT("PerfDataLog"), PerfDataLogServiceControlHandler);

    if (hPerfLogStatus == (SERVICE_STATUS_HANDLE)0) {
        lStatus = GetLastError();
        ReportEvent (hEventLog,
            EVENTLOG_ERROR_TYPE,
            0,
            PERFLOG_UNABLE_REGISTER_HANDLER,
            NULL,
            0,
            sizeof(DWORD),
            NULL,
            (LPVOID)&lStatus);
        // this is fatal so bail out
        return;
    }

    // registered the service successfully, so load the log queries
    // assign the handle buffer
    pThreadHandleArray = &LocalThreadArray[0];
    dwMaxHandleCount = LOCAL_HANDLE_COUNT;
    // open (each) query
    lStatus = RegOpenKeyEx (
        HKEY_LOCAL_MACHINE,
        TEXT("SYSTEM\\CurrentControlSet\\Services\\PerfDataLog\\Log Queries"),
        0L,
        KEY_READ,
        &hKeyLogQueries);

    if (lStatus != ERROR_SUCCESS) {
        // unable to read the log query information from the registry
        lStatus = GetLastError();
        ReportEvent (hEventLog,
            EVENTLOG_ERROR_TYPE,
            0,
            PERFLOG_UNABLE_OPEN_LOG_QUERY,
            NULL,
            0,
            sizeof(DWORD),
            NULL,
            (LPVOID)&lStatus);

        // we can't start the service with out the evnt log.
        ssPerfLogStatus.dwCurrentState    = SERVICE_STOPPED;
        SetServiceStatus (hPerfLogStatus, &ssPerfLogStatus);

        return;
    }

    // enumerate and start the queries in the registry
    dwQueryIndex = 0;
    *szQueryNameBuffer = 0;
    dwQueryNameBufferSize = MAX_PATH;
    *szQueryClassBuffer;
    dwQueryClassBufferSize = MAX_PATH;
    while ((lStatus = RegEnumKeyEx (
        hKeyLogQueries,
        dwQueryIndex,
        szQueryNameBuffer,
        &dwQueryNameBufferSize,
        NULL,
        szQueryClassBuffer,
        &dwQueryClassBufferSize,
        NULL)) != ERROR_NO_MORE_ITEMS) {

        // open this key
        lStatus = RegOpenKeyEx (
            hKeyLogQueries,
            szQueryNameBuffer,
            0L,
            KEY_READ | KEY_WRITE,
            &hKeyThisLogQuery);

        if (lStatus != ERROR_SUCCESS) {
            szStringArray[0] = szQueryNameBuffer;
            ReportEvent (hEventLog,
                EVENTLOG_WARNING_TYPE,
                0,
                PERFLOG_UNABLE_READ_LOG_QUERY,
                NULL,
                1,
                sizeof(DWORD),
                szStringArray,
                   (LPVOID)&lStatus);
            // skip to next item
            goto CONTINUE_ENUM_LOOP;
        }

        // update the service status
        ssPerfLogStatus.dwCheckPoint++;
        SetServiceStatus (hPerfLogStatus, &ssPerfLogStatus);

        // allocate a thread info block.
        lpThreadData = G_ALLOC (sizeof(LOG_THREAD_DATA));
        if (lpThreadData == NULL) {
            lStatus = GetLastError();
            szStringArray[0] = szQueryNameBuffer;
            ReportEvent (hEventLog,
                EVENTLOG_WARNING_TYPE,
                0,
                PERFLOG_UNABLE_ALLOCATE_DATABLOCK,
                NULL,
                1,
                sizeof(DWORD),
                szStringArray,
                (LPVOID)&lStatus);
            goto CONTINUE_ENUM_LOOP;
        }

        // initialize the thread data block
        lpThreadData->hKeyQuery = hKeyThisLogQuery;
        lpThreadData->hExitEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
        lpThreadData->bReloadNewConfig = FALSE;
        lstrcpy (lpThreadData->szQueryName, szQueryNameBuffer);

        // start logging thread
        hThread = CreateThread (
            NULL, 0, LoggingThreadProc,
            (LPVOID)lpThreadData, 0, &dwThreadId);

        if (hThread != NULL) {
            // add it to the list and continue
            if (pFirstThread == NULL) {
                // then this is the first thread so add it
                lpThreadData->next = NULL;
                pFirstThread = lpThreadData;
            } else {
                // insert this at the head of the list since
                // that's the easiest and the order isn't
                // really important
                lpThreadData->next = pFirstThread;
                pFirstThread = lpThreadData;
            }
            // add thread to array for termination wait
            if (dwHandleCount < dwMaxHandleCount) {
                pThreadHandleArray[dwHandleCount++] = hThread;
            } else {
                // realloc buffer and try again
                // this will be added when multi-query
                // support is added. for now we'll ignore
                // ones that don't fit.
            }
            lpThreadData = NULL; //clear for next lap
        } else {
            // unable to start thread
            lStatus = GetLastError();
            szStringArray[0] = szQueryNameBuffer;
            ReportEvent (hEventLog,
                EVENTLOG_WARNING_TYPE,
                0,
                PERFLOG_UNABLE_START_THREAD,
                NULL,
                1,
                sizeof(DWORD),
                szStringArray,
                (LPVOID)&lStatus);
        }
CONTINUE_ENUM_LOOP:
        // prepare for next loop
        dwQueryIndex++;
        // for now we just do the first item in the list
        // the full multiple log query feature will be
        // added later.
        if (dwQueryIndex > 0) break;
        // otherwise we would continue here
        *szQueryNameBuffer = 0;
        dwQueryNameBufferSize = MAX_PATH;
        *szQueryClassBuffer;
        dwQueryClassBufferSize = MAX_PATH;
    } // end enumeration of log queries

    // service is now started
    ssPerfLogStatus.dwCurrentState    = SERVICE_RUNNING;
    ssPerfLogStatus.dwCheckPoint++;
    SetServiceStatus (hPerfLogStatus, &ssPerfLogStatus);

    // wait for (all) timing and logging threads to complete
    lStatus = WaitForMultipleObjects (dwHandleCount,
        pThreadHandleArray, TRUE, INFINITE);

    ssPerfLogStatus.dwCurrentState    = SERVICE_STOP_PENDING;
    SetServiceStatus (hPerfLogStatus, &ssPerfLogStatus);

    // when here, all logging threads have terminated so the
    // memory can be released and the service can exit and shutdown.
    for (dwQueryIndex = 0; dwQueryIndex < dwHandleCount; dwQueryIndex++) {
        CloseHandle (pThreadHandleArray[dwQueryIndex]);
    }

    // release the dynamic memory
    FreeThreadData (pFirstThread);

    // and update the service status
    ssPerfLogStatus.dwCurrentState    = SERVICE_STOPPED;
    SetServiceStatus (hPerfLogStatus, &ssPerfLogStatus);

    if (hEventLog != NULL) CloseHandle (hEventLog);

    return;
}