confirm results
[tridge/junkcode.git] / preload_mmap.c
1 #include <sys/mman.h>
2 #include <sys/types.h>
3 #include <dlfcn.h>
4 #include <fcntl.h>
5
6 void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
7 {
8         static void *h;
9         static void *(*mmap_orig)(void *, size_t , int , int , int, off_t );
10         static int log_fd;
11         static char buf[200];
12         int n;
13         void *ret;
14
15         if (!h) {
16                 h = dlopen("/lib/libc.so.6", RTLD_LAZY);
17                 mmap_orig = dlsym(h, "mmap");
18                 log_fd = open("/tmp/mmap.log", O_WRONLY|O_CREAT|O_APPEND, 0666);
19         }
20
21         ret = mmap_orig(start, length, prot, flags, fd, offset);
22
23         n = snprintf(buf, sizeof(buf), "mmap(%p, 0x%x, 0x%x, 0x%x, %d, 0x%x) = %p\n", 
24                      start, length, prot, flags, fd, offset, ret);
25         
26         write(log_fd, buf, n);
27
28         return ret;
29 }