[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 1/3] plat/*: Introduce unikraft internal constructors
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> --- include/uk/ctors.h | 68 ++++++++++++++++++++++++++++++++++++++ plat/common/x86/link64.lds | 9 +++++ plat/kvm/arm/link64.lds.S | 8 +++++ plat/xen/arm/link32.lds | 8 +++++ 4 files changed, 93 insertions(+) create mode 100644 include/uk/ctors.h diff --git a/include/uk/ctors.h b/include/uk/ctors.h new file mode 100644 index 00000000..845391ac --- /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 (earliest) to 7 (latest)) + * 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 fc3316f6..c30f60f1 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 6aa955f5..b1d806d6 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/xen/arm/link32.lds b/plat/xen/arm/link32.lds index 246244ec..af876ec6 100644 --- a/plat/xen/arm/link32.lds +++ b/plat/xen/arm/link32.lds @@ -77,6 +77,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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |