VirtualBox

Ignore:
Timestamp:
Jun 5, 2018 7:32:45 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
122935
Message:

iprt/fuzz: Some delinting. bugref:9006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/fuzz/fuzz-observer.cpp

    r72437 r72454  
    11/* $Id$ */
    22/** @file
    3  * IPRT Fuzzing framework API (Fuzz).
     3 * IPRT - Fuzzing framework API, observer.
    44 */
    55
     
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
     31#include <iprt/fuzz.h>
     32#include "internal/iprt.h"
     33
    3134#include <iprt/asm.h>
    3235#include <iprt/assert.h>
    33 #include <iprt/cdefs.h>
    3436#include <iprt/ctype.h>
    3537#include <iprt/err.h>
    3638#include <iprt/env.h>
    3739#include <iprt/file.h>
    38 #include <iprt/fuzz.h>
     40#include <iprt/md5.h>
     41#include <iprt/mem.h>
     42#include <iprt/mp.h>
    3943#include <iprt/path.h>
    4044#include <iprt/pipe.h>
    4145#include <iprt/process.h>
    42 #include <iprt/md5.h>
    43 #include <iprt/mem.h>
    44 #include <iprt/mp.h>
    4546#include <iprt/semaphore.h>
    4647#include <iprt/stream.h>
     
    5152
    5253/*********************************************************************************************************************************
    53 *   Defined Constants And Macros                                                                                                 *
    54 *********************************************************************************************************************************/
    55 
    56 
    57 /*********************************************************************************************************************************
    5854*   Structures and Typedefs                                                                                                      *
    5955*********************************************************************************************************************************/
    60 
    6156/** Pointer to the internal fuzzing observer state. */
    6257typedef struct RTFUZZOBSINT *PRTFUZZOBSINT;
     
    6964{
    7065    /** The thread handle. */
    71     RTTHREAD                    hThrd;
     66    RTTHREAD                    hThread;
    7267    /** The observer ID. */
    7368    uint32_t                    idObs;
     
    9590    RTFUZZCTX                   hFuzzCtx;
    9691    /** Temp directory for input files. */
    97     char                        *pszTmpDir;
     92    char                       *pszTmpDir;
    9893    /** The binary to run. */
    99     char                        *pszBinary;
     94    char                       *pszBinary;
    10095    /** Arguments to run the binary with, terminated by a NULL entry. */
    101     char                        **papszArgs;
     96    char                      **papszArgs;
    10297    /** Number of arguments. */
    10398    uint32_t                    cArgs;
     
    107102    volatile bool               fShutdown;
    108103    /** Global observer thread handle. */
    109     RTTHREAD                    hThrdGlobal;
     104    RTTHREAD                    hThreadGlobal;
    110105    /** The event semaphore handle for the global observer thread. */
    111106    RTSEMEVENT                  hEvtGlobal;
     
    113108    volatile uint64_t           bmEvt;
    114109    /** Number of threads created - one for each process. */
    115     uint32_t                    cThrds;
     110    uint32_t                    cThreads;
    116111    /** Pointer to the array of observer thread states. */
    117     PRTFUZZOBSTHRD              paObsThrds;
     112    PRTFUZZOBSTHRD              paObsThreads;
    118113} RTFUZZOBSINT;
    119114
    120 
    121 /*********************************************************************************************************************************
    122 *   Global variables                                                                                                             *
    123 *********************************************************************************************************************************/
    124 
    125 
    126 
    127 /*********************************************************************************************************************************
    128 *   Internal Functions                                                                                                           *
    129 *********************************************************************************************************************************/
    130115
    131116
     
    134119 *
    135120 * @returns IPRT status code.
    136  * @param   hThrd               The thread handle.
     121 * @param   hThread               The thread handle.
    137122 * @param   pvUser              Opaque user data.
    138123 */
    139 static DECLCALLBACK(int) rtFuzzObsWorkerLoop(RTTHREAD hThrd, void *pvUser)
     124static DECLCALLBACK(int) rtFuzzObsWorkerLoop(RTTHREAD hThread, void *pvUser)
    140125{
    141126    PRTFUZZOBSTHRD pObsThrd = (PRTFUZZOBSTHRD)pvUser;
     
    161146    {
    162147        /* Wait for work. */
    163         int rc = RTThreadUserWait(hThrd, RT_INDEFINITE_WAIT);
     148        int rc = RTThreadUserWait(hThread, RT_INDEFINITE_WAIT);
    164149        AssertRC(rc);
    165150
     
    312297 *
    313298 * @returns IPRT status code.
    314  * @param   hThrd               The thread handle.
     299 * @param   hThread               The thread handle.
    315300 * @param   pvUser              Opaque user data.
    316301 */
    317 static DECLCALLBACK(int) rtFuzzObsMasterLoop(RTTHREAD hThrd, void *pvUser)
    318 {
    319     RT_NOREF(hThrd);
     302static DECLCALLBACK(int) rtFuzzObsMasterLoop(RTTHREAD hThread, void *pvUser)
     303{
     304    RT_NOREF(hThread);
    320305    int rc = VINF_SUCCESS;
    321306    PRTFUZZOBSINT pThis = (PRTFUZZOBSINT)pvUser;
    322307
    323     RTThreadUserSignal(hThrd);
     308    RTThreadUserSignal(hThread);
    324309
    325310    while (   !pThis->fShutdown
     
    333318            {
    334319                /* Create a new input for this observer and kick it. */
    335                 PRTFUZZOBSTHRD pObsThrd = &pThis->paObsThrds[idxObs];
     320                PRTFUZZOBSTHRD pObsThrd = &pThis->paObsThreads[idxObs];
    336321
    337322                /* Release the old input. */
     
    351336                {
    352337                    ASMAtomicWriteBool(&pObsThrd->fNewInput, true);
    353                     RTThreadUserSignal(pObsThrd->hThrd);
     338                    RTThreadUserSignal(pObsThrd->hThread);
    354339                }
    355340            }
     
    382367
    383368    ASMAtomicBitSet(&pThis->bmEvt, idObs);
    384     return RTThreadCreate(&pObsThrd->hThrd, rtFuzzObsWorkerLoop, pObsThrd, 0, RTTHREADTYPE_IO,
     369    return RTThreadCreate(&pObsThrd->hThread, rtFuzzObsWorkerLoop, pObsThrd, 0, RTTHREADTYPE_IO,
    385370                          RTTHREADFLAGS_WAITABLE, "Fuzz-Worker");
    386371}
     
    392377 * @returns IPRT status code.
    393378 * @param   pThis               The internal fuzzing observer state.
    394  * @param   cThrds              Number of worker threads to create.
    395  */
    396 static int rtFuzzObsWorkersCreate(PRTFUZZOBSINT pThis, uint32_t cThrds)
     379 * @param   cThreads            Number of worker threads to create.
     380 */
     381static int rtFuzzObsWorkersCreate(PRTFUZZOBSINT pThis, uint32_t cThreads)
    397382{
    398383    int rc = VINF_SUCCESS;
    399     PRTFUZZOBSTHRD paObsThrds = (PRTFUZZOBSTHRD)RTMemAllocZ(cThrds * sizeof(RTFUZZOBSTHRD));
    400     if (RT_LIKELY(paObsThrds))
    401     {
    402         for (unsigned i = 0; i < cThrds && RT_SUCCESS(rc); i++)
    403         {
    404             rc = rtFuzzObsWorkerThreadInit(pThis, i, &paObsThrds[i]);
     384    PRTFUZZOBSTHRD paObsThreads = (PRTFUZZOBSTHRD)RTMemAllocZ(cThreads * sizeof(RTFUZZOBSTHRD));
     385    if (RT_LIKELY(paObsThreads))
     386    {
     387        for (unsigned i = 0; i < cThreads && RT_SUCCESS(rc); i++)
     388        {
     389            rc = rtFuzzObsWorkerThreadInit(pThis, i, &paObsThreads[i]);
    405390            if (RT_FAILURE(rc))
    406391            {
     
    411396
    412397        if (RT_SUCCESS(rc))
    413             pThis->paObsThrds = paObsThrds;
     398            pThis->paObsThreads = paObsThreads;
    414399        else
    415             RTMemFree(paObsThrds);
     400            RTMemFree(paObsThreads);
    416401    }
    417402
     
    433418    if (RT_SUCCESS(rc))
    434419    {
    435         rc = RTThreadCreate(&pThis->hThrdGlobal, rtFuzzObsMasterLoop, pThis, 0, RTTHREADTYPE_IO,
     420        rc = RTThreadCreate(&pThis->hThreadGlobal, rtFuzzObsMasterLoop, pThis, 0, RTTHREADTYPE_IO,
    436421                            RTTHREADFLAGS_WAITABLE, "Fuzz-Master");
    437422        if (RT_SUCCESS(rc))
    438423        {
    439             RTThreadUserWait(pThis->hThrdGlobal, RT_INDEFINITE_WAIT);
     424            RTThreadUserWait(pThis->hThreadGlobal, RT_INDEFINITE_WAIT);
    440425        }
    441426        else
     
    461446        pThis->papszArgs   = NULL;
    462447        pThis->fFlags      = 0;
    463         pThis->hThrdGlobal = NIL_RTTHREAD;
     448        pThis->hThreadGlobal = NIL_RTTHREAD;
    464449        pThis->hEvtGlobal  = NIL_RTSEMEVENT;
    465450        pThis->bmEvt       = 0;
    466         pThis->cThrds      = 0;
    467         pThis->paObsThrds  = NULL;
     451        pThis->cThreads    = 0;
     452        pThis->paObsThreads  = NULL;
    468453        rc = RTFuzzCtxCreate(&pThis->hFuzzCtx);
    469454        if (RT_SUCCESS(rc))
     
    488473
    489474    /* Wait for the master thread to terminate. */
    490     if (pThis->hThrdGlobal != NIL_RTTHREAD)
     475    if (pThis->hThreadGlobal != NIL_RTTHREAD)
    491476    {
    492477        ASMAtomicXchgBool(&pThis->fShutdown, true);
    493         RTThreadWait(pThis->hThrdGlobal, RT_INDEFINITE_WAIT, NULL);
     478        RTThreadWait(pThis->hThreadGlobal, RT_INDEFINITE_WAIT, NULL);
    494479    }
    495480
    496481    /* Clean up the workers. */
    497     if (pThis->paObsThrds)
    498     {
    499         for (unsigned i = 0; i < pThis->cThrds; i++)
    500         {
    501             PRTFUZZOBSTHRD pThrd = &pThis->paObsThrds[i];
     482    if (pThis->paObsThreads)
     483    {
     484        for (unsigned i = 0; i < pThis->cThreads; i++)
     485        {
     486            PRTFUZZOBSTHRD pThrd = &pThis->paObsThreads[i];
    502487            ASMAtomicXchgBool(&pThrd->fShutdown, true);
    503             RTThreadWait(pThrd->hThrd, RT_INDEFINITE_WAIT, NULL);
     488            RTThreadWait(pThrd->hThread, RT_INDEFINITE_WAIT, NULL);
    504489            if (pThrd->hFuzzInput)
    505490                RTFuzzInputRelease(pThrd->hFuzzInput);
    506491        }
    507         RTMemFree(pThis->paObsThrds);
    508         pThis->paObsThrds = NULL;
     492        RTMemFree(pThis->paObsThreads);
     493        pThis->paObsThreads = NULL;
    509494    }
    510495
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette