← Back to davo.co
summaryrefslogtreecommitdiffstats
path: root/crash.h
blob: 6f522b8790bfc48056c87ed8f336fa58f20d1a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef CRASH_H
#define CRASH_H 1

/**
 ** @brief enable alignment check for i386 processors
 **
 ** Intel's i386 processor family is quite tolerant in accepting
 ** misalignment of data. This can lead to irritating bugs when ported
 ** to other architectures that are not as tolerant.
 **
 ** This function enables a check for this problem also for this
 ** family or processors, such that you can be sure to detect this
 ** problem early.
 **
 ** I found that code on Ygdrasil's blog:
 ** http://orchistro.tistory.com/206
 **/

inline
void enable_alignment_check(void) {
#if defined(__GNUC__)
# if defined(__x86_64__)
  __asm__("pushf\n"
          "\torl $0x40000, (%%rsp)\n"
          "\tpopf"
          : : : "cc");
# elif defined(__i386__)
  __asm__("pushf\n"
          "\torl $0x40000, (%%esp)\n"
          "\tpopf"
          : : : "cc");
# endif
#endif
}


#endif