[PATCH] Make LocalFirst() and LocalNext() return correct handles, addresses, flags and lock values for moveable blocks. Previous implementation just returned the arena block pointer and flags for fixed blocks. Needed for applications that use toolhelp to find their own memory blocks.

Alexandre Julliard julliard at winehq.org
Wed Feb 12 13:31:04 CST 2020


Dirk Niggemann <dirk.niggemann at gmail.com> writes:

> @@ -326,12 +350,33 @@ BOOL16 WINAPI LocalFirst16( LOCALENTRY *pLocalEntry, HGLOBAL16 handle )
>      WORD ds = GlobalHandleToSel16( handle );
>      char *ptr = MapSL( MAKESEGPTR( ds, 0 ) );
>      LOCALHEAPINFO *pInfo = get_local_heap( ds );
> -    if (!pInfo) return FALSE;
> +    WORD table, lhandle;
>  
> -    pLocalEntry->hHandle   = pInfo->first + LOCAL_ARENA_HEADER_SIZE;
> -    pLocalEntry->wAddress  = pLocalEntry->hHandle;
> -    pLocalEntry->wFlags    = LF_FIXED;
> -    pLocalEntry->wcLock    = 0;
> +    if (!pInfo) return FALSE;
> +    table                 = pInfo->htable;
> +    pLocalEntry->wAddress = pInfo->first + LOCAL_ARENA_HEADER_SIZE;
> +    lhandle               = pLocalEntry->wAddress;
> +    pLocalEntry->wFlags   = LF_FIXED;
> +    pLocalEntry->wcLock   = 0;
> +    /* Find the address in the moveable entry tables */
> +    while (table)
> +    {
> +        WORD count = *(WORD *)(ptr + table);
> +        LOCALHANDLEENTRY *pEntry = (LOCALHANDLEENTRY*)(ptr+table+sizeof(WORD));
> +        for (; count > 0; count--, pEntry++)
> +            if (pEntry->addr == lhandle + MOVEABLE_PREFIX)
> +            {
> +                lhandle = (HLOCAL16)((char *)pEntry - ptr);
> +                table = 0;
> +                pLocalEntry->wAddress  = pEntry->addr;
> +                pLocalEntry->wFlags    = pEntry->flags;
> +                pLocalEntry->wcLock    = pEntry->lock;
> +                TRACE("moveable handle %04x\n", lhandle);
> +                break;
> +            }
> +        if ( table ) table = *(WORD *)pEntry;
> +    }

IIRC the first block is always fixed, you shouldn't need that here.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list