[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v2 3/5] lib/syscall_shim: `UK_(LL)SYSCALL_R_DEFINE()`: Use given return type
Instead of declaring the return type for `UK_(LL)SYSCALL_R_DEFINE()` functions as `long`, the user-given return type is used. In general, this is done for convenience. Whenever a system call implementation uses pointers as return type, the helpers defined in `<uk/errptr.h>` can be used to encapsulate error codes. Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> --- doc/guides/developers-app.rst | 15 +++++++-------- lib/syscall_shim/include/uk/syscall.h | 11 ++++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/guides/developers-app.rst b/doc/guides/developers-app.rst index ce2f0153..d413aace 100644 --- a/doc/guides/developers-app.rst +++ b/doc/guides/developers-app.rst @@ -400,19 +400,18 @@ Example: UK_SYSCALL_R_DEFINE(ssize_t, write, int, fd, const void *, buf, size_t, count) { - long ret; + ssize_t ret; - ret = (long) vfs_do_write(fd, buf, count); + ret = vfs_do_write(fd, buf, count); if (ret < 0) { return -EFAULT; } return ret; } -Please note that in the raw case (``UK_SYSCALL_R_DEFINE``), the return type -within your code block is always ``long``. The specified return type as -parameter to the macro will be used for the libc-style wrapper. However, the -input parameters are defined with the actual type for your code block. +Please note that in the raw case (``UK_SYSCALL_R_DEFINE``), errors are always +returned as negative value. Whenever the return type is a pointer value, the +helpers defined in `<uk/errptr.h>` can be used to forward error codes. Both macros create the following three symbols: @@ -441,9 +440,9 @@ libc-style wrapper on top: UK_LLSYSCALL_R_DEFINE(ssize_t, write, int, fd, const void *, buf, size_t, count) { - long ret; + ssize_t ret; - ret = (long) vfs_do_write(fd, buf, count); + ret = vfs_do_write(fd, buf, count); if (ret < 0) { return -EFAULT; } diff --git a/lib/syscall_shim/include/uk/syscall.h b/lib/syscall_shim/include/uk/syscall.h index 6ee139fa..aafe20a7 100644 --- a/lib/syscall_shim/include/uk/syscall.h +++ b/lib/syscall_shim/include/uk/syscall.h @@ -39,6 +39,7 @@ #include <uk/config.h> #include <uk/essentials.h> +#include <uk/errptr.h> #include <errno.h> #include <uk/print.h> @@ -192,20 +193,20 @@ typedef long uk_syscall_arg_t; { \ long ret = rname( \ UK_ARG_MAPx(x, UK_S_ARG_CAST_LONG, __VA_ARGS__)); \ - if (ret < 0) { \ - errno = (int) -ret; \ + if (ret < 0 && PTRISERR(ret)) { \ + errno = (int) PTR2ERR(ret); \ return -1; \ } \ return ret; \ } \ - static inline long __##rname(UK_ARG_MAPx(x, UK_S_ARG_ACTUAL, \ + static inline rtype __##rname(UK_ARG_MAPx(x, UK_S_ARG_ACTUAL, \ __VA_ARGS__)); \ long rname(UK_ARG_MAPx(x, UK_S_ARG_LONG, __VA_ARGS__)) \ { \ - return __##rname( \ + return (long) __##rname( \ UK_ARG_MAPx(x, UK_S_ARG_CAST_ACTUAL, __VA_ARGS__)); \ } \ - static inline long __##rname(UK_ARG_MAPx(x, UK_S_ARG_ACTUAL, \ + static inline rtype __##rname(UK_ARG_MAPx(x, UK_S_ARG_ACTUAL, \ __VA_ARGS__)) #define _UK_LLSYSCALL_R_DEFINE(...) __UK_LLSYSCALL_R_DEFINE(__VA_ARGS__) #define UK_LLSYSCALL_R_DEFINE(rtype, name, ...) \ -- 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 |