aboutsummaryrefslogtreecommitdiff
path: root/tools
AgeCommit message (Collapse)AuthorFilesLines
2023-08-23tools/nolibc: loongarch: shrink _start with _start_cZhangjin Wu1-40/+4
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: mips: shrink _start with _start_cZhangjin Wu1-38/+8
move most of the _start operations to _start_c(), include the stackprotector initialization. Also clean up the instructions in delayed slots. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: x86_64: shrink _start with _start_cZhangjin Wu1-23/+6
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: i386: shrink _start with _start_cZhangjin Wu1-27/+7
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: aarch64: shrink _start with _start_cZhangjin Wu1-23/+4
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: arm: shrink _start with _start_cZhangjin Wu1-39/+5
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: crt.h: initialize stack protectorZhangjin Wu1-0/+4
As suggested by Thomas, It is able to move the stackprotector initialization from the assembly _start to the beginning of the new _start_c(). Let's call __stack_chk_init() in _start_c() as a preparation. Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: stackprotector.h: add empty __stack_chk_init for ↵Zhangjin Wu1-0/+2
!_NOLIBC_STACKPROTECTOR Let's define an empty __stack_chk_init for the !_NOLIBC_STACKPROTECTOR branch. This allows to remove #ifdef around every call of __stack_chk_init(). Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: add new crt.h with _start_cZhangjin Wu2-0/+58
As the environ and _auxv support added for nolibc, the assembly _start function becomes more and more complex and therefore makes the porting of nolibc to new architectures harder and harder. To simplify portability, this C version of _start_c() is added to do most of the assembly start operations in C, which reduces the complexity a lot and will eventually simplify the porting of nolibc to the new architectures. The new _start_c() only requires a stack pointer argument, it will find argc, argv, envp/environ and _auxv for us, and then call main(), finally, it exit() with main's return status. With this new _start_c(), the future new architectures only require to add very few assembly instructions. As suggested by Thomas, users may use a different signature of main (e.g. void main(void)), a _nolibc_main alias is added for main to silence the warning about potential conflicting types. As suggested by Willy, the code is carefully polished for both smaller size and better readability with local variables and the right types. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: remove the old sys_stat supportZhangjin Wu9-248/+13
The statx manpage [1] shows that it has been supported from Linux 4.11 and glibc 2.28, the Linux support can be checked for all of the architectures with this command: $ git grep -r statx v4.11 arch/ include/uapi/asm-generic/unistd.h \ | grep -E "aarch64|arm|mips|s390|x86|:include/uapi" Besides riscv and loongarch, all of the nolibc supported architectures have added sys_statx from Linux v4.11. riscv is mainlined to v4.15, loongarch is mainlined to v5.19, both of them use the generic unistd.h, so, they have added sys_statx from their first mainline versions. The current oldest stable branch is v4.14, only reserving sys_statx still preserves compatibility with all of the supported stable branches, So, let's remove the old arch related and dependent sys_stat support completely. This is friendly to the future new architecture porting. [1]: https://man7.org/linux/man-pages/man2/statx.2.html Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: fix up startup failures for -O0 under gcc < 11.1.0Zhangjin Wu8-8/+8
As gcc doc [1] shows: Most optimizations are completely disabled at -O0 or if an -O level is not set on the command line, even if individual optimization flags are specified. Test result [2] shows, gcc>=11.1.0 deviates from the above description, but before gcc 11.1.0, "-O0" still forcely uses frame pointer in the _start function even if the individual optimize("omit-frame-pointer") flag is specified. The frame pointer related operations will change the stack pointer (e.g. In x86_64, an extra "push %rbp" will be inserted at the beginning of _start) and make it differs from the one we expected, as a result, break the whole startup function. To fix up this issue, as suggested by Thomas, the individual "Os" and "omit-frame-pointer" optimize flags are used together on _start function to disable frame pointer completely even if the -O0 is set on the command line. [1]: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html [2]: https://lore.kernel.org/lkml/[email protected]/ Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: 7f8548589661 ("tools/nolibc: make compiler and assembler agree on the section around _start") Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: arch-*.h: add missing space after ','Zhangjin Wu8-8/+8
Fix up such errors reported by scripts/checkpatch.pl: ERROR: space required after that ',' (ctx:VxV) #148: FILE: tools/include/nolibc/arch-aarch64.h:148: +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void) ^ ERROR: space required after that ',' (ctx:VxV) #148: FILE: tools/include/nolibc/arch-aarch64.h:148: +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void) ^ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: avoid gaps in test numbersThomas Weißschuh1-17/+13
As the test numbers are based on line numbers gaps without testcases are to be avoided. Instead use the already existing test condition logic to implement conditional execution. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: simplify status printingThomas Weißschuh1-73/+81
pad_spc() is only ever used to print the status message of testcases. The line size is always constant, the return value is never used and the format string is never used as such. Remove all the unneeded logic and simplify the API and its users. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: make evaluation of test conditionsThomas Weißschuh1-21/+21
If "cond" is a multi-token statement the behavior of the preprocessor will lead to the negation "!" to be only applied to the first token. Although currently no test uses such multi-token conditions but it can happen at any time. Put braces around "cond" to ensure the negation works as expected. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: completely remove optional environ supportThomas Weißschuh2-13/+6
In commit 52e423f5b93e ("tools/nolibc: export environ as a weak symbol on i386") and friends the asm startup logic was extended to directly populate the "environ" array. This makes it impossible for "environ" to be dropped by the linker. Therefore also drop the other logic to handle non-present "environ". Also add a testcase to validate the initialization of environ. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: report: add newline before test failuresZhangjin Wu1-1/+1
a newline is inserted just before the test failures to avoid mixing the test failures with the raw test log. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: report: extrude the test status lineZhangjin Wu1-2/+2
two newlines are added around the test summary line to extrude the test status. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: report: align passed, skipped and failedZhangjin Wu1-1/+1
align the test values for different runs and different architectures. Since the total number of tests is not bigger than 1000 currently, let's align them with "%3d". Signed-off-by: Zhangjin Wu <[email protected]> [wt: s/%03d/%3d/ as discussed with Zhangjin] Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: report: print total testsZhangjin Wu1-1/+1
Let's count and print the total number of tests, now, the data of passed, skipped and failed have the same format. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: report: print a summarized test statusZhangjin Wu1-1/+2
one of the test status: success, warning and failure is printed to summarize the passed, skipped and failed values. - "success" means no skipped and no failed. - "warning" means has at least one skipped and no failed. - "failure" means all tests are failed. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add chmod_argv0 testZhangjin Wu1-0/+1
argv0 is readable and chmodable, let's use it for chmod test, but a safe umask should be used, the readable and executable modes should be reserved. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: chroot_exe: remove procfs dependencyZhangjin Wu1-1/+1
Since argv0 also works for CONFIG_PROC_FS=n, let's use it instead of '/proc/self/exe'. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: stat_timestamps: remove procfs dependencyZhangjin Wu1-1/+1
'/proc/self/' is a good path which doesn't have stale time info but it is only available for CONFIG_PROC_FS=y. When CONFIG_PROC_FS=n, use argv0 instead of '/proc/self', use '/' for the worst case. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: chdir_root: restore current path after testZhangjin Wu1-1/+1
The PWD environment variable has the path of the nolibc-test program, the current path must be the same as it, otherwise, the test cases will fail with relative path (e.g. ./nolibc-test). Since only chdir_root really changes the current path, let's restore it with the PWD environment variable. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: vfprintf: remove MEMFD_CREATE dependencyZhangjin Wu1-3/+3
The vfprintf test case require to open a temporary file to write, the old memfd_create() method is perfect but has strong dependency on MEMFD_CREATE and also TMPFS or HUGETLBFS (see fs/Kconfig): config MEMFD_CREATE def_bool TMPFS || HUGETLBFS And from v6.2, MFD_NOEXEC_SEAL must be passed for the non-executable memfd, otherwise, The kernel warning will be output to the test result like this: Running test 'vfprintf' 0 emptymemfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1 'init' "" = "" [OK] To avoid such warning and also to remove the MEMFD_CREATE dependency, let's open a file from tmpfs directly. The /tmp directory is used to detect the existing of tmpfs, if not there, skip instead of fail. And further, for pid == 1, the initramfs is loaded as ramfs, which can be used as tmpfs, so, it is able to further remove TMPFS dependency too. Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected] Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: prepare /tmp for tests that need to writeZhangjin Wu1-0/+3
create a /tmp directory. If it succeeds, the directory is writable, which is normally the case when booted from an initramfs anyway. This will be used instead of procfs for some tests. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ [wt: removed the unneeded mount() call] Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: fix up failures when CONFIG_PROC_FS=nZhangjin Wu1-2/+5
For CONFIG_PROC_FS=n, the /proc is not mountable, but the /proc directory has been created in the prepare() stage whenever /proc is there or not. so, the checking of /proc in the run_syscall() stage will be always true and at last it will fail all of the procfs dependent test cases, which deviates from the 'cond' check design of the EXPECT_xx macros, without procfs, these test cases should be skipped instead of failed. To solve this issue, one method is checking /proc/self instead of /proc, another method is removing the /proc directory completely for CONFIG_PROC_FS=n, we apply the second method to avoid misleading the users. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add a new rmdir() test caseZhangjin Wu1-0/+1
A new rmdir_blah test case is added to remove a non-existing /blah, which expects failure with ENOENT errno. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: add rmdir() supportZhangjin Wu1-0/+22
a reverse operation of mkdir() is meaningful, add rmdir() here. required by nolibc-test to remove /proc while CONFIG_PROC_FS is not enabled. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: link_cross: use /proc/self/cmdlineZhangjin Wu1-1/+1
For CONFIG_NET=n, there would be no /proc/self/net, so, use /proc/self/cmdline instead. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: fix up kernel parameters supportZhangjin Wu1-2/+31
kernel parameters allow pass two types of strings, one type is like 'noapic', another type is like 'panic=5', the first type is passed as arguments of the init program, the second type is passed as environment variables of the init program. when users pass kernel parameters like this: noapic NOLIBC_TEST=syscall our nolibc-test program will use the test setting from argv[1] and ignore the one from NOLIBC_TEST environment variable, and at last, it will print the following line and ignore the whole test setting. Ignoring unknown test name 'noapic' reversing the parsing order does solve the above issue: test = getenv("NOLIBC_TEST"); if (test) test = argv[1]; but it still doesn't work with such kernel parameters (without NOLIBC_TEST environment variable): noapic FOO=bar To support all of the potential kernel parameters, let's verify the test setting from both of argv[1] and NOLIBC_TEST environment variable. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: prefer <sys/reboot.h> to <linux/reboot.h>Zhangjin Wu1-2/+1
Since both glibc and musl provide RB_ flags via <sys/reboot.h>, and we just add RB_ flags for nolibc, let's use RB_ flags instead of LINUX_REBOOT_ flags and only reserve the required <sys/reboot.h> header. This allows compile libc-test for musl libc without the linux headers. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: types.h: add RB_ flags for reboot()Zhangjin Wu2-2/+11
Both glibc and musl provide RB_ flags via <sys/reboot.h> for reboot(), they don't need to include <linux/reboot.h>, let nolibc provide RB_ flags too. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: fix up int_fast16/32_t test cases for muslZhangjin Wu1-4/+8
musl limits the fast signed int in 32bit, but glibc and nolibc don't, to let such test cases work on musl, let's provide the type based SINT_MAX_OF_TYPE(type) and SINT_MIN_OF_TYPE(type). Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add _LARGEFILE64_SOURCE for muslZhangjin Wu1-0/+1
_GNU_SOURCE Implies _LARGEFILE64_SOURCE in glibc, but in musl, the default configuration doesn't enable _LARGEFILE64_SOURCE. >From include/dirent.h of musl, getdents64 is provided as getdents when _LARGEFILE64_SOURCE is defined. #if defined(_LARGEFILE64_SOURCE) ... #define getdents64 getdents #endif Let's define _LARGEFILE64_SOURCE to fix up this compile error: tools/testing/selftests/nolibc/nolibc-test.c: In function ‘test_getdents64’: tools/testing/selftests/nolibc/nolibc-test.c:453:8: warning: implicit declaration of function ‘getdents64’; did you mean ‘getdents’? [-Wimplicit-function-declaration] 453 | ret = getdents64(fd, (void *)buffer, sizeof(buffer)); | ^~~~~~~~~~ | getdents /usr/bin/ld: /tmp/ccKILm5u.o: in function `test_getdents64': nolibc-test.c:(.text+0xe3e): undefined reference to `getdents64' collect2: error: ld returned 1 exit status Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: gettid: restore for glibc and muslZhangjin Wu1-3/+7
As the gettid manpage [1] shows, glibc 2.30 has gettid support, so, let's enable the test for glibc >= 2.30. gettid works on musl too. [1]: https://man7.org/linux/man-pages/man2/gettid.2.html Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: stat_fault: silence NULL argument warning with glibcZhangjin Wu1-1/+1
Use another invalid address (void *)1 instead of NULL to silence this compile warning with glibc: $ make libc-test CC libc-test nolibc-test.c: In function ‘run_syscall’: nolibc-test.c:622:49: warning: null argument where non-null required (argument 1) [-Wnonnull] 622 | CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; | ^~~~ nolibc-test.c:304:79: note: in definition of macro ‘EXPECT_SYSER2’ 304 | do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) | ^~~~ nolibc-test.c:622:33: note: in expansion of macro ‘EXPECT_SYSER’ 622 | CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add run-libc-test targetZhangjin Wu1-0/+4
allow run and report glibc or musl based libc-test. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add mmap_munmap_good test caseZhangjin Wu1-0/+60
mmap() a file with a good offset and then munmap() it. a non-zero offset is passed to test the 6th argument of my_syscall6(). Note, it is not easy to find a unique file for mmap() in different scenes, so, a file list is used to search the right one: - /dev/zero: is commonly used to allocate anonymous memory and is likely present and readable - /proc/1/exe: for 'run' and 'run-user' target, 'run-user' can not find '/proc/self/exe' - /proc/self/exe: for 'libc-test' target, normal program 'libc-test' has no permission to access '/proc/1/exe' - argv0: the path of the program itself, let it pass even with worst case scene: no procfs and no /dev/zero Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add munmap_bad test caseZhangjin Wu1-0/+1
The addr argument of munmap() must be a multiple of the page size, passing invalid (void *)1 addr expects failure with -EINVAL. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add mmap_bad test caseZhangjin Wu1-0/+1
The length argument of mmap() must be greater than 0, passing a zero length argument expects failure with -EINVAL. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add sbrk_0 to test current brk gettingZhangjin Wu1-0/+1
>From musl 0.9.14 (to the latest version 1.2.3), both sbrk() and brk() have almost been disabled for they conflict with malloc, only sbrk(0) is still permitted as a way to get the current location of the program break, let's support such case. EXPECT_PTRNE() is used to expect sbrk() always successfully getting the current break. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: add EXPECT_PTREQ, EXPECT_PTRNE and EXPECT_PTRERZhangjin Wu1-0/+58
The syscalls like sbrk() and mmap() return pointers, to test them, more pointer compare test macros are required, add them: - EXPECT_PTREQ() expects two equal pointers. - EXPECT_PTRNE() expects two non-equal pointers. - EXPECT_PTRER() expects failure with a specified errno. - EXPECT_PTRER2() expects failure with one of two specified errnos. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: prepare: create /dev/zeroZhangjin Wu1-1/+3
/dev/zero is commonly used to allocate anonymous memory, it is a very good file for tests, let's prepare it. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23selftests/nolibc: export argv0 for some testsZhangjin Wu1-0/+4
argv0 is the path to nolibc-test program itself, which is a very good always existing readable file for some tests, let's export it. Note, the path may be absolute or relative, please make sure the tests work with both of them. If it is relative, we must make sure the current path is the one specified by the PWD environment variable. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: clean up sbrk() routineZhangjin Wu1-5/+4
Fix up the error reported by scripts/checkpatch.pl: ERROR: do not use assignment in if condition #95: FILE: tools/include/nolibc/sys.h:95: + if ((ret = sys_brk(0)) && (sys_brk(ret + inc) == ret + inc)) Apply the new generic __sysret() to merge the SET_ERRNO() and return lines. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: clean up mmap() routineZhangjin Wu2-23/+12
Do several cleanups together: - Since all supported architectures have my_syscall6() now, remove the #ifdef check. - Move the mmap() related macros to tools/include/nolibc/types.h and reuse most of them from <linux/mman.h> - Apply the new generic __sysret() to convert the calling of sys_map() to oneline code Note, since MAP_FAILED is -1 on Linux, so we can use the generic __sysret() which returns -1 upon error and still satisfy user land that checks for MAP_FAILED. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: __sysret: support syscalls who return a pointerZhangjin Wu1-5/+12
No official reference states the errno range, here aligns with musl and glibc and uses [-MAX_ERRNO, -1] instead of all negative ones. - musl: src/internal/syscall_ret.c - glibc: sysdeps/unix/sysv/linux/sysdep.h The MAX_ERRNO used by musl and glibc is 4095, just like the one nolibc defined in tools/include/nolibc/errno.h. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/ZKKdD%[email protected]/ Suggested-by: David Laight <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: add missing my_syscall6() for mipsZhangjin Wu2-6/+30
It is able to pass the 6th argument like the 5th argument via the stack for mips, let's add a new my_syscall6() now, see [1] for details: The mips/o32 system call convention passes arguments 5 through 8 on the user stack. Both mmap() and pselect6() require my_syscall6(). [1]: https://man7.org/linux/man-pages/man2/syscall.2.html Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>