Debugging SIGBUS on x86 Linux

前端 未结 9 1323
生来不讨喜
生来不讨喜 2020-11-30 08:38

What can cause SIGBUS (bus error) on a generic x86 userland application in Linux? All of the discussion I\'ve been able to find online is regarding memory alignment errors,

相关标签:
9条回答
  • 2020-11-30 09:38

    If you request a mapping backed by hugepages with mmap and the MAP_HUGETLB flag, you can get SIGBUS if the kernel runs out of allocated huge pages and thus cannot handle a page fault.

    In this case, you'll need to raise the number of allocated huge pages via

    • /sys/kernel/mm/hugepages/hugepages-<size>/nr_hugepages or
    • /sys/devices/system/node/nodeX/hugepages/hugepages-<size>/nr_hugepages on NUMA systems.
    0 讨论(0)
  • 2020-11-30 09:39

    A common cause of a bus error on x86 Linux is attempting to dereference something that is not really a pointer, or is a wild pointer. For example, failing to initialize a pointer, or assigning an arbitrary integer to a pointer and then attempting to dereference it will normally produce either a segmentation fault or a bus error.

    Alignment does apply to x86. Even though memory on an x86 is byte-addressable (so you can have a char pointer to any address), if you have for example an pointer to a 4-byte integer, that pointer must be aligned.

    You should run your program in gdb and determine which pointer access is generating the bus error to diagnose the issue.

    0 讨论(0)
  • 2020-11-30 09:39

    It's a bit off the beaten path, but you can get SIGBUS from an unaligned SSE2 (m128) load.

    0 讨论(0)
提交回复
热议问题