Changeset 1631 for zzuf


Ignore:
Timestamp:
Jan 9, 2007, 11:02:57 AM (13 years ago)
Author:
Sam Hocevar
Message:
  • Implement map_fd for OS X.
Location:
zzuf/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/configure.ac

    r1628 r1631  
    1515AC_PROG_LIBTOOL
    1616
    17 AC_CHECK_HEADERS(inttypes.h stdint.h getopt.h)
    18 AC_CHECK_FUNCS(open64 lseek64 mmap64 fopen64 fseeko _IO_getc getline getdelim __getdelim fgetln __srefill)
     17AC_CHECK_HEADERS(inttypes.h stdint.h getopt.h libc.h)
     18AC_CHECK_FUNCS(open64 lseek64 mmap64 fopen64 fseeko _IO_getc getline getdelim __getdelim fgetln __srefill map_fd)
    1919AC_CHECK_TYPES(sighandler_t, [], [],
    2020  [#define _GNU_SOURCE
  • zzuf/trunk/doc/zzuf.1

    r1624 r1631  
    282282\fBfgetln\fR(), \fB__srefill\fR()
    283283.TP
     284Mac OS X-specific:
     285\fBmap_fd\fR()
     286.TP
    284287Signal handling:
    285288\fBsignal\fR(), \fBsigaction\fR()
  • 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.