开发者

using dlsym for tracking mmap

I am trying to measure how much memory does some program mmaps. I am using the following code:

void * mmap (void * addr, size_t len, int prot, int flags, int fildes, off_t off) {
    printf("in mmap1\n");
    static void *(*realfn)(void*, size_t, int, int, int, off_t)
     = (void *(*)(void*, size_t, int, int, int, off_t))dlsym(RTLD_NEXT, "mmap");
    printf("in mmap2\n");
    void * result = (*realfn)(addr, len, prot, flags, fildes, off);
    if ((int) result != -1) {
      stats.add (len);
    }
    return result;
  }

stats is some global variable that saves the stats. I turn this code into a shared object and link with it. For some programs it works, but for some programs, in mmap1 is printed once, then in mmap1 is printed again, and then nothing happens (the program gets stuck at this point until I kill it, never reaching in mmap2.

I read about dlsym, but I can't find the problem causing this. I would love to here from someone more experienced. 开发者_运维技巧 Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜