diff options
| author | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
|---|---|---|
| committer | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
| commit | b3e9e62599532050fc776c5e8f076915b56c2235 (patch) | |
| tree | af252346106a61b18cc6fc6fdbd32e962d096f1c /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.h | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -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 |
