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,
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.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.
It's a bit off the beaten path, but you can get SIGBUS from an unaligned SSE2 (m128) load.