Changeset 1077 for trunk/dll/fortify.c


Ignore:
Timestamp:
Jul 18, 2008, 8:11:54 PM (17 years ago)
Author:
Steven Levine
Message:

Enhance Fortify infrastructure
Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope
Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT support
Add more fm/2 Fortify tooling and rework existing tooling for correct nesting
Still lots to do for cross-thread allocations
Add misc.h
Add walkem.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/fortify.c

    r1072 r1077  
    4343 /* 06 May 08 SHL Rework scope logic to be MT capable
    4444    26 May 08 SHL Show TID for leaking scope
    45     17 Jul 08 SHL Add Fortify_SetOwner Fortify_ChangeOwner
     45    17 Jul 08 SHL Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope
     46    18 Jul 08 SHL Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT
    4647 */
    4748
     
    177178#ifdef MT_SCOPES
    178179static unsigned volatile st_cOrdinals;          // Number of known threads
    179 static unsigned volatile char*  st_pScopes;     // Scope level of blocks allocated by thread
    180 static unsigned volatile long*  st_pOwners;     // Owner of blocks allocated by thread
     180static volatile unsigned char*  st_pScopes;     // Scope level of blocks allocated by thread
     181static volatile unsigned long*  st_pOwners;     // Owner of blocks allocated by thread
    181182#else
    182183static unsigned char  st_Scope            = 0;
     
    997998        FORTIFY_UNLOCK();
    998999    }
    999     return(++st_pScopes[ordinal]);
     1000    i = ++st_pScopes[ordinal];
     1001#   ifdef FORTIFY_VERBOSE_SCOPE_ENTER_EXIT
     1002    sprintf(st_Buffer,
     1003            "Fortify: Entering scope %u in TID %u at %s.%lu\n",
     1004            i, ordinal,
     1005            file, line);        // 26 May 08 SHL
     1006    st_Output(st_Buffer);
     1007#   endif
     1008    return(i);
    10001009#else
    10011010    return(++st_Scope);
     
    10251034    // Complain on leave without enter 06 May 08 SHL
    10261035    ordinal = Get_TID_Ordinal();
    1027     if (ordinal < st_cOrdinals && st_pScopes[ordinal] > 0)
     1036    if (ordinal < st_cOrdinals && st_pScopes[ordinal] > 0) {
    10281037        st_pScopes[ordinal]--;
     1038    }
    10291039    else {
    10301040        sprintf(st_Buffer,
    1031                 "\nFortify: attempting to leave scope before enter at %s.%lu in TID %u\n",
    1032                 file, line, ordinal);   // 26 May 08 SHL
     1041                "\nFortify: Attempting to leave scope before enter in TID %u at %s.%lu\n",
     1042                ordinal, file, line);   // 26 May 08 SHL
    10331043        st_Output(st_Buffer);
    10341044    }
     
    10371047        st_Scope--;
    10381048    else {
    1039         sprintf(st_Buffer, "\nFortify: attempting to leave scope before enter at %s.%lu\n", file, line);
     1049        sprintf(st_Buffer, "\nFortify: Attempting to leave scope before enter at %s.%lu\n", file, line);
    10401050        st_Output(st_Buffer);
    10411051    }
     
    10541064#ifdef MT_SCOPES
    10551065                sprintf(st_Buffer,
    1056                         "\nFortify: Memory leak detected leaving scope at %s.%lu in TID %u\n",
    1057                         file, line, ordinal);
     1066                        "\nFortify: Memory leak detected leaving scope %d in TID %u at %s.%lu\n",
     1067                        ordinal < st_cOrdinals ? st_pScopes[ordinal] + 1 : 0,
     1068                        ordinal,
     1069                        file, line);
    10581070#else
    10591071                sprintf(st_Buffer, "\nFortify: Memory leak detected leaving scope at %s.%lu\n", file, line);
     
    10781090        st_Output(st_Buffer);
    10791091    }
     1092#   ifdef FORTIFY_VERBOSE_SCOPE_ENTER_EXIT
     1093    else {
     1094        sprintf(st_Buffer,
     1095                "Fortify: Leaving scope %u in TID %u at %s.%lu\n",
     1096                ordinal < st_cOrdinals ? st_pScopes[ordinal] + 1 : 0,
     1097                ordinal,
     1098                file, line);    // 26 May 08 SHL
     1099        st_Output(st_Buffer);
     1100    }
     1101#   endif
    10801102
    10811103#ifdef FORTIFY_TRACK_DEALLOCATED_MEMORY
     
    24302452    if (ordinal >= st_cOrdinals) {
    24312453        // Expand arrays
    2432         unsigned i;
    2433         unsigned c;
     2454        unsigned i;
     2455        unsigned c;
    24342456        FORTIFY_LOCK();
    24352457        i = st_cOrdinals;
     
    24502472/**
    24512473 * Take ownership of block allocated by some other thread
    2452  * Allows scope enter/exit logic to correctly report leaks in 
     2474 * Allows scope enter/exit logic to correctly report leaks in
    24532475 * cross thread allocations
    2454  * @param pVoid is point to block allocated by Fortify
     2476 * @param pBlock points to block allocated by Fortify
    24552477 */
    24562478
     
    24662488    h->Scope = ordinal < st_cOrdinals ? st_pScopes[ordinal] : 0;
    24672489    h->Owner = ordinal;         // Take ownership
     2490    st_MakeHeaderValid(h);
     2491}
     2492
     2493/**
     2494 * Adjust scope level of allocated block
     2495 * Allows scope enter/exit logic to correctly report leaks in
     2496 * window procedure related allocations
     2497 * @param pBlock points to block allocated by Fortify
     2498 */
     2499
     2500void Fortify_ChangeScope(void *pBlock, int delta)
     2501{
     2502    unsigned char *ptr = (unsigned char *)pBlock -
     2503                             FORTIFY_HEADER_SIZE -
     2504                             FORTIFY_ALIGNED_BEFORE_SIZE;
     2505    struct Header *h = (struct Header *)ptr;
     2506    h->Scope += delta;
     2507    st_MakeHeaderValid(h);
    24682508}
    24692509
Note: See TracChangeset for help on using the changeset viewer.