5
\$\begingroup\$

We've had challenges for SIGSEGV and SIGILL so why not...

Write the shortest code that results in a Bus Error (SIGBUS) in any programming language.

Your program can't call raise() or kill(getpid(),sig) or pthread_kill(pthread_self(),sig), or any other equivalent.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ @ГригорийПерельман It's not a duplicate, no answer for that challenge can be applied to this one without nontrivial modification. \$\endgroup\$
    – orlp
    Commented Mar 21, 2017 at 6:25
  • 6
    \$\begingroup\$ @orlp There are Bash, Python, Perl, and C answers that are all essentially raise(11). They can be trivially modified to be raise(7) instead for this challenge. \$\endgroup\$
    – user45941
    Commented Mar 21, 2017 at 6:55
  • 2
    \$\begingroup\$ Are you riding the SIGBUS, or driving it? \$\endgroup\$
    – mbomb007
    Commented Mar 21, 2017 at 19:13
  • \$\begingroup\$ Java/Groovy is also just System.exit(#); where you only change the # to throw a different exit code... This is a very trivial difference in many languages. \$\endgroup\$ Commented Mar 21, 2017 at 19:29
  • 1
    \$\begingroup\$ Voting to reopen because the rule "Your program can't call raise() or kill(getpid(),sig) or pthread_kill(pthread_self(),sig), or any other equivalent." bans those copy-paste answers. \$\endgroup\$ Commented Feb 17, 2020 at 22:32

1 Answer 1

6
\$\begingroup\$

x86_64 bytecode, 15 bytes

   0:   c7 04 24 00 00 04 00    movl   $0x40000,(%rsp)
   7:   9d                      popfq  
   8:   8b 04 25 01 00 00 00    mov    0x1,%eax

Turns on the misaligned address trap flag and then immediately triggers it.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.