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

Re: [Minios-devel] [UNIKRAFT PATCH v2 2/5] lib/syscall_shim: Option to disable libc-style wrapper functions



Reviewed-by: Gaulthier Gain <gaulthier.gain@xxxxxxxxx>

> On 3 Apr 2020, at 18:29, Simon Kuenzer <simon.kuenzer@xxxxxxxxx> wrote:
> 
> Introduces the hidden Config.uk option `LIBSYSCALL_SHIM_NOWRAPPER` to
> disable the generation of libc-style syscall wrapper functions. The
> idea is that libC libraries (e.g., musl) that provide own
> wrappers (e.g., based on `uk_syscall()` and `uk_syscall_static()`)
> would set this option through their Config.uk. In such a case, the
> syscall_shim library will then only generate the low-level system call
> implementations.
> 
> Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
> ---
> doc/guides/developers-app.rst         |  9 +++++++
> lib/syscall_shim/Config.uk            |  6 +++++
> lib/syscall_shim/include/uk/syscall.h | 35 +++++++++++++++++++++++++++
> 3 files changed, 50 insertions(+)
> 
> diff --git a/doc/guides/developers-app.rst b/doc/guides/developers-app.rst
> index a7242e60..ce2f0153 100644
> --- a/doc/guides/developers-app.rst
> +++ b/doc/guides/developers-app.rst
> @@ -450,11 +450,20 @@ libc-style wrapper on top:
>         return ret;
>     }
> 
> +    #if UK_LIBC_SYSCALL
>     ssize_t write(int fd, const void *buf, size_t count)
>     {
>         return (ssize_t) uk_syscall_e_write((long) fd,
>                                             (long) buf, (long) count);
>     }
> +    #endif /* UK_LIBC_SYSCALL */
> +
> +Note: Please note that the implementation of custom libc-style wrappers have 
> to
> +be guarded with ``#if UK_LIBC_SYSCALL``. This macro is provided by the
> +``<uk/syscall.h>`` header. Some libC ports (e.g., musl) deactivate this 
> option
> +whenever their provide own wrapper functions. For such cases, the 
> syscall_shim
> +library will only provide the ``uk_syscall_e_<syscall_name>`` and
> +``uk_syscall_r_<syscall_name>`` symbols.
> 
> Note: When `syscall_shim` library is not enabled, the original design idea was
> that the macros provide the libc-style wrapper only. However, all the
> diff --git a/lib/syscall_shim/Config.uk b/lib/syscall_shim/Config.uk
> index 20962590..c3369463 100644
> --- a/lib/syscall_shim/Config.uk
> +++ b/lib/syscall_shim/Config.uk
> @@ -3,6 +3,12 @@ menuconfig LIBSYSCALL_SHIM
>       default n
> 
> if LIBSYSCALL_SHIM
> +     # Hidden configuration option that can be set by libc's in order to
> +     # switch off the generation of libc-style wrapper symbols
> +     config LIBSYSCALL_SHIM_NOWRAPPER
> +     bool
> +     default n
> +
>       config LIBSYSCALL_SHIM_HANDLER
>               bool "Binary system call handler (Linux ABI)"
>               default n
> diff --git a/lib/syscall_shim/include/uk/syscall.h 
> b/lib/syscall_shim/include/uk/syscall.h
> index a219365b..6ee139fa 100644
> --- a/lib/syscall_shim/include/uk/syscall.h
> +++ b/lib/syscall_shim/include/uk/syscall.h
> @@ -42,6 +42,20 @@
> #include <errno.h>
> #include <uk/print.h>
> 
> +/*
> + * Whenever the hidden Config.uk option LIBSYSCALL_SHIM_NOWRAPPER
> + * is set, the creation of libc-style wrappers are disable by the
> + * UK_SYSCALL_DEFINE() and UK_SYSCALL_R_DEFINE() macros. Alternatively,
> + * UK_LIBC_SYSCALLS can be set to 0 through compilation flags.
> + */
> +#ifndef UK_LIBC_SYSCALLS
> +#if CONFIG_LIBSYSCALL_SHIM_NOWRAPPER
> +#define UK_LIBC_SYSCALLS (0)
> +#else
> +#define UK_LIBC_SYSCALLS (1)
> +#endif /* CONFIG_LIBSYSCALL_SHIM_NOWRAPPER */
> +#endif /* UK_LIBC_SYSCALLS */
> +
> #define __uk_scc(X) ((long) (X))
> typedef long uk_syscall_arg_t;
> 
> @@ -135,7 +149,9 @@ typedef long uk_syscall_arg_t;
> /*
>  * UK_SYSCALL_DEFINE()
>  * Based on UK_LLSYSCALL_DEFINE and provides a libc-style wrapper
> + * in case UK_LIBC_SYSCALLS is enabled
>  */
> +#if UK_LIBC_SYSCALLS
> #define __UK_SYSCALL_DEFINE(x, rtype, name, ename, rname, ...)                
> \
>       long ename(UK_ARG_MAPx(x, UK_S_ARG_LONG, __VA_ARGS__));         \
>       rtype name(UK_ARG_MAPx(x, UK_S_ARG_ACTUAL, __VA_ARGS__))        \
> @@ -152,6 +168,15 @@ typedef long uk_syscall_arg_t;
>                          __UK_NAME2SCALLE_FN(name),                   \
>                          __UK_NAME2SCALLR_FN(name),                   \
>                          __VA_ARGS__)
> +#else
> +#define UK_SYSCALL_DEFINE(rtype, name, ...)                          \
> +     _UK_LLSYSCALL_DEFINE(__UK_SYSCALL_DEF_NARGS(__VA_ARGS__),       \
> +                          rtype,                                     \
> +                          name,                                      \
> +                          __UK_NAME2SCALLE_FN(name),                 \
> +                          __UK_NAME2SCALLR_FN(name),                 \
> +                          __VA_ARGS__)
> +#endif /* UK_LIBC_SYSCALLS */
> 
> /* Raw system call implementation that is returning negative codes on errors 
> */
> /* TODO: `void` as return type is currently not supported.
> @@ -194,7 +219,9 @@ typedef long uk_syscall_arg_t;
> /*
>  * UK_SYSCALL_R_DEFINE()
>  * Based on UK_LLSYSCALL_R_DEFINE and provides a libc-style wrapper
> + * in case UK_LIBC_SYSCALLS is enabled
>  */
> +#if UK_LIBC_SYSCALLS
> #define __UK_SYSCALL_R_DEFINE(x, rtype, name, ename, rname, ...)      \
>       long ename(UK_ARG_MAPx(x, UK_S_ARG_LONG, __VA_ARGS__));         \
>       rtype name(UK_ARG_MAPx(x, UK_S_ARG_ACTUAL, __VA_ARGS__))        \
> @@ -211,6 +238,14 @@ typedef long uk_syscall_arg_t;
>                            __UK_NAME2SCALLE_FN(name),                 \
>                            __UK_NAME2SCALLR_FN(name),                 \
>                            __VA_ARGS__)
> +#else
> +#define UK_SYSCALL_R_DEFINE(rtype, name, ...)                                
> \
> +     _UK_LLSYSCALL_R_DEFINE(__UK_SYSCALL_DEF_NARGS(__VA_ARGS__),     \
> +                            name,                                    \
> +                            __UK_NAME2SCALLE_FN(name),               \
> +                            __UK_NAME2SCALLR_FN(name),               \
> +                            __VA_ARGS__)
> +#endif /* UK_LIBC_SYSCALLS */
> 
> 
> #define __UK_SPROTO_ARGS_TYPE long
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@xxxxxxxxxxxxxxxxxxxx
> https://lists.xenproject.org/mailman/listinfo/minios-devel


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