From 3225db018ae5ccf156735bcd603a090ee235b0c1 Mon Sep 17 00:00:00 2001 From: kib Date: Wed, 21 Mar 2018 10:26:39 +0000 Subject: [PATCH] Move sysinit and sysuninit linker sets in the data (writeable) section. Both sets are sorted in place, and with the introduction of read-only permissions on the amd64 kernel text, the sorting override depended on CR0.WP turned off. Make it correct by moving the sets into writeable part of the KVA, also fixing boot on machines where hand-off from BIOS to OS occurs with CR0.WP set. Based on submission by: Peter Lei MFC after: 1 week --- sys/sys/kernel.h | 6 +++--- sys/sys/linker_set.h | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h index 2e103c7804b1..a9bfaa9ef7c4 100644 --- a/sys/sys/kernel.h +++ b/sys/sys/kernel.h @@ -259,7 +259,7 @@ sysinit_tslog_shim(const void * data) sysinit_tslog_shim, \ &uniquifier ## _sys_init_tslog \ }; \ - DATA_SET(sysinit_set,uniquifier ## _sys_init) + DATA_WSET(sysinit_set,uniquifier ## _sys_init) #else #define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ static struct sysinit uniquifier ## _sys_init = { \ @@ -268,7 +268,7 @@ sysinit_tslog_shim(const void * data) func, \ (ident) \ }; \ - DATA_SET(sysinit_set,uniquifier ## _sys_init) + DATA_WSET(sysinit_set,uniquifier ## _sys_init) #endif #define SYSINIT(uniquifier, subsystem, order, func, ident) \ @@ -285,7 +285,7 @@ sysinit_tslog_shim(const void * data) func, \ (ident) \ }; \ - DATA_SET(sysuninit_set,uniquifier ## _sys_uninit) + DATA_WSET(sysuninit_set,uniquifier ## _sys_uninit) #define SYSUNINIT(uniquifier, subsystem, order, func, ident) \ C_SYSUNINIT(uniquifier, subsystem, order, \ diff --git a/sys/sys/linker_set.h b/sys/sys/linker_set.h index 01d0bff98410..9f49b802887b 100644 --- a/sys/sys/linker_set.h +++ b/sys/sys/linker_set.h @@ -56,12 +56,13 @@ * Private macros, not to be used outside this header file. */ #ifdef __GNUCLIKE___SECTION -#define __MAKE_SET(set, sym) \ +#define __MAKE_SET_QV(set, sym, qv) \ __GLOBL(__CONCAT(__start_set_,set)); \ __GLOBL(__CONCAT(__stop_set_,set)); \ - static void const * __MAKE_SET_CONST \ + static void const * qv \ __set_##set##_sym_##sym __section("set_" #set) \ __used = &(sym) +#define __MAKE_SET(set, sym) __MAKE_SET_QV(set, sym, __MAKE_SET_CONST) #else /* !__GNUCLIKE___SECTION */ #error this file needs to be ported to your compiler #endif /* __GNUCLIKE___SECTION */ @@ -71,6 +72,7 @@ */ #define TEXT_SET(set, sym) __MAKE_SET(set, sym) #define DATA_SET(set, sym) __MAKE_SET(set, sym) +#define DATA_WSET(set, sym) __MAKE_SET_QV(set, sym, ) #define BSS_SET(set, sym) __MAKE_SET(set, sym) #define ABS_SET(set, sym) __MAKE_SET(set, sym) #define SET_ENTRY(set, sym) __MAKE_SET(set, sym)