[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v2 2/9] include: Clean-ups to <uk/ctors.h>
This commit brings the Unikraft constructor definitions closer to the one of the Unikraft Init table. UK_CTOR_FUNC() is basically replaced by UK_CTOR_PRIO(). Naming and argument order is derived from Init table definition <uk/init.h>. The table iterator is now similar as the one found in the Init table. Instead of providing an integer as index, the foreach-macro is directly iterating with a function pointer. Because of compatibility reasons, the previous macro UK_CTOR_FUNC() is still provided. The idea is that it gets removed as soon all depending code was updated (internal and external). Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> --- include/uk/ctors.h | 60 ++++++++++++------- lib/ukboot/boot.c | 44 +++++++------- lib/uklibparam/include/uk/libparam.h | 2 +- .../include/uk/plat/common/common.lds.h | 2 +- 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/include/uk/ctors.h b/include/uk/ctors.h index e7d0dece..35e4cf49 100644 --- a/include/uk/ctors.h +++ b/include/uk/ctors.h @@ -53,41 +53,55 @@ extern const uk_ctor_func_t __preinit_array_start[]; extern const uk_ctor_func_t __preinit_array_end; extern const uk_ctor_func_t __init_array_start[]; extern const uk_ctor_func_t __init_array_end; -extern const uk_ctor_func_t uk_ctortab[]; +extern const uk_ctor_func_t uk_ctortab_start[]; extern const uk_ctor_func_t uk_ctortab_end; /** * Register a Unikraft constructor function that is * called during bootstrap (uk_ctortab) * - * @param lvl - * Priority level (0 (higher) to 9 (least)) - * Note: Any other value for level will be ignored - * @param ctorf + * @param fn * Constructor function to be called + * @param prio + * Priority level (0 (earliest) to 9 (latest)) + * Note: Any other value for level will be ignored + */ +#define __UK_CTORTAB(fn, prio) \ + static const uk_ctor_func_t \ + __used __section(".uk_ctortab" #prio) \ + __uk_ctortab ## prio ## _ ## fn = (fn) + +#define _UK_CTORTAB(fn, prio) \ + __UK_CTORTAB(fn, prio) + +#define UK_CTOR_PRIO(fn, prio) \ + _UK_CTORTAB(fn, prio) + +/** + * Similar interface without priority. */ -#define __UK_CTOR_FUNC(lvl, ctorf) \ - static const uk_ctor_func_t \ - __used __section(".uk_ctortab" #lvl) \ - __uk_ctab ## lvl ## _ ## ctorf = (ctorf) -#define UK_CTOR_FUNC(lvl, ctorf) __UK_CTOR_FUNC(lvl, ctorf) +#define UK_CTOR(fn) UK_CTOR_PRIO(fn, 9) + +/* DELETEME: Compatibility wrapper for existing code, to be removed! */ +#define UK_CTOR_FUNC(lvl, ctorf) \ + _UK_CTORTAB(ctorf, lvl) /** - * Helper macro for iterating over constructor pointer arrays - * Please note that the array may contain NULL pointer entries + * Helper macro for iterating over constructor pointer tables + * Please note that the table may contain NULL pointer entries * - * @param arr_start - * Start address of pointer array (type: const uk_ctor_func_t const []) - * @param arr_end - * End address of pointer array - * @param i - * Iterator variable (integer) which should be used to access the - * individual fields + * @param itr + * Iterator variable (uk_ctor_func_t *) which points to the individual + * table entries during iteration + * @param ctortab_start + * Start address of table (type: const uk_ctor_func_t[]) + * @param ctortab_end + * End address of table (type: const uk_ctor_func_t) */ -#define uk_ctor_foreach(arr_start, arr_end, i) \ - for ((i) = 0; \ - &((arr_start)[i]) < &(arr_end); \ - ++(i)) +#define uk_ctortab_foreach(itr, ctortab_start, ctortab_end) \ + for ((itr) = DECONST(uk_ctor_func_t*, ctortab_start); \ + (itr) < &(ctortab_end); \ + (itr)++) #ifdef __cplusplus } diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c index 9bd15ca8..fc2cf52a 100644 --- a/lib/ukboot/boot.c +++ b/lib/ukboot/boot.c @@ -77,6 +77,7 @@ static void main_thread_func(void *arg) int ret; struct thread_main_arg *tma = arg; uk_init_t *itr; + uk_ctor_func_t *ctorfn; /** * Run init table @@ -112,25 +113,24 @@ static void main_thread_func(void *arg) * from its OS being initialized. */ uk_pr_info("Pre-init table at %p - %p\n", - __preinit_array_start, &__preinit_array_end); - uk_ctor_foreach(__preinit_array_start, __preinit_array_end, i) { - if (__preinit_array_start[i]) { - uk_pr_debug("Call pre-init constructor (entry %d (%p): %p())...\n", - i, &__preinit_array_start[i], - __preinit_array_start[i]); - __preinit_array_start[i](); - } + &__preinit_array_start[0], &__preinit_array_end); + uk_ctortab_foreach(ctorfn, + __preinit_array_start, __preinit_array_end) { + if (!*ctorfn) + continue; + + uk_pr_debug("Call pre-init constructor: %p()...\n", *ctorfn); + (*ctorfn)(); } uk_pr_info("Constructor table at %p - %p\n", - __init_array_start, &__init_array_end); - uk_ctor_foreach(__init_array_start, __init_array_end, i) { - if (__init_array_start[i]) { - uk_pr_debug("Call constructor (entry %d (%p): %p())...\n", - i, &__init_array_start[i], - __init_array_start[i]); - __init_array_start[i](); - } + &__init_array_start[0], &__init_array_end); + uk_ctortab_foreach(ctorfn, __init_array_start, __init_array_end) { + if (!*ctorfn) + continue; + + uk_pr_debug("Call constructor: %p()...\n", *ctorfn); + (*ctorfn)(); } uk_pr_info("Calling main(%d, [", tma->argc); @@ -171,7 +171,6 @@ void ukplat_entry_argp(char *arg0, char *argb, __sz argb_len) void ukplat_entry(int argc, char *argv[]) { struct thread_main_arg tma; - int i; int kern_args = 0; int rc __maybe_unused = 0; #if CONFIG_LIBUKALLOC @@ -184,11 +183,14 @@ void ukplat_entry(int argc, char *argv[]) struct uk_sched *s = NULL; struct uk_thread *main_thread = NULL; #endif + uk_ctor_func_t *ctorfn; - uk_pr_info("Unikraft constructors table at %p\n", uk_ctortab); - uk_ctor_foreach(uk_ctortab, uk_ctortab_end, i) { - uk_pr_debug("Call constructor %p\n", uk_ctortab[i]); - uk_ctortab[i](); + uk_pr_info("Unikraft constructor table at %p - %p\n", + &uk_ctortab_start[0], &uk_ctortab_end); + uk_ctortab_foreach(ctorfn, uk_ctortab_start, uk_ctortab_end) { + UK_ASSERT(*ctorfn); + uk_pr_debug("Call constructor: %p())...\n", *ctorfn); + (*ctorfn)(); } #ifdef CONFIG_LIBUKLIBPARAM diff --git a/lib/uklibparam/include/uk/libparam.h b/lib/uklibparam/include/uk/libparam.h index 2a271ed3..f8f8ba4b 100644 --- a/lib/uklibparam/include/uk/libparam.h +++ b/lib/uklibparam/include/uk/libparam.h @@ -300,7 +300,7 @@ void _uk_libparam_lib_add(struct uk_lib_section *lib_sec); #define UK_LIB_CTOR_PRIO 1 #define UK_LIB_CONSTRUCTOR_SETUP(prio, name) \ - __UK_CTOR_FUNC(prio, name) + UK_CTOR_PRIO(name, prio) /** * Create a constructor to initialize the parameters in the library. diff --git a/plat/common/include/uk/plat/common/common.lds.h b/plat/common/include/uk/plat/common/common.lds.h index 593e6699..d31aa1dd 100644 --- a/plat/common/include/uk/plat/common/common.lds.h +++ b/plat/common/include/uk/plat/common/common.lds.h @@ -87,7 +87,7 @@ #define CTORTAB_SECTION \ . = ALIGN(__PAGE_SIZE); \ - uk_ctortab = .; \ + uk_ctortab_start = .; \ .uk_ctortab : \ { \ KEEP(*(SORT_BY_NAME(.uk_ctortab[0-9]))) \ -- 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 |