← Back to davo.co
summaryrefslogtreecommitdiffstats
path: root/crash.h
diff options
context:
space:
mode:
authorDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
committerDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
commitb3e9e62599532050fc776c5e8f076915b56c2235 (patch)
treeaf252346106a61b18cc6fc6fdbd32e962d096f1c /crash.h
Import official C23 code examples for Modern C (Jens Gustedt, 2024)HEADupstream-importmain
- Add official C source files, Makefile, c23-fallback.h, and LICENSE - Update README.md with study mirror notice
Diffstat (limited to 'crash.h')
-rw-r--r--crash.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/crash.h b/crash.h
new file mode 100644
index 0000000..6f522b8
--- /dev/null
+++ b/crash.h
@@ -0,0 +1,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