Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么调用的common_stack_logger #16

Open
aimsgmiss opened this issue Feb 6, 2018 · 6 comments
Open

怎么调用的common_stack_logger #16

aimsgmiss opened this issue Feb 6, 2018 · 6 comments

Comments

@aimsgmiss
Copy link

common_stack_logger
这个函数怎么调用的,谢谢啦

@aimsgmiss
Copy link
Author

malloc_zone_malloc

hook了malloc_zone_malloc 但是没发现在那里hook

@JunyiXie
Copy link

利用了libmalloc 中的某个函数指针

@biosli
Copy link

biosli commented Feb 27, 2018

去苹果开源库看看libmalloc的代码

@HePingLaoSan
Copy link

HePingLaoSan commented Aug 26, 2019

利用了libmalloc 中的某个函数指针

image

源码中判断了malloc_logger 是否存在,如果存在,则调用对应的方法,但怎么知道iOS系统是否使用了这个函数的呢?

@HePingLaoSan
Copy link

大概了解了,malloc_logger 是一个钩子函数
image hook到了common_stack_logger这个函数上实现了自定义的调用,但是这么做的代价就是disable了系统对于malloc_logger的实现(比如源码中的这个功能turn_on_stack_logging

@MomoYincongxiao
Copy link

MomoYincongxiao commented Nov 22, 2019

注册此类全局函数指针应该保存之前的注册,并在自己的实现中回调回去,否则如果其他组件也想检测malloc调用,就会被后来的注册者冲掉

malloc_logger_t *oom_pre_malloc_logger;
- (void)registerMallocLogger {
    //save previous
    if (malloc_logger && malloc_logger != common_stack_logger) {
        oom_pre_malloc_logger = malloc_logger;
    }
    malloc_logger = (malloc_logger_t *)common_stack_logger;
}
extern malloc_logger_t *ra_oom_pre_malloc_logger;
void common_stack_logger(uint32_t type, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t result, uint32_t backtrace_to_skip)
{
    if (oom_pre_malloc_logger) {
        oom_pre_malloc_logger(type, arg1, arg2, arg3, result, backtrace_to_skip);
    }
    //QQLeak
    malloc_stack_logger(type,arg1,arg2,arg3,result,backtrace_to_skip);
    //OOMDetector
    oom_malloc_logger(type,arg1,arg2,arg3,result,4);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants