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

[Minios-devel] [UNIKRAFT PATCH v4 1/3] plat/*: Introduce unikraft internal constructors



From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>

This patch adds a new section for the ukplat_ctortab
array. The 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). This patch was needed because
C++ normally uses __attribute__((constructor)) and without
this we would run the C++ constructors during the startup with the
internal unikraft constructors.

This is based on the previous patch of Simon Kuenzer.

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
 include/uk/ctors.h         | 68 ++++++++++++++++++++++++++++++++++++++
 plat/common/x86/link64.lds |  9 +++++
 plat/kvm/arm/link64.lds.S  |  8 +++++
 plat/linuxu/Linker.uk      |  2 ++
 plat/linuxu/arm/link.lds   | 11 ++++++
 plat/linuxu/x86/link64.lds |  6 ++++
 plat/xen/arm/link32.lds    |  8 +++++
 7 files changed, 112 insertions(+)
 create mode 100644 include/uk/ctors.h
 create mode 100644 plat/linuxu/arm/link.lds
 create mode 100644 plat/linuxu/x86/link64.lds

diff --git a/include/uk/ctors.h b/include/uk/ctors.h
new file mode 100644
index 00000000..15ec90fe
--- /dev/null
+++ b/include/uk/ctors.h
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ *                     Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+ *
+ *
+ * Copyright (c) 2019, 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 __UK_CTORS_H__
+#define __UK_CTORS_H__
+
+#include <uk/essentials.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*uk_ctor_func_t)(void);
+extern const uk_ctor_func_t uk_ctortab[];
+
+/*
+ * Register a constructor function that is
+ * called during bootstrap
+ * @param lvl
+ *   Priority level (0 (higher) to 7 (least))
+ *   Note: Any other value for level will be ignored
+ * @param ctorf
+ *   Constructor function to be called
+ */
+#define UK_CTOR_FUNC(lvl, ctorf) \
+               static const uk_ctor_func_t     \
+               __used __section(".uk_ctortab" #lvl)    \
+               __uk_ctab ## lvl ## _ ## ctorf = (ctorf)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UK__CTORS_H__ */
diff --git a/plat/common/x86/link64.lds b/plat/common/x86/link64.lds
index 018cdac3..a7ba67bb 100644
--- a/plat/common/x86/link64.lds
+++ b/plat/common/x86/link64.lds
@@ -48,3 +48,12 @@ __eh_frame_hdr_start = .;
        *(.eh_frame_hdr.*)
 }
 __eh_frame_hdr_end = .;
+
+. = ALIGN(0x1000);
+uk_ctortab = .;
+.uk_ctortab :
+{
+    *(SORT_BY_NAME(.uk_ctortab[0-7]))
+    LONG(0)
+}
+
diff --git a/plat/kvm/arm/link64.lds.S b/plat/kvm/arm/link64.lds.S
index 82328633..f0da7768 100644
--- a/plat/kvm/arm/link64.lds.S
+++ b/plat/kvm/arm/link64.lds.S
@@ -99,6 +99,14 @@ SECTIONS {
 
        _erodata = .;
 
+       . = ALIGN(__PAGE_SIZE);
+       uk_ctortab = .;
+       .uk_ctortab :
+       {
+               *(SORT_BY_NAME(.uk_ctortab[0-7]))
+               LONG(0)
+       }
+
        /* Constructor tables (read-only) */
        _ctors = .;
        .preinit_array : {
diff --git a/plat/linuxu/Linker.uk b/plat/linuxu/Linker.uk
index ef4b201c..20ebfc05 100644
--- a/plat/linuxu/Linker.uk
+++ b/plat/linuxu/Linker.uk
@@ -4,6 +4,8 @@ LINUXU_LDFLAGS-y += -Wl,-e,_liblinuxuplat_start
 ## Link image
 ##
 LINUXU_IMAGE := $(BUILD_DIR)/$(CONFIG_UK_NAME)_linuxu-$(CONFIG_UK_ARCH)
+LINUXU_LD_SCRIPT-$(CONFIG_ARCH_X86_64) += $(LIBLINUXUPLAT_BASE)/x86/link64.lds
+LINUXU_LD_SCRIPT-$(CONFIG_ARCH_ARM_32) += $(LIBLINUXUPLAT_BASE)/arm/link.lds
 LINUXU_LD_SCRIPT_FLAGS := $(addprefix -Wl$(comma)-T$(comma),\
                            $(LINUXU_LD_SCRIPT-y) $(EXTRA_LD_SCRIPT-y))
 
diff --git a/plat/linuxu/arm/link.lds b/plat/linuxu/arm/link.lds
new file mode 100644
index 00000000..1dfda274
--- /dev/null
+++ b/plat/linuxu/arm/link.lds
@@ -0,0 +1,11 @@
+SECTIONS
+{
+   . = ALIGN(0x1000);
+   uk_ctortab = .;
+   .uk_ctortab :
+   {
+       *(SORT_BY_NAME(.uk_ctortab[0-7]))
+       LONG(0)
+   }
+}
+INSERT AFTER .rodata
diff --git a/plat/linuxu/x86/link64.lds b/plat/linuxu/x86/link64.lds
new file mode 100644
index 00000000..077aaf66
--- /dev/null
+++ b/plat/linuxu/x86/link64.lds
@@ -0,0 +1,6 @@
+SECTIONS
+{
+   INCLUDE plat/common/x86/link64.lds
+}
+INSERT AFTER .rodata
+
diff --git a/plat/xen/arm/link32.lds b/plat/xen/arm/link32.lds
index 2b8e42dd..522df30c 100644
--- a/plat/xen/arm/link32.lds
+++ b/plat/xen/arm/link32.lds
@@ -78,6 +78,14 @@ SECTIONS
        . = ALIGN(4096);
        _erodata = .;
 
+       uk_ctortab = .;
+       .uk_ctortab :
+       {
+               *(SORT_BY_NAME(.uk_ctortab[0-7]))
+               LONG(0)
+       }
+       . = ALIGN(4096);
+
        _ctors = .;
        .preinit_array : {
                . = ALIGN(0x8);
-- 
2.20.1

_______________________________________________
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®.