Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>#include &lt;stdio.h&gt; int main(int argc, char **argv) { char c[] = "a"; printf("%d\n", *(int*)(c)); } </code></pre> <p>This gives me a <a href="http://en.wikipedia.org/wiki/SIGBUS" rel="nofollow noreferrer">SIGBUS</a> after setting <code>set $ps |= (1&lt;&lt;18)</code> in gdb, which apparently is thrown when address alignment is incorrect (amongst other reasons).</p> <p>EDIT: It's fairly easy to raise SIGBUS:</p> <pre><code>int main(int argc, char **argv) { /* EDIT: enable AC check */ asm("pushf; " "orl $(1&lt;&lt;18), (%esp); " "popf;"); char c[] = "1234567"; char d[] = "12345678"; return 0; } </code></pre> <p>Looking at main's disassembly in gdb:</p> <pre><code>Dump of assembler code for function main: .... 0x08048406 &lt;main+34&gt;: mov 0x8048510,%eax 0x0804840b &lt;main+39&gt;: mov 0x8048514,%edx 0x08048411 &lt;main+45&gt;: mov %eax,-0x10(%ebp) 0x08048414 &lt;main+48&gt;: mov %edx,-0xc(%ebp) 0x08048417 &lt;main+51&gt;: movl $0x34333231,-0x19(%ebp) &lt;== BAM! SIGBUS 0x0804841e &lt;main+58&gt;: movl $0x38373635,-0x15(%ebp) 0x08048425 &lt;main+65&gt;: movb $0x0,-0x11(%ebp) </code></pre> <p>Anyhow, Christoph your test program fails under Linux raising a SIGBUS as it should. It's probably a Windows thing?</p> <hr> <p>You can enable the Alignment Check bit in code using this snippet:</p> <pre><code>/* enable AC check */ asm("pushf; " "orl $(1&lt;&lt;18), (%esp); " "popf;"); </code></pre> <p>Also, ensure that the flag was indeed set:</p> <pre><code>unsigned int flags; asm("pushf; " "movl (%%esp), %0; " "popf; " : "=r"(flags)); fprintf(stderr, "%d\n", flags &amp; (1&lt;&lt;18)); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload