Linux segfault meaning
yanyg@t430:~/platform/build$ sudo cat /var/log/messages | grep segfault Mar 3 22:35:23 t430 kernel: [259968.485176] test_memory[25547]: segfault at 0 ip 0000561ca344c481 sp 00007fff51370480 error 6 in test_memory[561ca343e000+3e000] Mar 3 22:36:01 t430 kernel: [260006.883227] test_memory[27588]: segfault at 0 ip 000055937db1f496 sp 00007ffd3ecafef0 error 6 in test_memory[55937db11000+3e000] Mar 3 22:36:12 t430 kernel: [260017.962634] test_memory[28159]: segfault at 0 ip 000055c8ac8c4496 sp 00007ffec8b966b0 error 6 in test_memory[55c8ac8b6000+3e000] Mar 3 22:38:37 t430 kernel: [260162.515243] test_memory[1919]: segfault at 0 ip 0000561b33b8b496 sp 00007fffdb075e90 error 4 in test_memory[561b33b7d000+3e000] Mar 3 22:43:01 t430 kernel: [260426.348912] test_memory[13029]: segfault at 0 ip 0000564c5bc9f486 sp 00007ffe05d4e3b0 error 4 in test_memory[564c5bc91000+3e000] Mar 3 22:45:51 t430 kernel: [260596.608846] test_memory[21028]: segfault at 0 ip 000056186403d4db sp 00007fff77c5fb50 error 6 in test_memory[56186402f000+3e000] Mar 3 22:48:37 t430 kernel: [260762.502445] test_memory[26497]: segfault at 0 ip 0000560b14cc84db sp 00007fffbd248ef0 error 6 in test_memory[560b14cba000+3e000]
- test_memory[26497]: 进程binary名称和ID;
- at 0: 尝试访问无效地址0;
- ip 0000560b14cc84db: 正在执行的指令(rip);
- sp 00007fffbd248ef0: 当前堆栈指针(rsp);
- error: 4 用户态读,6用户态写
/* * Page fault error code bits: * * bit 0 == 0: no page found 1: protection fault * bit 1 == 0: read access 1: write access * bit 2 == 0: kernel-mode access 1: user-mode access * bit 3 == 1: use of reserved bit detected * bit 4 == 1: fault was an instruction fetch * bit 5 == 1: protection keys block access */ enum x86_pf_error_code { X86_PF_PROT = 1 << 0, X86_PF_WRITE = 1 << 1, X86_PF_USER = 1 << 2, X86_PF_RSVD = 1 << 3, X86_PF_INSTR = 1 << 4, X86_PF_PK = 1 << 5, };
- in test_memory[560b14cba000+3e000]: 发生问题时ip所在的虚拟地址范围,
560b14cba000是起始地址,3e000是size;