From 7741af977fd2c723272abfce8c166deb125cf6c6 Mon Sep 17 00:00:00 2001 From: Simon Kuenzer Date: Fri, 24 Feb 2023 01:42:55 +0100 Subject: [PATCH] lib/uklibparam: `UK_LIBPARAM_PARAM_ALIAS()`,`UK_LIBPARAM_PARAM_ARR_ALIAS()` This commit provides `UK_LIBPARAM_PARAM_ALIAS()` and `UK_LIBPARAM_PARAM_ARR_ALIAS()` which are variants of `UK_LIBPARAM_PARAM()` and `UK_LIBPARAM_PARAM_ARR()`. These registration macros allow to set a custom parameter name instead of deriving it from the variable name. Signed-off-by: Simon Kuenzer Reviewed-by: Delia Pavel Approved-by: Razvan Deaconescu Tested-by: Unikraft CI GitHub-Closes: #868 --- lib/uklibparam/include/uk/libparam.h | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/uklibparam/include/uk/libparam.h b/lib/uklibparam/include/uk/libparam.h index c635cef61..223548350 100644 --- a/lib/uklibparam/include/uk/libparam.h +++ b/lib/uklibparam/include/uk/libparam.h @@ -263,6 +263,22 @@ int uk_libparam_parse(int argc, char **argv, int flags); #define UK_LIBPARAM_PARAM(var, type, desc) \ _UK_LIBPARAM_PARAM_DEFINE(var, &var, type, 1, desc) +/* + * Register a single parameter with a custom name + * + * @param name + * Name used for library parameter + * @param addr + * Reference to variable/memory address of parameter + * @param type + * Data type: bool, char, uchar, int, uint, charp, __s8, __u8, __s16, + * __u16, __s32, __u32, __s64, __u64, __uptr + * @param desc + * C string with parameter description. Optional, can be __NULL. + */ +#define UK_LIBPARAM_PARAM_ALIAS(name, addr, type, desc) \ + _UK_LIBPARAM_PARAM_DEFINE(name, (addr), type, 1, desc) + /* * Register a parameter array * @@ -280,6 +296,25 @@ int uk_libparam_parse(int argc, char **argv, int flags); #define UK_LIBPARAM_PARAM_ARR(var, type, count, desc) \ _UK_LIBPARAM_PARAM_DEFINE(var, &var, type, (count), desc) +/* + * Register a parameter array with a custom name + * + * @param name + * Name used for library parameter + * @param addr + * Reference to first array element/memory address of parameter + * @param type + * Data type of array elements: bool, char, uchar, int, uint, charp, __s8, + * __u8, __s16, __u16, __s32, __u32, __s64, + * __u64, __uptr + * @param count + * Number of elements in the array that can be filled (<= array size) + * @param desc + * C string with parameter description. Optional, can be __NULL. + */ +#define UK_LIBPARAM_PARAM_ARR_ALIAS(name, addr, type, count, desc) \ + _UK_LIBPARAM_PARAM_DEFINE(name, (addr), type, (count), desc) + /* Deprecated registration macros */ /* WARNING: These interfaces are here for backwards compatibility and will be * removed in the near future. -- 2.39.5