223b7220b8ccc3642433776c4c9d07e01448254cvboxsync/* $Id$ */
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync/** @file
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * IPRT - Internal header for hacking alignment checks on x86 and AMD64.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync */
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2009-2010 Oracle Corporation
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync *
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * available from http://www.virtualbox.org. This file is free software;
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * you can redistribute it and/or modify it under the terms of the GNU
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * General Public License (GPL) as published by the Free Software
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync *
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * The contents of this file may alternatively be used under the terms
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * of the Common Development and Distribution License Version 1.0
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * VirtualBox OSE distribution, in which case the provisions of the
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * CDDL are applicable instead of those of the GPL.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync *
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * You may elect to license modified versions of this file under the
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * terms and conditions of either the GPL or the CDDL or both.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync */
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync#ifndef ___internal_alignmentchecks_h
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync#define ___internal_alignmentchecks_h
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync/** @def IPRT_WITH_ALIGNMENT_CHECKS
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync * Enables or disables the alignment check feature and related hacks. */
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync#ifndef IPRT_WITH_ALIGNMENT_CHECKS
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync# if ( defined(DEBUG) && !defined(IN_GUEST) ) || defined(DOXYGEN_RUNNING)
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync# define IPRT_WITH_ALIGNMENT_CHECKS 1
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync# endif
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync#endif
2360f6acdb82e06abcbf131d33816da062d698c9vboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync/** @def IPRT_ALIGNMENT_CHECKS_DISABLE
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * Disables alignment checks.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * Typically used before calling problematic library functions.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync */
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync/** @def IPRT_ALIGNMENT_CHECKS_ENABLE
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * (re-)Enables alignment checks if they are supposed to be active.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * This is used to counter IPRT_ALIGNMENT_CHECKS_DISABLE as well as enabling
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync * them for the first time.
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync */
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
2f0d866e126dd288169fed591c259c1c6b4016e5vboxsync#if defined(IPRT_WITH_ALIGNMENT_CHECKS) \
2f0d866e126dd288169fed591c259c1c6b4016e5vboxsync && ( defined(RT_ARCH_AMD64) \
2f0d866e126dd288169fed591c259c1c6b4016e5vboxsync || defined(RT_ARCH_X86) )
2f0d866e126dd288169fed591c259c1c6b4016e5vboxsync# include <iprt/asm-amd64-x86.h>
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsyncRT_C_DECLS_BEGIN
223b7220b8ccc3642433776c4c9d07e01448254cvboxsyncextern RTDATADECL(bool) g_fRTAlignmentChecks;
223b7220b8ccc3642433776c4c9d07e01448254cvboxsyncRT_C_DECLS_END
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync# define IPRT_ALIGNMENT_CHECKS_DISABLE() \
b0738128c45e3f85ad96ff0e968c11b1448d0fbbvboxsync do { if (g_fRTAlignmentChecks) ASMSetFlags(ASMGetFlags() & ~RT_BIT_32(18)); } while (0)
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync# define IPRT_ALIGNMENT_CHECKS_ENABLE() \
b0738128c45e3f85ad96ff0e968c11b1448d0fbbvboxsync do { if (g_fRTAlignmentChecks) ASMSetFlags(ASMGetFlags() | RT_BIT_32(18)); } while (0)
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync#else
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync# define IPRT_ALIGNMENT_CHECKS_DISABLE() do {} while (0)
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync# define IPRT_ALIGNMENT_CHECKS_ENABLE() do {} while (0)
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync#endif
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync#endif
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync