|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 3/4] plat/*: Provide section for library constructors
This patch adds a section called ukplat_ctortab to the Unikraft
binaries. This section contains a NULL-terminated list of
function pointers of constructors and sorted by priority.
This list is populated at link time. Libraries can register a
function to it by using a new macro called 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 | 84 +++++++++++++++++++++++++++++++++++++++++++++++
plat/kvm/x86/link64.ld | 25 +++++++++++++-
plat/linuxu/arm/link32.ld | 24 ++++++++++++++
plat/linuxu/x86/link64.ld | 24 ++++++++++++++
plat/xen/arm/link32.ld | 24 ++++++++++++++
plat/xen/x86/link64.ld | 24 ++++++++++++++
6 files changed, 204 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..48f024d
--- /dev/null
+++ b/include/uk/plat/ctors.h
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ *
+ *
+ * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. 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..97d264f 100644
--- a/plat/kvm/x86/link64.ld
+++ b/plat/kvm/x86/link64.ld
@@ -54,9 +54,32 @@ SECTIONS {
*(.eh_frame)
}
- _erodata = .;
+ /* Constructor table */
+ ukplat_ctortab = .;
+ .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);
+ }
+ ukplat_ectortab = .;
. = ALIGN(0x1000);
+ _erodata = .;
+
/* Read-write data (initialized) */
.got :
{
diff --git a/plat/linuxu/arm/link32.ld b/plat/linuxu/arm/link32.ld
index 7dac4f6..99375d1 100644
--- a/plat/linuxu/arm/link32.ld
+++ b/plat/linuxu/arm/link32.ld
@@ -55,6 +55,30 @@ SECTIONS {
*(.rodata)
*(.rodata.*)
}
+
+ /* Constructor table */
+ ukplat_ctortab = .;
+ .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);
+ }
+ ukplat_ectortab = .;
+
. = ALIGN(0x1000);
_erodata = .;
diff --git a/plat/linuxu/x86/link64.ld b/plat/linuxu/x86/link64.ld
index a7d642d..3f78b81 100644
--- a/plat/linuxu/x86/link64.ld
+++ b/plat/linuxu/x86/link64.ld
@@ -56,6 +56,30 @@ SECTIONS {
*(.rodata)
*(.rodata.*)
}
+
+ /* Constructor table */
+ ukplat_ctortab = .;
+ .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);
+ }
+ ukplat_ectortab = .;
+
. = ALIGN(0x1000);
_erodata = .;
diff --git a/plat/xen/arm/link32.ld b/plat/xen/arm/link32.ld
index 77184c0..17ca503 100644
--- a/plat/xen/arm/link32.ld
+++ b/plat/xen/arm/link32.ld
@@ -49,6 +49,30 @@ SECTIONS
_rodata = .;
.rodata : { *(.rodata) *(.rodata.*) }
+
+ /* Constructor table */
+ ukplat_ctortab = .;
+ .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);
+ }
+ ukplat_ectortab = .;
+
. = ALIGN(4096);
_erodata = .;
diff --git a/plat/xen/x86/link64.ld b/plat/xen/x86/link64.ld
index dd092aa..7c41c6d 100644
--- a/plat/xen/x86/link64.ld
+++ b/plat/xen/x86/link64.ld
@@ -44,6 +44,30 @@ SECTIONS
*(.rodata)
*(.rodata.*)
}
+
+ /* Constructor table */
+ ukplat_ctortab = .;
+ .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);
+ }
+ ukplat_ectortab = .;
+
. = ALIGN(4096);
_erodata = .;
--
2.7.4
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |