GithubHelp home page GithubHelp logo

Comments (4)

maocanmao avatar maocanmao commented on May 22, 2024 1

@maocanmao 请问是发现了问题原因才close的吗?前几天事情比较多,这周本来打算查一下这个问题的。

我把hook malloc calloc realloc 这几个函数的hookcallback函数去掉了,内存占用就下来了。但是我在callback里也只是打了一行日志

from bhook.

caikelun avatar caikelun commented on May 22, 2024

没有遇到过,建议逐步减少hook点对比分析。另外:

  1. 建议检查下代码,有没有类似memalign proxy中调用calloc的情况
  2. 请用最新版本的bytehook再试一下,看是否有区别
  3. 可以对比分析下maps和smaps
  4. bytehook本身以及hook行为确实需要占用一些内存(对GOT的修改本身会引起private dirty的增加,记录solist用于发现新加载so,记录hook信息用于unhook和log,auto mode需要为每个hook点的每个caller保存调用信息用于避免环形调用),但不会占用“大几百M”。如果对内存占用的要求比较苛刻,可以试一下manual mode,占用内存会相对少一点

from bhook.

maocanmao avatar maocanmao commented on May 22, 2024

大佬,我这边升级了最新版本的bytehook,通过减少hook点,发现如果开启hook malloc calloc realloc 的时候(部分hook,有几个so排除在外),native heap会显著增大。
未开启时
image
开启时
image

hook函数中也没有做什么事,很奇怪。

    malloc_hook_stub = bytehook_hook_partial(hook_filter, nullptr, nullptr, "malloc",
                                             (void *) my_malloc,(bytehook_hooked_t) hookedMallocCallback, nullptr);

    calloc_hook_stub = bytehook_hook_partial(hook_filter, nullptr, nullptr, "calloc",
                                             (void *) my_calloc,(bytehook_hooked_t) hookedMallocCallback, nullptr);

    realloc_hook_stub = bytehook_hook_partial(hook_filter, nullptr, nullptr, "realloc",
                                              (void *) my_realloc,(bytehook_hooked_t) hookedMallocCallback, nullptr);
void *my_malloc(size_t size) {
    BYTEHOOK_STACK_SCOPE();
    void *result = BYTEHOOK_CALL_PREV(my_malloc, size);
    return result;
}

void *my_calloc(size_t count, size_t size) {
    BYTEHOOK_STACK_SCOPE();
    void *result = BYTEHOOK_CALL_PREV(my_calloc, count, size);
    return result;
}

void *my_realloc(void *ptr, size_t size) {
    BYTEHOOK_STACK_SCOPE();
    void *result = BYTEHOOK_CALL_PREV(my_realloc, ptr, size);
    return result;
}

另外对比了一下smaps,主要的区别就是libc_malloc的大小
110008 kB : [anon:libc_malloc]
237788 kB : [anon:libc_malloc]

from bhook.

caikelun avatar caikelun commented on May 22, 2024

@maocanmao 请问是发现了问题原因才close的吗?前几天事情比较多,这周本来打算查一下这个问题的。

from bhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.