[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 3/4] plat/*: Introduce library constructors



This patch adds an array called ukplat_ctortab to the read-only
data section (rodata). This array is NULL-terminated and
consists of function pointers to constructors. The pointers are
sorted by priority (0-7) and the array is populated at link
time. Libraries can register a constructor function by using
the new macro UKPLAT_CTOR_FUNC() (provided with
include/uk/plat/ctors.h). It is intended that a bootstrapping
library is executing each function during boot so that
libraries can execute necessary initialization routines.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 include/uk/plat/ctors.h   | 82 +++++++++++++++++++++++++++++++++++++++++++++++
 plat/kvm/x86/link64.ld    | 21 ++++++++++++
 plat/linuxu/arm/link32.ld | 21 ++++++++++++
 plat/linuxu/x86/link64.ld | 21 ++++++++++++
 plat/xen/arm/link32.ld    | 28 +++++++++++++++-
 plat/xen/x86/link64.ld    | 21 ++++++++++++
 6 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 include/uk/plat/ctors.h

diff --git a/include/uk/plat/ctors.h b/include/uk/plat/ctors.h
new file mode 100644
index 0000000..b992d12
--- /dev/null
+++ b/include/uk/plat/ctors.h
@@ -0,0 +1,82 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ *
+ *
+ * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#ifndef __UKPLAT_CTORS_H__
+#define __UKPLAT_CTORS_H__
+
+#include <uk/essentials.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*ukplat_ctor_func_t)(void);
+
+
+/**
+ * NULL-terminated list of constructor function pointers.
+ * Array is generated by linker script.
+ * Functions have to be called during bootstrapping
+ * (e.g., libukboot).
+ */
+extern const ukplat_ctor_func_t ukplat_ctortab[];
+
+
+/**
+ * Register a constructor function that is
+ * called during bootstrapping
+ *
+ * @param lvl
+ *   Priority level (0 (earliest) -7 (latest))
+ *   Note: Any other value for level will be ignored
+ * @param ctorf
+ *   Constructor function to be called
+ */
+#define UKPLAT_CTOR_FUNC(lvl, ctorf) \
+       _UKPLAT_CTOR_FUNC(lvl, __LIBNAME__, ctorf)
+
+#define _UKPLAT_CTOR_FUNC(lvl, libname, ctorf) \
+       __UKPLAT_CTOR_FUNC(lvl, libname, ctorf)
+
+#define __UKPLAT_CTOR_FUNC(lvl, libname, ctorf) \
+       static const ukplat_ctor_func_t \
+       __used __section(".ukplat_ctortab" #lvl) \
+       __ukplat_ctab ## lvl ## _ ## libname ## _ ## ctorf = (ctorf)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UKPLAT_CTORS_H__ */
diff --git a/plat/kvm/x86/link64.ld b/plat/kvm/x86/link64.ld
index 85ea058..b70557c 100644
--- a/plat/kvm/x86/link64.ld
+++ b/plat/kvm/x86/link64.ld
@@ -48,6 +48,27 @@ SECTIONS {
     {
         *(.rodata)
         *(.rodata.*)
+
+        /* Constructor table */
+        . = ALIGN(0x8);
+        ukplat_ctortab = .;
+        *(.ukplat_ctortab0)
+        *(.ukplat_ctortab0.*)
+        *(.ukplat_ctortab1)
+        *(.ukplat_ctortab1.*)
+        *(.ukplat_ctortab2)
+        *(.ukplat_ctortab2.*)
+        *(.ukplat_ctortab3)
+        *(.ukplat_ctortab3.*)
+        *(.ukplat_ctortab4)
+        *(.ukplat_ctortab4.*)
+        *(.ukplat_ctortab5)
+        *(.ukplat_ctortab5.*)
+        *(.ukplat_ctortab6)
+        *(.ukplat_ctortab6.*)
+        *(.ukplat_ctortab7)
+        *(.ukplat_ctortab7.*)
+        LONG(0); /* NULL termination */
     }
     .eh_frame :
     {
diff --git a/plat/linuxu/arm/link32.ld b/plat/linuxu/arm/link32.ld
index 7dac4f6..1122979 100644
--- a/plat/linuxu/arm/link32.ld
+++ b/plat/linuxu/arm/link32.ld
@@ -54,6 +54,27 @@ SECTIONS {
        {
                *(.rodata)
                *(.rodata.*)
+
+               /* Constructor table */
+               . = ALIGN(0x4);
+               ukplat_ctortab = .;
+               *(.ukplat_ctortab0)
+               *(.ukplat_ctortab0.*)
+               *(.ukplat_ctortab1)
+               *(.ukplat_ctortab1.*)
+               *(.ukplat_ctortab2)
+               *(.ukplat_ctortab2.*)
+               *(.ukplat_ctortab3)
+               *(.ukplat_ctortab3.*)
+               *(.ukplat_ctortab4)
+               *(.ukplat_ctortab4.*)
+               *(.ukplat_ctortab5)
+               *(.ukplat_ctortab5.*)
+               *(.ukplat_ctortab6)
+               *(.ukplat_ctortab6.*)
+               *(.ukplat_ctortab7)
+               *(.ukplat_ctortab7.*)
+               LONG(0);
        }
        . = ALIGN(0x1000);
        _erodata = .;
diff --git a/plat/linuxu/x86/link64.ld b/plat/linuxu/x86/link64.ld
index a7d642d..a09b89c 100644
--- a/plat/linuxu/x86/link64.ld
+++ b/plat/linuxu/x86/link64.ld
@@ -55,6 +55,27 @@ SECTIONS {
        {
                *(.rodata)
                *(.rodata.*)
+
+               /* Constructor table */
+               . = ALIGN(0x8);
+               ukplat_ctortab = .;
+               *(.ukplat_ctortab0)
+               *(.ukplat_ctortab0.*)
+               *(.ukplat_ctortab1)
+               *(.ukplat_ctortab1.*)
+               *(.ukplat_ctortab2)
+               *(.ukplat_ctortab2.*)
+               *(.ukplat_ctortab3)
+               *(.ukplat_ctortab3.*)
+               *(.ukplat_ctortab4)
+               *(.ukplat_ctortab4.*)
+               *(.ukplat_ctortab5)
+               *(.ukplat_ctortab5.*)
+               *(.ukplat_ctortab6)
+               *(.ukplat_ctortab6.*)
+               *(.ukplat_ctortab7)
+               *(.ukplat_ctortab7.*)
+               LONG(0); /* NULL termination */
        }
        . = ALIGN(0x1000);
        _erodata = .;
diff --git a/plat/xen/arm/link32.ld b/plat/xen/arm/link32.ld
index 77184c0..72182c9 100644
--- a/plat/xen/arm/link32.ld
+++ b/plat/xen/arm/link32.ld
@@ -47,8 +47,34 @@ SECTIONS
 
        _etext = .;                     /* End of text section */
 
+       /* Read-only data */
        _rodata = .;
-       .rodata : { *(.rodata) *(.rodata.*) }
+       .rodata :
+       {
+               *(.rodata)
+               *(.rodata.*)
+
+               /* Constructor table */
+               . = ALIGN(0x4);
+               ukplat_ctortab = .;
+               *(.ukplat_ctortab0)
+               *(.ukplat_ctortab0.*)
+               *(.ukplat_ctortab1)
+               *(.ukplat_ctortab1.*)
+               *(.ukplat_ctortab2)
+               *(.ukplat_ctortab2.*)
+               *(.ukplat_ctortab3)
+               *(.ukplat_ctortab3.*)
+               *(.ukplat_ctortab4)
+               *(.ukplat_ctortab4.*)
+               *(.ukplat_ctortab5)
+               *(.ukplat_ctortab5.*)
+               *(.ukplat_ctortab6)
+               *(.ukplat_ctortab6.*)
+               *(.ukplat_ctortab7)
+               *(.ukplat_ctortab7.*)
+               LONG(0); /* NULL termination */
+       }
        . = ALIGN(4096);
        _erodata = .;
 
diff --git a/plat/xen/x86/link64.ld b/plat/xen/x86/link64.ld
index dd092aa..df43034 100644
--- a/plat/xen/x86/link64.ld
+++ b/plat/xen/x86/link64.ld
@@ -43,6 +43,27 @@ SECTIONS
        .rodata : {
                *(.rodata)
                *(.rodata.*)
+
+               /* Constructor table */
+               . = ALIGN(0x8);
+               ukplat_ctortab = .;
+               *(.ukplat_ctortab0)
+               *(.ukplat_ctortab0.*)
+               *(.ukplat_ctortab1)
+               *(.ukplat_ctortab1.*)
+               *(.ukplat_ctortab2)
+               *(.ukplat_ctortab2.*)
+               *(.ukplat_ctortab3)
+               *(.ukplat_ctortab3.*)
+               *(.ukplat_ctortab4)
+               *(.ukplat_ctortab4.*)
+               *(.ukplat_ctortab5)
+               *(.ukplat_ctortab5.*)
+               *(.ukplat_ctortab6)
+               *(.ukplat_ctortab6.*)
+               *(.ukplat_ctortab7)
+               *(.ukplat_ctortab7.*)
+               LONG(0); /* NULL termination */
        }
        . = ALIGN(4096);
        _erodata = .;
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.