zoukankan      html  css  js  c++  java
  • 堆越界--coredump 在malloc函数里

    一,可执行程序分析: 

    objdump -h xxx,可以看到程序内部各个段的内存分布,结果如下(部分): 

     26 .data         0000016c  0000000000879d20  0000000000879d20  00279d20  2**5
                      CONTENTS, ALLOC, LOAD, DATA
     27 .bss          00001000  0000000000879ea0  0000000000879ea0  00279e8c  2**5
                      ALLOC

     实时上,各个段的信息不包括heap和stack的信息。

    二,signal 11, Segment Fault。

    malloc,内存块实际上是挂在链表上。数据结构包括next,内容,大小。不能被写坏,否则可能造成coredump。

    原因见malloc / free 流程图(数据结构)。 

    今天看见一篇写得很好的文章可以说明这个问题:-- 

    http://www.cnblogs.com/onlyforcloud/articles/4476436.html 
    1. malloc实际是调用Void_t*  public_mALLOc(size_t) --> victim = _int_malloc(ar_ptr, bytes); 接下来分析 _int_malloc内部流程
    2. 根据size_t传递的大小计算出mfastbinptr。(idx = fastbin_index(nb);mfastbinptr* fb = &fastbin (av, idx);)| #define fastbin_index(sz)  ((((unsigned int)(sz)) >> (SIZE_SZ == 8 ? 4 : 3)) - 2) | #define fastbin(ar_ptr, idx) ((ar_ptr)->fastbinsY[idx]) | struct malloc_state { ... mfastbinptr fastbinsY[NFASTBINS]; ... }
    3. 因此实际上public_mALLOc会从 arena_lookup(ar_ptr)里查找出ar_ptr。 
    4. # define tsd_getspecific(key, vptr) (vptr = (key))
    5. static tsd_key_t arena_key; ar_ptr实际等于arena_key.

    6. typedef struct malloc_chunk* mchunkptr; 

    7. sYSMALLOc -> struct malloc_par
  • 相关阅读:
    Python-Image 基本的图像处理操作
    剪枝
    poj1182(食物链)续
    HLG2035广搜
    HLG2040二叉树遍历已知前中,求后
    先序,中序,后序,已知两者求第三者
    C++中new的解说
    僵尸进程
    HLG2062(make,heap问题)
    make_head,,,pop_head,,,push_head,,,sort_head..
  • 原文地址:https://www.cnblogs.com/onlyforcloud/p/4465456.html
Copyright © 2011-2022 走看看