Changeset 1749 for zzuf


Ignore:
Timestamp:
Feb 19, 2007, 11:28:16 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Use mmap() instead of malloc() in the mmap() reimplementation so that returned values are not in the heap.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/lib-mem.c

    r1730 r1749  
    218218#define MMAP(fn, off_t) \
    219219    do { \
     220        char *b = MAP_FAILED; \
    220221        LOADSYM(fn); \
    221         ret = ORIG(fn)(start, length, prot, flags, fd, offset); \
    222222        if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) \
    223             return ret; \
    224         if(ret && length) \
     223            return ORIG(fn)(start, length, prot, flags, fd, offset); \
     224        ret = ORIG(fn)(NULL, length, prot, flags, fd, offset); \
     225        if(ret != MAP_FAILED && length) \
    225226        { \
    226             char *b = malloc(length); \
     227            b = ORIG(fn)(start, length, PROT_READ | PROT_WRITE, \
     228                         MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
     229            if(b == MAP_FAILED) \
     230            { \
     231                munmap(ret, length); \
     232                ret = MAP_FAILED; \
     233            } \
     234        } \
     235        if(b != MAP_FAILED) \
     236        { \
    227237            int i, oldpos; \
    228238            for(i = 0; i < nbmaps; i += 2) \
     
    284294            continue;
    285295
    286         free(start);
     296        ORIG(munmap)(start, length);
    287297        ret = ORIG(munmap)(maps[i + 1], length);
    288298        maps[i] = NULL;
Note: See TracChangeset for help on using the changeset viewer.