From 324203f79bc432d096c3b1831311dbf1bedac856 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 15:54:24 -0500 Subject: [PATCH] arch/x86: rearrange for standard use of extern "C" Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Background from issue #17997: Declarations that use C linkage should be placed within extern "C" so the language linkage is correct when the header is included by a C++ compiler. Similarly #include directives should be outside the extern "C" to ensure the language-specific default linkage is applied to any declarations provided by the included header. See: https://en.cppreference.com/w/cpp/language/language_linkage Signed-off-by: Peter Bigot --- arch/x86/include/ia32/kernel_arch_func.h | 4 ++-- include/arch/x86/ia32/arch.h | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/ia32/kernel_arch_func.h b/arch/x86/include/ia32/kernel_arch_func.h index 574c441fdb9..c9580d352b2 100644 --- a/arch/x86/include/ia32/kernel_arch_func.h +++ b/arch/x86/include/ia32/kernel_arch_func.h @@ -12,6 +12,8 @@ #ifndef _ASMLANGUAGE +#include /* For size_t */ + #ifdef __cplusplus extern "C" { #endif @@ -92,8 +94,6 @@ static inline struct x86_mmu_pdpt *z_x86_pdpt_get(struct k_thread *thread) /* ASM code to fiddle with registers to enable the MMU with PAE paging */ void z_x86_enable_paging(void); -#include /* For size_t */ - #ifdef __cplusplus } #endif diff --git a/include/arch/x86/ia32/arch.h b/include/arch/x86/ia32/arch.h index 1c0f1a24767..6c2848716d3 100644 --- a/include/arch/x86/ia32/arch.h +++ b/include/arch/x86/ia32/arch.h @@ -25,13 +25,12 @@ #include #ifndef _ASMLANGUAGE +#include /* for size_t */ + #include #include -#endif -#ifdef __cplusplus -extern "C" { -#endif +#endif /* _ASMLANGUAGE */ /* GDT layout */ #define CODE_SEG 0x08 @@ -53,9 +52,13 @@ extern "C" { #ifndef _ASMLANGUAGE -/* interrupt/exception/error related definitions */ +#ifdef __cplusplus +extern "C" { +#endif +/* interrupt/exception/error related definitions */ + /* * The TCS must be aligned to the same boundary as that used by the floating * point register set. This applies even for threads that don't initially @@ -315,10 +318,6 @@ struct _x86_syscall_stack_frame { u32_t ss; }; -#endif /* !_ASMLANGUAGE */ - -#ifndef _ASMLANGUAGE - /** * * @internal @@ -561,8 +560,6 @@ extern void k_float_enable(struct k_thread *thread, unsigned int options); * @} */ -#include /* for size_t */ - extern void k_cpu_idle(void); extern u32_t z_timer_cycle_get_32(void); @@ -809,10 +806,10 @@ int z_x86_mmu_validate(struct x86_mmu_pdpt *pdpt, void *addr, size_t size, int write); #endif /* CONFIG_X86_MMU */ -#endif /* !_ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* !_ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_X86_IA32_ARCH_H_ */