Ignore:
Timestamp:
Jan 9, 2007, 11:02:57 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Implement map_fd for OS X.
File:
1 edited

Legend:

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

    r1626 r1631  
    3939#include <fcntl.h>
    4040#include <stdarg.h>
     41#if defined HAVE_LIBC_H
     42#   include <libc.h>
     43#endif
    4144
    4245#include "libzzuf.h"
     
    7275#endif
    7376static int     (*munmap_orig)  (void *start, size_t length);
     77#ifdef HAVE_MAP_FD
     78static kern_return_t (*map_fd_orig) (int fd, vm_offset_t offset,
     79                                     vm_offset_t *addr, boolean_t find_space,
     80                                     vm_size_t numbytes);
     81#endif
    7482static int     (*close_orig)   (int fd);
    7583
     
    93101#endif
    94102    LOADSYM(munmap);
     103#ifdef HAVE_MAP_FD
     104    LOADSYM(map_fd);
     105#endif
    95106    LOADSYM(close);
    96107}
     
    306317}
    307318
     319#ifdef HAVE_MAP_FD
     320kern_return_t map_fd(int fd, vm_offset_t offset, vm_offset_t *addr,
     321                     boolean_t find_space, vm_size_t numbytes)
     322{
     323    kern_return_t ret;
     324
     325    if(!_zz_ready)
     326        LOADSYM(map_fd);
     327    ret = map_fd_orig(fd, offset, addr, find_space, numbytes);
     328    if(!_zz_ready || !_zz_iswatched(fd) || _zz_disabled)
     329        return ret;
     330
     331    if(ret == 0)
     332    {
     333        void *tmp = malloc(numbytes);
     334        memcpy(tmp, (void *)*addr, numbytes);
     335        _zz_fuzz(fd, tmp, numbytes);
     336        *addr = (vm_offset_t)tmp;
     337        /* FIXME: the map is never freed; there is no such thing as unmap_fd,
     338         * but I suppose that kind of map should go when the filedesciptor is
     339         * closed (unlike mmap, which returns a persistent buffer). */
     340    }
     341
     342    debug("map_fd(%i, %lli, &%p, %i, %lli) = %i", fd, (long long int)offset,
     343          (void *)*addr, (int)find_space, (long long int)numbytes, ret);
     344
     345    return ret;
     346}
     347#endif
     348
    308349int close(int fd)
    309350{
Note: See TracChangeset for help on using the changeset viewer.