[PATCH v3 0/3] tools/nolibc: add a new syscall helper

Zhangjin Wu falcon at tinylab.org
Wed Jun 7 04:28:58 PDT 2023


Willy, Thomas

This is the revision of the v2 syscall helpers [1], it is based on
20230606-nolibc-rv32+stkp7a of [2]. It doesn't conflict with the v4 of
-ENOSYS patchset [3], so, it is ok to simply merge both of them.

This revision mainly applied Thomas' method, removed the __syscall()
helper and replaced it with __sysret() instead, because __syscall()
looks like _syscall() and syscall(), it may mixlead the developers.

Changes from v2 -> v3:

* tools/nolibc: sys.h: add a syscall return helper

  * The __syscall() is removed.

  * Align the code style of __sysret() with the others, and use
    __inline__ instead of inline (like stdlib.h) to let it work with
    the default -std=c89 in tools/testing/selftests/nolibc/Makefile

* tools/nolibc: unistd.h: apply __sysret() helper

  As v2.

* tools/nolibc: sys.h: apply __sysret() helper

  replaced __syscall() with __sysret() and merged two separated patches of v2 to one.

Did run-user tests for rv32 (with [3]), rv64 and arm64.

BTW, two questions for Thomas,

* This commit 659a49abc9c2 ("tools/nolibc: validate C89 compatibility")
  enables -std=c89, why not gnu11 used by kernel ? ;-)

* Do we need to tune the order of the macros in unistd.h like this:

    #define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__))
    #define _syscall_n(N, ...) _syscall(N, __VA_ARGS__)
    #define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
    #define _sycall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
    #define syscall(...) _syscall_n(_sycall_narg(__VA_ARGS__), ##__VA_ARGS__)

  Before, It works but seems not put in using order:

    #define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__))
    #define _sycall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
    #define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
    #define _syscall_n(N, ...) _syscall(N, __VA_ARGS__)
    #define syscall(...) _syscall_n(_sycall_narg(__VA_ARGS__), ##__VA_ARGS__)

Thanks.

Best regards,
Zhangjin

---
[1]: https://lore.kernel.org/linux-riscv/cover.1686036862.git.falcon@tinylab.org/
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git
[3]: https://lore.kernel.org/linux-riscv/cover.1686128703.git.falcon@tinylab.org/T/#t

Zhangjin Wu (3):
  tools/nolibc: sys.h: add a syscall return helper
  tools/nolibc: unistd.h: apply __sysret() helper
  tools/nolibc: sys.h: apply __sysret() helper

 tools/include/nolibc/sys.h    | 364 +++++-----------------------------
 tools/include/nolibc/unistd.h |  11 +-
 2 files changed, 55 insertions(+), 320 deletions(-)

-- 
2.25.1




More information about the linux-riscv mailing list