x86 64 - Create a memory address alignment on x86 -


i want create memory address alignment fault on x86 machine. why want this? because expressly test out sigbus handler.

here test example.

#include <stdio.h>  int main(int argc, char** argv) {     unsigned char array[32];     short *short_ptr;      short_ptr = (short *)&array[1];     *short_ptr = 0xffff;  // store     printf("value of c = %x", *short_ptr);      return 0; } 

i know create misalignment exception on sparc architecture. but, can't life of me figure out how on x86.

how can it?

to create alignment fault, have set ac flag in eflags. bit 18.

a simple way in assembly is:

pushf       ; push flags onto stack pop eax     ; pop pushed flags eax bts eax, 18 ; set bit 18 in eax (note, might not work. may need "mov ebx, 18; bts eax ebx") push eax    ; push onto stack popf        ; pop eflags stack 

i'm not sure can short, depending on how short short is. 8-bit access aligned, since can't access less 8 bits anyway. try using int sure.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -