From mboxrd@z Thu Jan 1 00:00:00 1970 From: Frediano Ziglio Subject: [PATCH 1/5] Call constructors during initialization Date: Wed, 6 Feb 2013 14:32:56 +0000 Message-ID: <1360161180-3448-2-git-send-email-frediano.ziglio@citrix.com> References: <1360161180-3448-1-git-send-email-frediano.ziglio@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1360161180-3448-1-git-send-email-frediano.ziglio@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Konrad Rzeszutek Wilk , "Keir (Xen.org)" , Ian Campbell , Jan Beulich , George Dunlap Cc: Frediano Ziglio , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org This allow modules to set initializer functions. This is used by Gcc instrumentation code for profiling arcs and test coverage. --- xen/arch/arm/setup.c | 2 ++ xen/arch/arm/xen.lds.S | 7 +++++++ xen/arch/x86/setup.c | 2 ++ xen/arch/x86/xen.lds.S | 7 +++++++ xen/common/lib.c | 16 ++++++++++++++++ xen/include/xen/lib.h | 2 ++ 6 files changed, 36 insertions(+) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index e1ab7f6..4b98dd8 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -445,6 +445,8 @@ void __init start_xen(unsigned long boot_phys_offset, scrub_heap_pages(); */ + init_constructors(); + console_endboot(); /* Hide UART from DOM0 if we're using it */ diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 410d7db..bc9eae9 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -84,6 +84,13 @@ SECTIONS *(.init.data) *(.init.data.rel) *(.init.data.rel.*) + + . = ALIGN(8); + __CTOR_LIST__ = .; + QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2) + *(.ctors) + QUAD(0) + __CTOR_END__ = .; } :text . = ALIGN(32); .init.setup : { diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index f4d3788..a75066e 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1313,6 +1313,8 @@ void __init __start_xen(unsigned long mbi_p) init_trace_bufs(); + init_constructors(); + console_endboot(); /* Hide UART from DOM0 if we're using it */ diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index d324afd..5570389 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -108,6 +108,13 @@ SECTIONS __trampoline_seg_start = .; *(.trampoline_seg) __trampoline_seg_stop = .; + + . = ALIGN(8); + __CTOR_LIST__ = .; + QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2) + *(.ctors) + QUAD(0) + __CTOR_END__ = .; } :text . = ALIGN(32); .init.setup : { diff --git a/xen/common/lib.c b/xen/common/lib.c index 03c8b8b..715df82 100644 --- a/xen/common/lib.c +++ b/xen/common/lib.c @@ -2,6 +2,7 @@ #include #include #include +#include #include /* for ctype.h */ @@ -478,6 +479,21 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps) return ret; } +typedef void (*ctor_func_t)(void); + +extern const struct +{ + unsigned long count; + ctor_func_t funcs[1]; +} __CTOR_LIST__; + +void __init init_constructors(void) +{ + unsigned long n; + for ( n = 0; n < __CTOR_LIST__.count; ++n ) + __CTOR_LIST__.funcs[n](); +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index f7074cf..d856ab1 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -125,4 +125,6 @@ extern void add_taint(unsigned); struct cpu_user_regs; void dump_execstate(struct cpu_user_regs *); +void init_constructors(void); + #endif /* __LIB_H__ */ -- 1.7.9.5