Changeset 1637 for zzuf


Ignore:
Timestamp:
Jan 9, 2007, 5:16:00 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Add verbosity to read() and mmap() so that we roughly know where we are reading.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/load-fd.c

    r1635 r1637  
    200200        return ret;
    201201
    202     debug("read(%i, %p, %li) = %i", fd, buf, (long int)count, ret);
    203202    if(ret > 0)
    204203    {
     204        char *b = buf;
     205
    205206        _zz_fuzz(fd, buf, ret);
    206207        _zz_addpos(fd, ret);
     208
     209        if(ret >= 4)
     210            debug("read(%i, %p, %li) = %i \"%c%c%c%c...", fd, buf,
     211                  (long int)count, ret, b[0], b[1], b[2], b[3]);
     212        else
     213            debug("read(%i, %p, %li) = %i \"%c...", fd, buf,
     214                  (long int)count, ret, b[0]);
    207215    }
     216    else
     217        debug("read(%i, %p, %li) = %i", fd, buf, (long int)count, ret);
    208218
    209219    /* Sanity check, can be OK though (for instance with a character device) */
     
    259269        if(!_zz_ready || !_zz_iswatched(fd) || _zz_disabled) \
    260270            return ret; \
    261         if(ret) \
     271        if(ret && length) \
    262272        { \
    263             void *tmp = malloc(length); \
     273            char *b = malloc(length); \
    264274            int i, oldpos; \
    265275            for(i = 0; i < nbmaps; i += 2) \
     
    271281                maps = realloc(maps, nbmaps * sizeof(void *)); \
    272282            } \
    273             maps[i] = tmp; \
     283            maps[i] = b; \
    274284            maps[i + 1] = ret; \
    275285            oldpos = _zz_getpos(fd); \
    276286            _zz_setpos(fd, offset); /* mmap() maps the fd at offset 0 */ \
    277             memcpy(tmp, ret, length); /* FIXME: get rid of this */ \
    278             _zz_fuzz(fd, tmp, length); \
     287            memcpy(b, ret, length); /* FIXME: get rid of this */ \
     288            _zz_fuzz(fd, (uint8_t *)b, length); \
    279289            _zz_setpos(fd, oldpos); \
    280             ret = tmp; \
     290            ret = b; \
     291            if(length >= 4) \
     292                debug(STR(fn)"(%p, %li, %i, %i, %i, %lli) = %p \"%c%c%c%c...", \
     293                      start, (long int)length, prot, flags, fd, \
     294                      (long long int)offset, ret, b[0], b[1], b[2], b[3]); \
     295            else \
     296                debug(STR(fn)"(%p, %li, %i, %i, %i, %lli) = %p \"%c...", \
     297                      start, (long int)length, prot, flags, fd, \
     298                      (long long int)offset, ret, b[0]); \
    281299        } \
    282300        debug(STR(fn)"(%p, %li, %i, %i, %i, %lli) = %p", start, \
     
    332350        return ret;
    333351
    334     if(ret == 0)
     352    if(ret == 0 && numbytes)
    335353    {
    336         void *tmp = malloc(numbytes);
    337         memcpy(tmp, (void *)*addr, numbytes);
    338         _zz_fuzz(fd, tmp, numbytes);
    339         *addr = (vm_offset_t)tmp;
     354        /* FIXME: do we also have to rewind the filedescriptor like in mmap? */
     355        void *b = malloc(numbytes);
     356        memcpy(b, (void *)*addr, numbytes);
     357        _zz_fuzz(fd, b, numbytes);
     358        *addr = (vm_offset_t)b;
    340359        /* FIXME: the map is never freed; there is no such thing as unmap_fd,
    341          * but I suppose that kind of map should go when the filedesciptor is
     360         * but I suppose that kind of map should go when the filedescriptor is
    342361         * closed (unlike mmap, which returns a persistent buffer). */
     362
     363        if(numbytes >= 4)
     364           debug("map_fd(%i, %lli, &%p, %i, %lli) = %i \"%c%c%c%c", fd,
     365                 (long long int)offset, (void *)*addr, (int)find_space,
     366                 (long long int)numbytes, ret, b[0], b[1], b[2], b[3]);
     367        else
     368           debug("map_fd(%i, %lli, &%p, %i, %lli) = %i \"%c", fd,
     369                 (long long int)offset, (void *)*addr, (int)find_space,
     370                 (long long int)numbytes, ret, b[0]);
    343371    }
    344 
    345     debug("map_fd(%i, %lli, &%p, %i, %lli) = %i", fd, (long long int)offset,
    346           (void *)*addr, (int)find_space, (long long int)numbytes, ret);
     372    else
     373        debug("map_fd(%i, %lli, &%p, %i, %lli) = %i", fd, (long long int)offset,
     374              (void *)*addr, (int)find_space, (long long int)numbytes, ret);
    347375
    348376    return ret;
Note: See TracChangeset for help on using the changeset viewer.