Dereferencing a null pointer

前端 未结 5 2047
时光说笑
时光说笑 2021-01-18 05:10

Why I can\'t dereference a null pointer? That is, why I can\'t read/write memory which address is simply 0?

Does the base pointer of my process have a different addr

5条回答
  •  不要未来只要你来
    2021-01-18 05:47

    The VM page that sits at address (void *)0x0 or NULL is by default not mapped in any modern OS, thus dereferencing a NULL pointer will result in a segmentation violation.

    NULL pointers are frequently used as pointers that point nowhere.

    Yes, you can obtain the address of your text, stack and heap bases. For stack this is relatively easy, for text and heap you will need to consult /proc/self/smaps (if you have procfs).

提交回复
热议问题