WWDC2015 Advanced Debugging and the address santinizer

打全局?jǐn)帱c(diǎn)的時(shí)候 控制臺(tái)不會(huì)輸出exception
可以通過輸入 po $arg1 來輸出錯(cuò)誤

What Is Address Sanitizer

Similar to Guard Malloc and Valgrind
Finds memory corruption at runtime
Less overhead
Integrated into Debug Navigator
Works on OS X, iOS(simulator and device)

Analyze Memory Corruption

Use after free
Heap buffer overflow
Stack buffer overflow
Global variable overflow
Overflows in C++ containers
Use after return

Compiler Optimization Level

None [00] is recommended
Fast [
01] is supported
Higher optimization is not supported

How Address Sanitizer Works

clang -fsanitize=address
At runtime, this binary links with as an runtime dylib that contains even more checks, and that dylib is required by the instrumentation

會(huì)進(jìn)行一個(gè)檢查

*p = 0xb00

--->

if (IsPoisoned(p)) Crash();
*p = 0xb00;

Shadow Mapping

IsPoisoned needs to be fast
1/8 of the address space
mmap'd at lunch

bool IsPosioned(Addr) {
  Shadow = Addr >> 3 + offset
  return (*Shadow) != 0
}

Heap

更改Malloc 的方式,從默認(rèn)的連續(xù)分配內(nèi)存改成間隔分配

Custom Malloc Implementation

Inserts poisoned "red zones" around allocations
Heap underflows/overflows
Delay reuse of freed memory
Use-after-free, double free
Collects stack traces for allocations and frees
Comprehensive error reports

Guard Malloc
NSZombie
Malloc SCribble
image.png
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,872評(píng)論 0 10
  • Redis 配置文件示例 注意:想要讀取配置文件,Redis的第一個(gè)參數(shù)必須是文件的路徑 ./redis-serv...
    起個(gè)名忒難閱讀 1,361評(píng)論 0 1
  • This chapter discusses some of the design decisions that ...
    狂風(fēng)無跡閱讀 1,096評(píng)論 0 0
  • 2018年最后一個(gè)月已悄然而至,回想這一年好像并沒有什么成就??剂藥状蔚睦蠋?,終以兩分之差而告終。挫敗了信心,人也...
    文ww文閱讀 315評(píng)論 0 3
  • 酒店的門突然開了,一陣?yán)滹L(fēng)毫無顧忌地卷了進(jìn)來,奕楠正百無聊賴地坐在酒店大堂的沙發(fā)上,被這突然襲來的冷風(fēng)刺激了一...
    博贊教育張老師閱讀 467評(píng)論 0 6

友情鏈接更多精彩內(nèi)容