Pull nolibc updates from Thomas Weißschuh: - Many new features and optimizations to printf() - Rename non-standard symbols to avoid collisions with application code - Support for byteswap.h, endian.h, err.h and asprintf() - 64-bit dev_t - Smaller cleanups and fixes to the code and build system * tag 'nolibc-20260412-for-7.1-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc: (61 commits) selftests/nolibc: use gcc 15 tools/nolibc: support UBSAN on gcc tools/nolibc: create __nolibc_no_sanitize_ubsan selftests/nolibc: don't skip tests for unimplemented syscalls anymore selftests/nolibc: explicitly handle ENOSYS from ptrace() tools/nolibc: add byteorder conversions tools/nolibc: add the _syscall() macro tools/nolibc: move the call to __sysret() into syscall() tools/nolibc: rename the internal macros used in syscall() selftests/nolibc: only use libgcc when really necessary selftests/nolibc: test the memory allocator tools/nolibc: check for overflow in calloc() without divisions tools/nolibc: add support for asprintf() tools/nolibc: use __builtin_offsetof() tools/nolibc: use makedev() in fstatat() tools/nolibc: handle all major and minor numbers in makedev() and friends tools/nolibc: make dev_t 64 bits wide tools/nolibc: move the logic of makedev() and friends into functions selftests/nolibc: add a test for stat().st_rdev selftests/nolibc: add some tests for makedev() and friends ...
Unified · Split
| @@ -17,19 +17,17 @@ endif · 16 unmodified lines | ||
| 17 | 17 | # it defaults to this nolibc directory. |
| 18 | 18 | OUTPUT ?= $(CURDIR)/ |
| 19 | 19 | |
| 20 | −ifeq ($(V),1) | |
| 21 | −Q= | |
| 22 | −else | |
| 23 | −Q=@ | |
| 24 | −endif | |
| 25 | − | |
| 26 | −arch_files := arch.h $(wildcard arch-*.h) | |
| 20 | +architectures := arm arm64 loongarch m68k mips powerpc riscv s390 sh sparc x86 | |
| 21 | +arch_files := arch.h $(addsuffix .h, $(addprefix arch-, $(architectures))) | |
| 27 | 22 | all_files := \ |
| 23 | + byteswap.h \ | |
| 28 | 24 | compiler.h \ |
| 29 | 25 | crt.h \ |
| 30 | 26 | ctype.h \ |
| 31 | 27 | dirent.h \ |
| 32 | 28 | elf.h \ |
| 29 | + endian.h \ | |
| 30 | + err.h \ | |
| 33 | 31 | errno.h \ |
| 34 | 32 | fcntl.h \ |
| 35 | 33 | getopt.h \ |
| @@ -96,12 +94,10 @@ help: · 60 unmodified lines | ||
| 96 | 94 | |
| 97 | 95 | # installs headers for all archs at once. |
| 98 | 96 | headers: |
| 99 | − $(Q)mkdir -p "$(OUTPUT)sysroot" | |
| 100 | 97 | $(Q)mkdir -p "$(OUTPUT)sysroot/include" |
| 101 | 98 | $(Q)cp --parents $(arch_files) $(all_files) "$(OUTPUT)sysroot/include/" |
| 102 | 99 | |
| 103 | 100 | headers_standalone: headers |
| 104 | − $(Q)$(MAKE) -C $(srctree) headers | |
| 105 | 101 | $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot |
| 106 | 102 | |
| 107 | 103 | CFLAGS_s390 := -m64 |
| @@ -50,7 +50,7 @@ · 49 unmodified lines | ||
| 50 | 50 | |
| 51 | 51 | #endif /* end THUMB */ |
| 52 | 52 | |
| 53 | −#define my_syscall0(num) \ | |
| 53 | +#define __nolibc_syscall0(num) \ | |
| 54 | 54 | ({ \ |
| 55 | 55 | register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ |
| 56 | 56 | register long _arg1 __asm__ ("r0"); \ |
| @@ -67,7 +67,7 @@ · 10 unmodified lines | ||
| 67 | 67 | _arg1; \ |
| 68 | 68 | }) |
| 69 | 69 | |
| 70 | −#define my_syscall1(num, arg1) \ | |
| 70 | +#define __nolibc_syscall1(num, arg1) \ | |
| 71 | 71 | ({ \ |
| 72 | 72 | register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ |
| 73 | 73 | register long _arg1 __asm__ ("r0") = (long)(arg1); \ |
| @@ -84,7 +84,7 @@ · 10 unmodified lines | ||
| 84 | 84 | _arg1; \ |
| 85 | 85 | }) |
| 86 | 86 | |
| 87 | −#define my_syscall2(num, arg1, arg2) \ | |
| 87 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 88 | 88 | ({ \ |
| 89 | 89 | register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ |
| 90 | 90 | register long _arg1 __asm__ ("r0") = (long)(arg1); \ |
| @@ -102,7 +102,7 @@ · 11 unmodified lines | ||
| 102 | 102 | _arg1; \ |
| 103 | 103 | }) |
| 104 | 104 | |
| 105 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 105 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 106 | 106 | ({ \ |
| 107 | 107 | register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ |
| 108 | 108 | register long _arg1 __asm__ ("r0") = (long)(arg1); \ |
| @@ -121,7 +121,7 @@ · 12 unmodified lines | ||
| 121 | 121 | _arg1; \ |
| 122 | 122 | }) |
| 123 | 123 | |
| 124 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 124 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 125 | 125 | ({ \ |
| 126 | 126 | register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ |
| 127 | 127 | register long _arg1 __asm__ ("r0") = (long)(arg1); \ |
| @@ -141,7 +141,7 @@ · 13 unmodified lines | ||
| 141 | 141 | _arg1; \ |
| 142 | 142 | }) |
| 143 | 143 | |
| 144 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 144 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 145 | 145 | ({ \ |
| 146 | 146 | register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ |
| 147 | 147 | register long _arg1 __asm__ ("r0") = (long)(arg1); \ |
| @@ -162,7 +162,7 @@ · 14 unmodified lines | ||
| 162 | 162 | _arg1; \ |
| 163 | 163 | }) |
| 164 | 164 | |
| 165 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 165 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 166 | 166 | ({ \ |
| 167 | 167 | register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \ |
| 168 | 168 | register long _arg1 __asm__ ("r0") = (long)(arg1); \ |
| @@ -22,7 +22,7 @@ · 21 unmodified lines | ||
| 22 | 22 | * don't have to experience issues with register constraints. |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | −#define my_syscall0(num) \ | |
| 25 | +#define __nolibc_syscall0(num) \ | |
| 26 | 26 | ({ \ |
| 27 | 27 | register long _num __asm__ ("x8") = (num); \ |
| 28 | 28 | register long _arg1 __asm__ ("x0"); \ |
| @@ -36,7 +36,7 @@ · 7 unmodified lines | ||
| 36 | 36 | _arg1; \ |
| 37 | 37 | }) |
| 38 | 38 | |
| 39 | −#define my_syscall1(num, arg1) \ | |
| 39 | +#define __nolibc_syscall1(num, arg1) \ | |
| 40 | 40 | ({ \ |
| 41 | 41 | register long _num __asm__ ("x8") = (num); \ |
| 42 | 42 | register long _arg1 __asm__ ("x0") = (long)(arg1); \ |
| @@ -51,7 +51,7 @@ · 8 unmodified lines | ||
| 51 | 51 | _arg1; \ |
| 52 | 52 | }) |
| 53 | 53 | |
| 54 | −#define my_syscall2(num, arg1, arg2) \ | |
| 54 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 55 | 55 | ({ \ |
| 56 | 56 | register long _num __asm__ ("x8") = (num); \ |
| 57 | 57 | register long _arg1 __asm__ ("x0") = (long)(arg1); \ |
| @@ -67,7 +67,7 @@ · 9 unmodified lines | ||
| 67 | 67 | _arg1; \ |
| 68 | 68 | }) |
| 69 | 69 | |
| 70 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 70 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 71 | 71 | ({ \ |
| 72 | 72 | register long _num __asm__ ("x8") = (num); \ |
| 73 | 73 | register long _arg1 __asm__ ("x0") = (long)(arg1); \ |
| @@ -84,7 +84,7 @@ · 10 unmodified lines | ||
| 84 | 84 | _arg1; \ |
| 85 | 85 | }) |
| 86 | 86 | |
| 87 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 87 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 88 | 88 | ({ \ |
| 89 | 89 | register long _num __asm__ ("x8") = (num); \ |
| 90 | 90 | register long _arg1 __asm__ ("x0") = (long)(arg1); \ |
| @@ -102,7 +102,7 @@ · 11 unmodified lines | ||
| 102 | 102 | _arg1; \ |
| 103 | 103 | }) |
| 104 | 104 | |
| 105 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 105 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 106 | 106 | ({ \ |
| 107 | 107 | register long _num __asm__ ("x8") = (num); \ |
| 108 | 108 | register long _arg1 __asm__ ("x0") = (long)(arg1); \ |
| @@ -121,7 +121,7 @@ · 12 unmodified lines | ||
| 121 | 121 | _arg1; \ |
| 122 | 122 | }) |
| 123 | 123 | |
| 124 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 124 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 125 | 125 | ({ \ |
| 126 | 126 | register long _num __asm__ ("x8") = (num); \ |
| 127 | 127 | register long _arg1 __asm__ ("x0") = (long)(arg1); \ |
| @@ -24,7 +24,7 @@ · 23 unmodified lines | ||
| 24 | 24 | #define _NOLIBC_SYSCALL_CLOBBERLIST \ |
| 25 | 25 | "memory", "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8" |
| 26 | 26 | |
| 27 | −#define my_syscall0(num) \ | |
| 27 | +#define __nolibc_syscall0(num) \ | |
| 28 | 28 | ({ \ |
| 29 | 29 | register long _num __asm__ ("a7") = (num); \ |
| 30 | 30 | register long _arg1 __asm__ ("a0"); \ |
| @@ -38,7 +38,7 @@ · 7 unmodified lines | ||
| 38 | 38 | _arg1; \ |
| 39 | 39 | }) |
| 40 | 40 | |
| 41 | −#define my_syscall1(num, arg1) \ | |
| 41 | +#define __nolibc_syscall1(num, arg1) \ | |
| 42 | 42 | ({ \ |
| 43 | 43 | register long _num __asm__ ("a7") = (num); \ |
| 44 | 44 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -52,7 +52,7 @@ · 7 unmodified lines | ||
| 52 | 52 | _arg1; \ |
| 53 | 53 | }) |
| 54 | 54 | |
| 55 | −#define my_syscall2(num, arg1, arg2) \ | |
| 55 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 56 | 56 | ({ \ |
| 57 | 57 | register long _num __asm__ ("a7") = (num); \ |
| 58 | 58 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -68,7 +68,7 @@ · 9 unmodified lines | ||
| 68 | 68 | _arg1; \ |
| 69 | 69 | }) |
| 70 | 70 | |
| 71 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 71 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 72 | 72 | ({ \ |
| 73 | 73 | register long _num __asm__ ("a7") = (num); \ |
| 74 | 74 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -85,7 +85,7 @@ · 10 unmodified lines | ||
| 85 | 85 | _arg1; \ |
| 86 | 86 | }) |
| 87 | 87 | |
| 88 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 88 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 89 | 89 | ({ \ |
| 90 | 90 | register long _num __asm__ ("a7") = (num); \ |
| 91 | 91 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -103,7 +103,7 @@ · 11 unmodified lines | ||
| 103 | 103 | _arg1; \ |
| 104 | 104 | }) |
| 105 | 105 | |
| 106 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 106 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 107 | 107 | ({ \ |
| 108 | 108 | register long _num __asm__ ("a7") = (num); \ |
| 109 | 109 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -122,7 +122,7 @@ · 12 unmodified lines | ||
| 122 | 122 | _arg1; \ |
| 123 | 123 | }) |
| 124 | 124 | |
| 125 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 125 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 126 | 126 | ({ \ |
| 127 | 127 | register long _num __asm__ ("a7") = (num); \ |
| 128 | 128 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -15,7 +15,7 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | #define _NOLIBC_SYSCALL_CLOBBERLIST "memory" |
| 17 | 17 | |
| 18 | −#define my_syscall0(num) \ | |
| 18 | +#define __nolibc_syscall0(num) \ | |
| 19 | 19 | ({ \ |
| 20 | 20 | register long _num __asm__ ("d0") = (num); \ |
| 21 | 21 | \ |
| @@ -28,7 +28,7 @@ · 6 unmodified lines | ||
| 28 | 28 | _num; \ |
| 29 | 29 | }) |
| 30 | 30 | |
| 31 | −#define my_syscall1(num, arg1) \ | |
| 31 | +#define __nolibc_syscall1(num, arg1) \ | |
| 32 | 32 | ({ \ |
| 33 | 33 | register long _num __asm__ ("d0") = (num); \ |
| 34 | 34 | register long _arg1 __asm__ ("d1") = (long)(arg1); \ |
| @@ -42,7 +42,7 @@ · 7 unmodified lines | ||
| 42 | 42 | _num; \ |
| 43 | 43 | }) |
| 44 | 44 | |
| 45 | −#define my_syscall2(num, arg1, arg2) \ | |
| 45 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 46 | 46 | ({ \ |
| 47 | 47 | register long _num __asm__ ("d0") = (num); \ |
| 48 | 48 | register long _arg1 __asm__ ("d1") = (long)(arg1); \ |
| @@ -57,7 +57,7 @@ · 8 unmodified lines | ||
| 57 | 57 | _num; \ |
| 58 | 58 | }) |
| 59 | 59 | |
| 60 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 60 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 61 | 61 | ({ \ |
| 62 | 62 | register long _num __asm__ ("d0") = (num); \ |
| 63 | 63 | register long _arg1 __asm__ ("d1") = (long)(arg1); \ |
| @@ -73,7 +73,7 @@ · 9 unmodified lines | ||
| 73 | 73 | _num; \ |
| 74 | 74 | }) |
| 75 | 75 | |
| 76 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 76 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 77 | 77 | ({ \ |
| 78 | 78 | register long _num __asm__ ("d0") = (num); \ |
| 79 | 79 | register long _arg1 __asm__ ("d1") = (long)(arg1); \ |
| @@ -90,7 +90,7 @@ · 10 unmodified lines | ||
| 90 | 90 | _num; \ |
| 91 | 91 | }) |
| 92 | 92 | |
| 93 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 93 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 94 | 94 | ({ \ |
| 95 | 95 | register long _num __asm__ ("d0") = (num); \ |
| 96 | 96 | register long _arg1 __asm__ ("d1") = (long)(arg1); \ |
| @@ -108,7 +108,7 @@ · 11 unmodified lines | ||
| 108 | 108 | _num; \ |
| 109 | 109 | }) |
| 110 | 110 | |
| 111 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 111 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 112 | 112 | ({ \ |
| 113 | 113 | register long _num __asm__ ("d0") = (num); \ |
| 114 | 114 | register long _arg1 __asm__ ("d1") = (long)(arg1); \ |
| @@ -39,11 +39,19 @@ · 38 unmodified lines | ||
| 39 | 39 | * - stack is 16-byte aligned |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | +#if !defined(__mips_isa_rev) || __mips_isa_rev < 6 | |
| 43 | +#define _NOLIBC_SYSCALL_CLOBBER_HI_LO "hi", "lo" | |
| 44 | +#else | |
| 45 | +#define _NOLIBC_SYSCALL_CLOBBER_HI_LO "$0" | |
| 46 | +#endif | |
| 47 | + | |
| 42 | 48 | #if defined(_ABIO32) |
| 43 | 49 | |
| 44 | 50 | #define _NOLIBC_SYSCALL_CLOBBERLIST \ |
| 45 | − "memory", "cc", "at", "v1", "hi", "lo", \ | |
| 46 | − "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" | |
| 51 | + "memory", "cc", "at", "v1", \ | |
| 52 | + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", \ | |
| 53 | + _NOLIBC_SYSCALL_CLOBBER_HI_LO | |
| 54 | + | |
| 47 | 55 | #define _NOLIBC_SYSCALL_STACK_RESERVE "addiu $sp, $sp, -32\n" |
| 48 | 56 | #define _NOLIBC_SYSCALL_STACK_UNRESERVE "addiu $sp, $sp, 32\n" |
| 49 | 57 | |
| @@ -52,14 +60,15 @@ · 2 unmodified lines | ||
| 52 | 60 | /* binutils, GCC and clang disagree about register aliases, use numbers instead. */ |
| 53 | 61 | #define _NOLIBC_SYSCALL_CLOBBERLIST \ |
| 54 | 62 | "memory", "cc", "at", "v1", \ |
| 55 | − "10", "11", "12", "13", "14", "15", "24", "25" | |
| 63 | + "10", "11", "12", "13", "14", "15", "24", "25", \ | |
| 64 | + _NOLIBC_SYSCALL_CLOBBER_HI_LO | |
| 56 | 65 | |
| 57 | 66 | #define _NOLIBC_SYSCALL_STACK_RESERVE |
| 58 | 67 | #define _NOLIBC_SYSCALL_STACK_UNRESERVE |
| 59 | 68 | |
| 60 | 69 | #endif /* _ABIO32 */ |
| 61 | 70 | |
| 62 | −#define my_syscall0(num) \ | |
| 71 | +#define __nolibc_syscall0(num) \ | |
| 63 | 72 | ({ \ |
| 64 | 73 | register long _num __asm__ ("v0") = (num); \ |
| 65 | 74 | register long _arg4 __asm__ ("a3"); \ |
| @@ -75,7 +84,7 @@ · 9 unmodified lines | ||
| 75 | 84 | _arg4 ? -_num : _num; \ |
| 76 | 85 | }) |
| 77 | 86 | |
| 78 | −#define my_syscall1(num, arg1) \ | |
| 87 | +#define __nolibc_syscall1(num, arg1) \ | |
| 79 | 88 | ({ \ |
| 80 | 89 | register long _num __asm__ ("v0") = (num); \ |
| 81 | 90 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -93,7 +102,7 @@ · 11 unmodified lines | ||
| 93 | 102 | _arg4 ? -_num : _num; \ |
| 94 | 103 | }) |
| 95 | 104 | |
| 96 | −#define my_syscall2(num, arg1, arg2) \ | |
| 105 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 97 | 106 | ({ \ |
| 98 | 107 | register long _num __asm__ ("v0") = (num); \ |
| 99 | 108 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -112,7 +121,7 @@ · 12 unmodified lines | ||
| 112 | 121 | _arg4 ? -_num : _num; \ |
| 113 | 122 | }) |
| 114 | 123 | |
| 115 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 124 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 116 | 125 | ({ \ |
| 117 | 126 | register long _num __asm__ ("v0") = (num); \ |
| 118 | 127 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -132,7 +141,7 @@ · 13 unmodified lines | ||
| 132 | 141 | _arg4 ? -_num : _num; \ |
| 133 | 142 | }) |
| 134 | 143 | |
| 135 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 144 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 136 | 145 | ({ \ |
| 137 | 146 | register long _num __asm__ ("v0") = (num); \ |
| 138 | 147 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -154,7 +163,7 @@ · 15 unmodified lines | ||
| 154 | 163 | |
| 155 | 164 | #if defined(_ABIO32) |
| 156 | 165 | |
| 157 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 166 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 158 | 167 | ({ \ |
| 159 | 168 | register long _num __asm__ ("v0") = (num); \ |
| 160 | 169 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -176,7 +185,7 @@ · 15 unmodified lines | ||
| 176 | 185 | _arg4 ? -_num : _num; \ |
| 177 | 186 | }) |
| 178 | 187 | |
| 179 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 188 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 180 | 189 | ({ \ |
| 181 | 190 | register long _num __asm__ ("v0") = (num); \ |
| 182 | 191 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -203,7 +212,7 @@ · 20 unmodified lines | ||
| 203 | 212 | |
| 204 | 213 | #else /* _ABIN32 || _ABI64 */ |
| 205 | 214 | |
| 206 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 215 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 207 | 216 | ({ \ |
| 208 | 217 | register long _num __asm__ ("v0") = (num); \ |
| 209 | 218 | register long _arg1 __asm__ ("$4") = (long)(arg1); \ |
| @@ -222,7 +231,7 @@ · 12 unmodified lines | ||
| 222 | 231 | _arg4 ? -_num : _num; \ |
| 223 | 232 | }) |
| 224 | 233 | |
| 225 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 234 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 226 | 235 | ({ \ |
| 227 | 236 | register long _num __asm__ ("v0") = (num); \ |
| 228 | 237 | register long _arg1 __asm__ ("$4") = (long)(arg1); \ |
| @@ -25,7 +25,7 @@ · 24 unmodified lines | ||
| 25 | 25 | #define _NOLIBC_SYSCALL_CLOBBERLIST \ |
| 26 | 26 | "memory", "cr0", "r12", "r11", "r10", "r9" |
| 27 | 27 | |
| 28 | −#define my_syscall0(num) \ | |
| 28 | +#define __nolibc_syscall0(num) \ | |
| 29 | 29 | ({ \ |
| 30 | 30 | register long _ret __asm__ ("r3"); \ |
| 31 | 31 | register long _num __asm__ ("r0") = (num); \ |
| @@ -42,7 +42,7 @@ · 10 unmodified lines | ||
| 42 | 42 | _ret; \ |
| 43 | 43 | }) |
| 44 | 44 | |
| 45 | −#define my_syscall1(num, arg1) \ | |
| 45 | +#define __nolibc_syscall1(num, arg1) \ | |
| 46 | 46 | ({ \ |
| 47 | 47 | register long _ret __asm__ ("r3"); \ |
| 48 | 48 | register long _num __asm__ ("r0") = (num); \ |
| @@ -61,7 +61,7 @@ · 12 unmodified lines | ||
| 61 | 61 | }) |
| 62 | 62 | |
| 63 | 63 | |
| 64 | −#define my_syscall2(num, arg1, arg2) \ | |
| 64 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 65 | 65 | ({ \ |
| 66 | 66 | register long _ret __asm__ ("r3"); \ |
| 67 | 67 | register long _num __asm__ ("r0") = (num); \ |
| @@ -81,7 +81,7 @@ · 13 unmodified lines | ||
| 81 | 81 | }) |
| 82 | 82 | |
| 83 | 83 | |
| 84 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 84 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 85 | 85 | ({ \ |
| 86 | 86 | register long _ret __asm__ ("r3"); \ |
| 87 | 87 | register long _num __asm__ ("r0") = (num); \ |
| @@ -102,7 +102,7 @@ · 14 unmodified lines | ||
| 102 | 102 | }) |
| 103 | 103 | |
| 104 | 104 | |
| 105 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 105 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 106 | 106 | ({ \ |
| 107 | 107 | register long _ret __asm__ ("r3"); \ |
| 108 | 108 | register long _num __asm__ ("r0") = (num); \ |
| @@ -125,7 +125,7 @@ · 16 unmodified lines | ||
| 125 | 125 | }) |
| 126 | 126 | |
| 127 | 127 | |
| 128 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 128 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 129 | 129 | ({ \ |
| 130 | 130 | register long _ret __asm__ ("r3"); \ |
| 131 | 131 | register long _num __asm__ ("r0") = (num); \ |
| @@ -148,7 +148,7 @@ · 16 unmodified lines | ||
| 148 | 148 | _ret; \ |
| 149 | 149 | }) |
| 150 | 150 | |
| 151 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 151 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 152 | 152 | ({ \ |
| 153 | 153 | register long _ret __asm__ ("r3"); \ |
| 154 | 154 | register long _num __asm__ ("r0") = (num); \ |
| @@ -21,7 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | * so that we don't have to experience issues with register constraints. |
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | −#define my_syscall0(num) \ | |
| 24 | +#define __nolibc_syscall0(num) \ | |
| 25 | 25 | ({ \ |
| 26 | 26 | register long _num __asm__ ("a7") = (num); \ |
| 27 | 27 | register long _arg1 __asm__ ("a0"); \ |
| @@ -35,7 +35,7 @@ · 7 unmodified lines | ||
| 35 | 35 | _arg1; \ |
| 36 | 36 | }) |
| 37 | 37 | |
| 38 | −#define my_syscall1(num, arg1) \ | |
| 38 | +#define __nolibc_syscall1(num, arg1) \ | |
| 39 | 39 | ({ \ |
| 40 | 40 | register long _num __asm__ ("a7") = (num); \ |
| 41 | 41 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -49,7 +49,7 @@ · 7 unmodified lines | ||
| 49 | 49 | _arg1; \ |
| 50 | 50 | }) |
| 51 | 51 | |
| 52 | −#define my_syscall2(num, arg1, arg2) \ | |
| 52 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 53 | 53 | ({ \ |
| 54 | 54 | register long _num __asm__ ("a7") = (num); \ |
| 55 | 55 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -65,7 +65,7 @@ · 9 unmodified lines | ||
| 65 | 65 | _arg1; \ |
| 66 | 66 | }) |
| 67 | 67 | |
| 68 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 68 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 69 | 69 | ({ \ |
| 70 | 70 | register long _num __asm__ ("a7") = (num); \ |
| 71 | 71 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -82,7 +82,7 @@ · 10 unmodified lines | ||
| 82 | 82 | _arg1; \ |
| 83 | 83 | }) |
| 84 | 84 | |
| 85 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 85 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 86 | 86 | ({ \ |
| 87 | 87 | register long _num __asm__ ("a7") = (num); \ |
| 88 | 88 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -100,7 +100,7 @@ · 11 unmodified lines | ||
| 100 | 100 | _arg1; \ |
| 101 | 101 | }) |
| 102 | 102 | |
| 103 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 103 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 104 | 104 | ({ \ |
| 105 | 105 | register long _num __asm__ ("a7") = (num); \ |
| 106 | 106 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -119,7 +119,7 @@ · 12 unmodified lines | ||
| 119 | 119 | _arg1; \ |
| 120 | 120 | }) |
| 121 | 121 | |
| 122 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 122 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 123 | 123 | ({ \ |
| 124 | 124 | register long _num __asm__ ("a7") = (num); \ |
| 125 | 125 | register long _arg1 __asm__ ("a0") = (long)(arg1); \ |
| @@ -28,7 +28,7 @@ · 27 unmodified lines | ||
| 28 | 28 | * |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | −#define my_syscall0(num) \ | |
| 31 | +#define __nolibc_syscall0(num) \ | |
| 32 | 32 | ({ \ |
| 33 | 33 | register long _num __asm__ ("1") = (num); \ |
| 34 | 34 | register long _rc __asm__ ("2"); \ |
| @@ -42,7 +42,7 @@ · 7 unmodified lines | ||
| 42 | 42 | _rc; \ |
| 43 | 43 | }) |
| 44 | 44 | |
| 45 | −#define my_syscall1(num, arg1) \ | |
| 45 | +#define __nolibc_syscall1(num, arg1) \ | |
| 46 | 46 | ({ \ |
| 47 | 47 | register long _num __asm__ ("1") = (num); \ |
| 48 | 48 | register long _arg1 __asm__ ("2") = (long)(arg1); \ |
| @@ -56,7 +56,7 @@ · 7 unmodified lines | ||
| 56 | 56 | _arg1; \ |
| 57 | 57 | }) |
| 58 | 58 | |
| 59 | −#define my_syscall2(num, arg1, arg2) \ | |
| 59 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 60 | 60 | ({ \ |
| 61 | 61 | register long _num __asm__ ("1") = (num); \ |
| 62 | 62 | register long _arg1 __asm__ ("2") = (long)(arg1); \ |
| @@ -71,7 +71,7 @@ · 8 unmodified lines | ||
| 71 | 71 | _arg1; \ |
| 72 | 72 | }) |
| 73 | 73 | |
| 74 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 74 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 75 | 75 | ({ \ |
| 76 | 76 | register long _num __asm__ ("1") = (num); \ |
| 77 | 77 | register long _arg1 __asm__ ("2") = (long)(arg1); \ |
| @@ -87,7 +87,7 @@ · 9 unmodified lines | ||
| 87 | 87 | _arg1; \ |
| 88 | 88 | }) |
| 89 | 89 | |
| 90 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 90 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 91 | 91 | ({ \ |
| 92 | 92 | register long _num __asm__ ("1") = (num); \ |
| 93 | 93 | register long _arg1 __asm__ ("2") = (long)(arg1); \ |
| @@ -104,7 +104,7 @@ · 10 unmodified lines | ||
| 104 | 104 | _arg1; \ |
| 105 | 105 | }) |
| 106 | 106 | |
| 107 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 107 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 108 | 108 | ({ \ |
| 109 | 109 | register long _num __asm__ ("1") = (num); \ |
| 110 | 110 | register long _arg1 __asm__ ("2") = (long)(arg1); \ |
| @@ -123,7 +123,7 @@ · 12 unmodified lines | ||
| 123 | 123 | _arg1; \ |
| 124 | 124 | }) |
| 125 | 125 | |
| 126 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 126 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 127 | 127 | ({ \ |
| 128 | 128 | register long _num __asm__ ("1") = (num); \ |
| 129 | 129 | register long _arg1 __asm__ ("2") = (long)(arg1); \ |
| @@ -167,8 +167,8 @@ struct s390_mmap_arg_struct { · 37 unmodified lines | ||
| 167 | 167 | }; |
| 168 | 168 | |
| 169 | 169 | static __attribute__((unused)) |
| 170 | −void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, | |
| 171 | − off_t offset) | |
| 170 | +void *_sys_mmap(void *addr, size_t length, int prot, int flags, int fd, | |
| 171 | + off_t offset) | |
| 172 | 172 | { |
| 173 | 173 | struct s390_mmap_arg_struct args = { |
| 174 | 174 | .addr = (unsigned long)addr, |
| @@ -179,22 +179,22 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, · 4 unmodified lines | ||
| 179 | 179 | .offset = (unsigned long)offset |
| 180 | 180 | }; |
| 181 | 181 | |
| 182 | − return (void *)my_syscall1(__NR_mmap, &args); | |
| 182 | + return (void *)__nolibc_syscall1(__NR_mmap, &args); | |
| 183 | 183 | } |
| 184 | −#define sys_mmap sys_mmap | |
| 184 | +#define _sys_mmap _sys_mmap | |
| 185 | 185 | |
| 186 | 186 | static __attribute__((unused)) |
| 187 | −pid_t sys_fork(void) | |
| 187 | +pid_t _sys_fork(void) | |
| 188 | 188 | { |
| 189 | − return my_syscall5(__NR_clone, 0, SIGCHLD, 0, 0, 0); | |
| 189 | + return __nolibc_syscall5(__NR_clone, 0, SIGCHLD, 0, 0, 0); | |
| 190 | 190 | } |
| 191 | −#define sys_fork sys_fork | |
| 191 | +#define _sys_fork _sys_fork | |
| 192 | 192 | |
| 193 | 193 | static __attribute__((unused)) |
| 194 | −pid_t sys_vfork(void) | |
| 194 | +pid_t _sys_vfork(void) | |
| 195 | 195 | { |
| 196 | − return my_syscall5(__NR_clone, 0, CLONE_VM | CLONE_VFORK | SIGCHLD, 0, 0, 0); | |
| 196 | + return __nolibc_syscall5(__NR_clone, 0, CLONE_VM | CLONE_VFORK | SIGCHLD, 0, 0, 0); | |
| 197 | 197 | } |
| 198 | −#define sys_vfork sys_vfork | |
| 198 | +#define _sys_vfork _sys_vfork | |
| 199 | 199 | |
| 200 | 200 | #endif /* _NOLIBC_ARCH_S390_H */ |
| @@ -19,7 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | * - syscall return value is in r0 |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | −#define my_syscall0(num) \ | |
| 22 | +#define __nolibc_syscall0(num) \ | |
| 23 | 23 | ({ \ |
| 24 | 24 | register long _num __asm__ ("r3") = (num); \ |
| 25 | 25 | register long _ret __asm__ ("r0"); \ |
| @@ -33,7 +33,7 @@ · 7 unmodified lines | ||
| 33 | 33 | _ret; \ |
| 34 | 34 | }) |
| 35 | 35 | |
| 36 | −#define my_syscall1(num, arg1) \ | |
| 36 | +#define __nolibc_syscall1(num, arg1) \ | |
| 37 | 37 | ({ \ |
| 38 | 38 | register long _num __asm__ ("r3") = (num); \ |
| 39 | 39 | register long _ret __asm__ ("r0"); \ |
| @@ -48,7 +48,7 @@ · 8 unmodified lines | ||
| 48 | 48 | _ret; \ |
| 49 | 49 | }) |
| 50 | 50 | |
| 51 | −#define my_syscall2(num, arg1, arg2) \ | |
| 51 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 52 | 52 | ({ \ |
| 53 | 53 | register long _num __asm__ ("r3") = (num); \ |
| 54 | 54 | register long _ret __asm__ ("r0"); \ |
| @@ -64,7 +64,7 @@ · 9 unmodified lines | ||
| 64 | 64 | _ret; \ |
| 65 | 65 | }) |
| 66 | 66 | |
| 67 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 67 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 68 | 68 | ({ \ |
| 69 | 69 | register long _num __asm__ ("r3") = (num); \ |
| 70 | 70 | register long _ret __asm__ ("r0"); \ |
| @@ -81,7 +81,7 @@ · 10 unmodified lines | ||
| 81 | 81 | _ret; \ |
| 82 | 82 | }) |
| 83 | 83 | |
| 84 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 84 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 85 | 85 | ({ \ |
| 86 | 86 | register long _num __asm__ ("r3") = (num); \ |
| 87 | 87 | register long _ret __asm__ ("r0"); \ |
| @@ -99,7 +99,7 @@ · 11 unmodified lines | ||
| 99 | 99 | _ret; \ |
| 100 | 100 | }) |
| 101 | 101 | |
| 102 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 102 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 103 | 103 | ({ \ |
| 104 | 104 | register long _num __asm__ ("r3") = (num); \ |
| 105 | 105 | register long _ret __asm__ ("r0"); \ |
| @@ -119,7 +119,7 @@ · 13 unmodified lines | ||
| 119 | 119 | _ret; \ |
| 120 | 120 | }) |
| 121 | 121 | |
| 122 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 122 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 123 | 123 | ({ \ |
| 124 | 124 | register long _num __asm__ ("r3") = (num); \ |
| 125 | 125 | register long _ret __asm__ ("r0"); \ |
| @@ -38,7 +38,7 @@ · 37 unmodified lines | ||
| 38 | 38 | |
| 39 | 39 | #endif /* __arch64__ */ |
| 40 | 40 | |
| 41 | −#define my_syscall0(num) \ | |
| 41 | +#define __nolibc_syscall0(num) \ | |
| 42 | 42 | ({ \ |
| 43 | 43 | register long _num __asm__ ("g1") = (num); \ |
| 44 | 44 | register long _arg1 __asm__ ("o0"); \ |
| @@ -52,7 +52,7 @@ · 7 unmodified lines | ||
| 52 | 52 | _arg1; \ |
| 53 | 53 | }) |
| 54 | 54 | |
| 55 | −#define my_syscall1(num, arg1) \ | |
| 55 | +#define __nolibc_syscall1(num, arg1) \ | |
| 56 | 56 | ({ \ |
| 57 | 57 | register long _num __asm__ ("g1") = (num); \ |
| 58 | 58 | register long _arg1 __asm__ ("o0") = (long)(arg1); \ |
| @@ -66,7 +66,7 @@ · 7 unmodified lines | ||
| 66 | 66 | _arg1; \ |
| 67 | 67 | }) |
| 68 | 68 | |
| 69 | −#define my_syscall2(num, arg1, arg2) \ | |
| 69 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 70 | 70 | ({ \ |
| 71 | 71 | register long _num __asm__ ("g1") = (num); \ |
| 72 | 72 | register long _arg1 __asm__ ("o0") = (long)(arg1); \ |
| @@ -81,7 +81,7 @@ · 8 unmodified lines | ||
| 81 | 81 | _arg1; \ |
| 82 | 82 | }) |
| 83 | 83 | |
| 84 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 84 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 85 | 85 | ({ \ |
| 86 | 86 | register long _num __asm__ ("g1") = (num); \ |
| 87 | 87 | register long _arg1 __asm__ ("o0") = (long)(arg1); \ |
| @@ -97,7 +97,7 @@ · 9 unmodified lines | ||
| 97 | 97 | _arg1; \ |
| 98 | 98 | }) |
| 99 | 99 | |
| 100 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 100 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 101 | 101 | ({ \ |
| 102 | 102 | register long _num __asm__ ("g1") = (num); \ |
| 103 | 103 | register long _arg1 __asm__ ("o0") = (long)(arg1); \ |
| @@ -114,7 +114,7 @@ · 10 unmodified lines | ||
| 114 | 114 | _arg1; \ |
| 115 | 115 | }) |
| 116 | 116 | |
| 117 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 117 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 118 | 118 | ({ \ |
| 119 | 119 | register long _num __asm__ ("g1") = (num); \ |
| 120 | 120 | register long _arg1 __asm__ ("o0") = (long)(arg1); \ |
| @@ -132,7 +132,7 @@ · 11 unmodified lines | ||
| 132 | 132 | _arg1; \ |
| 133 | 133 | }) |
| 134 | 134 | |
| 135 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 135 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 136 | 136 | ({ \ |
| 137 | 137 | register long _num __asm__ ("g1") = (num); \ |
| 138 | 138 | register long _arg1 __asm__ ("o0") = (long)(arg1); \ |
| @@ -175,12 +175,12 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 36 unmodified lines | ||
| 175 | 175 | static pid_t getpid(void); |
| 176 | 176 | |
| 177 | 177 | static __attribute__((unused)) |
| 178 | −pid_t sys_fork(void) | |
| 178 | +pid_t _sys_fork(void) | |
| 179 | 179 | { |
| 180 | 180 | pid_t parent, ret; |
| 181 | 181 | |
| 182 | 182 | parent = getpid(); |
| 183 | − ret = my_syscall0(__NR_fork); | |
| 183 | + ret = __nolibc_syscall0(__NR_fork); | |
| 184 | 184 | |
| 185 | 185 | /* The syscall returns the parent pid in the child instead of 0 */ |
| 186 | 186 | if (ret == parent) |
| @@ -188,15 +188,15 @@ pid_t sys_fork(void) · 1 unmodified line | ||
| 188 | 188 | else |
| 189 | 189 | return ret; |
| 190 | 190 | } |
| 191 | −#define sys_fork sys_fork | |
| 191 | +#define _sys_fork _sys_fork | |
| 192 | 192 | |
| 193 | 193 | static __attribute__((unused)) |
| 194 | −pid_t sys_vfork(void) | |
| 194 | +pid_t _sys_vfork(void) | |
| 195 | 195 | { |
| 196 | 196 | pid_t parent, ret; |
| 197 | 197 | |
| 198 | 198 | parent = getpid(); |
| 199 | − ret = my_syscall0(__NR_vfork); | |
| 199 | + ret = __nolibc_syscall0(__NR_vfork); | |
| 200 | 200 | |
| 201 | 201 | /* The syscall returns the parent pid in the child instead of 0 */ |
| 202 | 202 | if (ret == parent) |
| @@ -204,6 +204,6 @@ pid_t sys_vfork(void) · 1 unmodified line | ||
| 204 | 204 | else |
| 205 | 205 | return ret; |
| 206 | 206 | } |
| 207 | −#define sys_vfork sys_vfork | |
| 207 | +#define _sys_vfork _sys_vfork | |
| 208 | 208 | |
| 209 | 209 | #endif /* _NOLIBC_ARCH_SPARC_H */ |
| @@ -30,7 +30,7 @@ · 29 unmodified lines | ||
| 30 | 30 | */ |
| 31 | 31 | #define __ARCH_WANT_SYS_OLD_SELECT |
| 32 | 32 | |
| 33 | −#define my_syscall0(num) \ | |
| 33 | +#define __nolibc_syscall0(num) \ | |
| 34 | 34 | ({ \ |
| 35 | 35 | long _ret; \ |
| 36 | 36 | register long _num __asm__ ("eax") = (num); \ |
| @@ -44,7 +44,7 @@ · 7 unmodified lines | ||
| 44 | 44 | _ret; \ |
| 45 | 45 | }) |
| 46 | 46 | |
| 47 | −#define my_syscall1(num, arg1) \ | |
| 47 | +#define __nolibc_syscall1(num, arg1) \ | |
| 48 | 48 | ({ \ |
| 49 | 49 | long _ret; \ |
| 50 | 50 | register long _num __asm__ ("eax") = (num); \ |
| @@ -60,7 +60,7 @@ · 9 unmodified lines | ||
| 60 | 60 | _ret; \ |
| 61 | 61 | }) |
| 62 | 62 | |
| 63 | −#define my_syscall2(num, arg1, arg2) \ | |
| 63 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 64 | 64 | ({ \ |
| 65 | 65 | long _ret; \ |
| 66 | 66 | register long _num __asm__ ("eax") = (num); \ |
| @@ -77,7 +77,7 @@ · 10 unmodified lines | ||
| 77 | 77 | _ret; \ |
| 78 | 78 | }) |
| 79 | 79 | |
| 80 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 80 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 81 | 81 | ({ \ |
| 82 | 82 | long _ret; \ |
| 83 | 83 | register long _num __asm__ ("eax") = (num); \ |
| @@ -95,7 +95,7 @@ · 11 unmodified lines | ||
| 95 | 95 | _ret; \ |
| 96 | 96 | }) |
| 97 | 97 | |
| 98 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 98 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 99 | 99 | ({ \ |
| 100 | 100 | long _ret; \ |
| 101 | 101 | register long _num __asm__ ("eax") = (num); \ |
| @@ -114,7 +114,7 @@ · 12 unmodified lines | ||
| 114 | 114 | _ret; \ |
| 115 | 115 | }) |
| 116 | 116 | |
| 117 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 117 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 118 | 118 | ({ \ |
| 119 | 119 | long _ret; \ |
| 120 | 120 | register long _num __asm__ ("eax") = (num); \ |
| @@ -134,27 +134,27 @@ · 13 unmodified lines | ||
| 134 | 134 | _ret; \ |
| 135 | 135 | }) |
| 136 | 136 | |
| 137 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 138 | −({ \ | |
| 139 | − long _eax = (long)(num); \ | |
| 140 | − long _arg6 = (long)(arg6); /* Always in memory */ \ | |
| 141 | − __asm__ volatile ( \ | |
| 142 | − "pushl %[_arg6]\n\t" \ | |
| 143 | − "pushl %%ebp\n\t" \ | |
| 144 | − "movl 4(%%esp),%%ebp\n\t" \ | |
| 145 | − "int $0x80\n\t" \ | |
| 146 | − "popl %%ebp\n\t" \ | |
| 147 | − "addl $4,%%esp\n\t" \ | |
| 148 | − : "+a"(_eax) /* %eax */ \ | |
| 149 | − : "b"(arg1), /* %ebx */ \ | |
| 150 | − "c"(arg2), /* %ecx */ \ | |
| 151 | − "d"(arg3), /* %edx */ \ | |
| 152 | − "S"(arg4), /* %esi */ \ | |
| 153 | − "D"(arg5), /* %edi */ \ | |
| 154 | − [_arg6]"m"(_arg6) /* memory */ \ | |
| 155 | − : "memory", "cc" \ | |
| 156 | − ); \ | |
| 157 | − _eax; \ | |
| 137 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 138 | +({ \ | |
| 139 | + long _eax = (long)(num); \ | |
| 140 | + long _arg6 = (long)(arg6); /* Always in memory */ \ | |
| 141 | + __asm__ volatile ( \ | |
| 142 | + "pushl %[_arg6]\n\t" \ | |
| 143 | + "pushl %%ebp\n\t" \ | |
| 144 | + "movl 4(%%esp),%%ebp\n\t" \ | |
| 145 | + "int $0x80\n\t" \ | |
| 146 | + "popl %%ebp\n\t" \ | |
| 147 | + "addl $4,%%esp\n\t" \ | |
| 148 | + : "+a"(_eax) /* %eax */ \ | |
| 149 | + : "b"(arg1), /* %ebx */ \ | |
| 150 | + "c"(arg2), /* %ecx */ \ | |
| 151 | + "d"(arg3), /* %edx */ \ | |
| 152 | + "S"(arg4), /* %esi */ \ | |
| 153 | + "D"(arg5), /* %edi */ \ | |
| 154 | + [_arg6]"m"(_arg6) /* memory */ \ | |
| 155 | + : "memory", "cc" \ | |
| 156 | + ); \ | |
| 157 | + _eax; \ | |
| 158 | 158 | }) |
| 159 | 159 | |
| 160 | 160 | #ifndef NOLIBC_NO_RUNTIME |
| @@ -200,7 +200,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 39 unmodified lines | ||
| 200 | 200 | * |
| 201 | 201 | */ |
| 202 | 202 | |
| 203 | −#define my_syscall0(num) \ | |
| 203 | +#define __nolibc_syscall0(num) \ | |
| 204 | 204 | ({ \ |
| 205 | 205 | long _ret; \ |
| 206 | 206 | register long _num __asm__ ("rax") = (num); \ |
| @@ -214,7 +214,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 7 unmodified lines | ||
| 214 | 214 | _ret; \ |
| 215 | 215 | }) |
| 216 | 216 | |
| 217 | −#define my_syscall1(num, arg1) \ | |
| 217 | +#define __nolibc_syscall1(num, arg1) \ | |
| 218 | 218 | ({ \ |
| 219 | 219 | long _ret; \ |
| 220 | 220 | register long _num __asm__ ("rax") = (num); \ |
| @@ -230,7 +230,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 9 unmodified lines | ||
| 230 | 230 | _ret; \ |
| 231 | 231 | }) |
| 232 | 232 | |
| 233 | −#define my_syscall2(num, arg1, arg2) \ | |
| 233 | +#define __nolibc_syscall2(num, arg1, arg2) \ | |
| 234 | 234 | ({ \ |
| 235 | 235 | long _ret; \ |
| 236 | 236 | register long _num __asm__ ("rax") = (num); \ |
| @@ -247,7 +247,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 10 unmodified lines | ||
| 247 | 247 | _ret; \ |
| 248 | 248 | }) |
| 249 | 249 | |
| 250 | −#define my_syscall3(num, arg1, arg2, arg3) \ | |
| 250 | +#define __nolibc_syscall3(num, arg1, arg2, arg3) \ | |
| 251 | 251 | ({ \ |
| 252 | 252 | long _ret; \ |
| 253 | 253 | register long _num __asm__ ("rax") = (num); \ |
| @@ -265,7 +265,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 11 unmodified lines | ||
| 265 | 265 | _ret; \ |
| 266 | 266 | }) |
| 267 | 267 | |
| 268 | −#define my_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 268 | +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \ | |
| 269 | 269 | ({ \ |
| 270 | 270 | long _ret; \ |
| 271 | 271 | register long _num __asm__ ("rax") = (num); \ |
| @@ -284,7 +284,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 12 unmodified lines | ||
| 284 | 284 | _ret; \ |
| 285 | 285 | }) |
| 286 | 286 | |
| 287 | −#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 287 | +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ | |
| 288 | 288 | ({ \ |
| 289 | 289 | long _ret; \ |
| 290 | 290 | register long _num __asm__ ("rax") = (num); \ |
| @@ -304,7 +304,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s · 13 unmodified lines | ||
| 304 | 304 | _ret; \ |
| 305 | 305 | }) |
| 306 | 306 | |
| 307 | −#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 307 | +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ | |
| 308 | 308 | ({ \ |
| 309 | 309 | long _ret; \ |
| 310 | 310 | register long _num __asm__ ("rax") = (num); \ |
| @@ -0,0 +1,21 @@ | ||
| 1 | +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ | |
| 2 | +/* | |
| 3 | + * Byte swapping for NOLIBC | |
| 4 | + * Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net> | |
| 5 | + */ | |
| 6 | + | |
| 7 | +/* make sure to include all global symbols */ | |
| 8 | +#include "nolibc.h" | |
| 9 | + | |
| 10 | +#ifndef _NOLIBC_BYTESWAP_H | |
| 11 | +#define _NOLIBC_BYTESWAP_H | |
| 12 | + | |
| 13 | +#include "stdint.h" | |
| 14 | + | |
| 15 | +#include <linux/swab.h> | |
| 16 | + | |
| 17 | +#define bswap_16(_x) __swab16(_x) | |
| 18 | +#define bswap_32(_x) __swab32(_x) | |
| 19 | +#define bswap_64(_x) __swab64(_x) | |
| 20 | + | |
| 21 | +#endif /* _NOLIBC_BYTESWAP_H */ | |
| @@ -47,6 +47,12 @@ · 46 unmodified lines | ||
| 47 | 47 | # define __nolibc_fallthrough do { } while (0) |
| 48 | 48 | #endif /* __nolibc_has_attribute(fallthrough) */ |
| 49 | 49 | |
| 50 | +#if defined(__STDC_VERSION__) | |
| 51 | +# define __nolibc_stdc_version __STDC_VERSION__ | |
| 52 | +#else | |
| 53 | +# define __nolibc_stdc_version 0 | |
| 54 | +#endif | |
| 55 | + | |
| 50 | 56 | #define __nolibc_version(_major, _minor, _patch) ((_major) * 10000 + (_minor) * 100 + (_patch)) |
| 51 | 57 | |
| 52 | 58 | #ifdef __GNUC__ |
| @@ -63,7 +69,7 @@ · 10 unmodified lines | ||
| 63 | 69 | # define __nolibc_clang_version 0 |
| 64 | 70 | #endif /* __clang__ */ |
| 65 | 71 | |
| 66 | −#if __STDC_VERSION__ >= 201112L || \ | |
| 72 | +#if __nolibc_stdc_version >= 201112L || \ | |
| 67 | 73 | __nolibc_gnuc_version >= __nolibc_version(4, 6, 0) || \ |
| 68 | 74 | __nolibc_clang_version >= __nolibc_version(3, 0, 0) |
| 69 | 75 | # define __nolibc_static_assert(_t) _Static_assert(_t, "") |
| @@ -71,4 +77,17 @@ · 1 unmodified line | ||
| 71 | 77 | # define __nolibc_static_assert(_t) |
| 72 | 78 | #endif |
| 73 | 79 | |
| 80 | +/* Make the optimizer believe the variable can be manipulated arbitrarily. */ | |
| 81 | +#define _NOLIBC_OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "+r" (var)) | |
| 82 | + | |
| 83 | +#if __nolibc_has_feature(undefined_behavior_sanitizer) | |
| 84 | +# if defined(__clang__) | |
| 85 | +# define __nolibc_no_sanitize_undefined __attribute__((no_sanitize("function"))) | |
| 86 | +# else | |
| 87 | +# define __nolibc_no_sanitize_undefined __attribute__((no_sanitize_undefined)) | |
| 88 | +# endif | |
| 89 | +#else | |
| 90 | +# define __nolibc_no_sanitize_undefined | |
| 91 | +#endif | |
| 92 | + | |
| 74 | 93 | #endif /* _NOLIBC_COMPILER_H */ |
| @@ -17,6 +17,7 @@ const unsigned long *_auxv __attribute__((weak)); · 16 unmodified lines | ||
| 17 | 17 | void _start(void); |
| 18 | 18 | static void __stack_chk_init(void); |
| 19 | 19 | static void exit(int); |
| 20 | +static char *strrchr(const char *s, int c); | |
| 20 | 21 | |
| 21 | 22 | extern void (*const __preinit_array_start[])(int, char **, char**) __attribute__((weak)); |
| 22 | 23 | extern void (*const __preinit_array_end[])(int, char **, char**) __attribute__((weak)); |
| @@ -27,11 +28,26 @@ extern void (*const __init_array_end[])(int, char **, char**) __attribute__((wea · 4 unmodified lines | ||
| 27 | 28 | extern void (*const __fini_array_start[])(void) __attribute__((weak)); |
| 28 | 29 | extern void (*const __fini_array_end[])(void) __attribute__((weak)); |
| 29 | 30 | |
| 31 | +#ifndef NOLIBC_IGNORE_ERRNO | |
| 32 | +extern char *program_invocation_name __attribute__((weak)); | |
| 33 | +extern char *program_invocation_short_name __attribute__((weak)); | |
| 34 | + | |
| 35 | +static __inline__ | |
| 36 | +char *__nolibc_program_invocation_short_name(char *long_name) | |
| 37 | +{ | |
| 38 | + | |
| 39 | + char *short_name; | |
| 40 | + | |
| 41 | + short_name = strrchr(long_name, '/'); | |
| 42 | + if (!short_name || !short_name[0]) | |
| 43 | + return long_name; | |
| 44 | + | |
| 45 | + return short_name + 1; | |
| 46 | +} | |
| 47 | +#endif /* NOLIBC_IGNORE_ERRNO */ | |
| 48 | + | |
| 30 | 49 | void _start_c(long *sp); |
| 31 | −__attribute__((weak,used)) | |
| 32 | −#if __nolibc_has_feature(undefined_behavior_sanitizer) | |
| 33 | − __attribute__((no_sanitize("function"))) | |
| 34 | −#endif | |
| 50 | +__attribute__((weak,used)) __nolibc_no_sanitize_undefined | |
| 35 | 51 | void _start_c(long *sp) |
| 36 | 52 | { |
| 37 | 53 | long argc; |
| @@ -76,6 +92,13 @@ void _start_c(long *sp) · 38 unmodified lines | ||
| 76 | 92 | ; |
| 77 | 93 | _auxv = auxv; |
| 78 | 94 | |
| 95 | +#ifndef NOLIBC_IGNORE_ERRNO | |
| 96 | + if (argc > 0 && argv[0]) { | |
| 97 | + program_invocation_name = argv[0]; | |
| 98 | + program_invocation_short_name = __nolibc_program_invocation_short_name(argv[0]); | |
| 99 | + } | |
| 100 | +#endif /* NOLIBC_IGNORE_ERRNO */ | |
| 101 | + | |
| 79 | 102 | for (ctor_func = __preinit_array_start; ctor_func < __preinit_array_end; ctor_func++) |
| 80 | 103 | (*ctor_func)(argc, argv, envp); |
| 81 | 104 | for (ctor_func = __init_array_start; ctor_func < __init_array_end; ctor_func++) |
| @@ -73,7 +73,7 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) · 72 unmodified lines | ||
| 73 | 73 | |
| 74 | 74 | fd = ~i; |
| 75 | 75 | |
| 76 | − ret = sys_getdents64(fd, ldir, sizeof(buf)); | |
| 76 | + ret = _sys_getdents64(fd, ldir, sizeof(buf)); | |
| 77 | 77 | if (ret < 0) |
| 78 | 78 | return -ret; |
| 79 | 79 | if (ret == 0) { |
| @@ -86,7 +86,7 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) · 6 unmodified lines | ||
| 86 | 86 | * readdir() can only return one entry at a time. |
| 87 | 87 | * Make sure the non-returned ones are not skipped. |
| 88 | 88 | */ |
| 89 | − ret = sys_lseek(fd, ldir->d_off, SEEK_SET); | |
| 89 | + ret = _sys_lseek(fd, ldir->d_off, SEEK_SET); | |
| 90 | 90 | if (ret < 0) |
| 91 | 91 | return -ret; |
| 92 | 92 | |
| @@ -0,0 +1,32 @@ | ||
| 1 | +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ | |
| 2 | +/* | |
| 3 | + * Byte order conversion for NOLIBC | |
| 4 | + * Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net> | |
| 5 | + */ | |
| 6 | + | |
| 7 | +/* make sure to include all global symbols */ | |
| 8 | +#include "nolibc.h" | |
| 9 | + | |
| 10 | +#ifndef _NOLIBC_ENDIAN_H | |
| 11 | +#define _NOLIBC_ENDIAN_H | |
| 12 | + | |
| 13 | +#include "stdint.h" | |
| 14 | + | |
| 15 | +#include <asm/byteorder.h> | |
| 16 | + | |
| 17 | +#define htobe16(_x) __cpu_to_be16(_x) | |
| 18 | +#define htole16(_x) __cpu_to_le16(_x) | |
| 19 | +#define be16toh(_x) __be16_to_cpu(_x) | |
| 20 | +#define le16toh(_x) __le16_to_cpu(_x) | |
| 21 | + | |
| 22 | +#define htobe32(_x) __cpu_to_be32(_x) | |
| 23 | +#define htole32(_x) __cpu_to_le32(_x) | |
| 24 | +#define be32toh(_x) __be32_to_cpu(_x) | |
| 25 | +#define le32toh(_x) __le32_to_cpu(_x) | |
| 26 | + | |
| 27 | +#define htobe64(_x) __cpu_to_be64(_x) | |
| 28 | +#define htole64(_x) __cpu_to_le64(_x) | |
| 29 | +#define be64toh(_x) __be64_to_cpu(_x) | |
| 30 | +#define le64toh(_x) __le64_to_cpu(_x) | |
| 31 | + | |
| 32 | +#endif /* _NOLIBC_ENDIAN_H */ | |
| @@ -0,0 +1,87 @@ | ||
| 1 | +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ | |
| 2 | +/* | |
| 3 | + * formatted error message for NOLIBC | |
| 4 | + * Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net> | |
| 5 | + */ | |
| 6 | + | |
| 7 | +/* make sure to include all global symbols */ | |
| 8 | +#include "nolibc.h" | |
| 9 | + | |
| 10 | +#ifndef _NOLIBC_ERR_H | |
| 11 | +#define _NOLIBC_ERR_H | |
| 12 | + | |
| 13 | +#include "errno.h" | |
| 14 | +#include "stdarg.h" | |
| 15 | +#include "sys.h" | |
| 16 | + | |
| 17 | +static __attribute__((unused)) | |
| 18 | +void vwarn(const char *fmt, va_list args) | |
| 19 | +{ | |
| 20 | + fprintf(stderr, "%s: ", program_invocation_short_name); | |
| 21 | + vfprintf(stderr, fmt, args); | |
| 22 | + fprintf(stderr, ": %m\n"); | |
| 23 | +} | |
| 24 | + | |
| 25 | +static __attribute__((unused)) | |
| 26 | +void vwarnx(const char *fmt, va_list args) | |
| 27 | +{ | |
| 28 | + fprintf(stderr, "%s: ", program_invocation_short_name); | |
| 29 | + vfprintf(stderr, fmt, args); | |
| 30 | + fprintf(stderr, "\n"); | |
| 31 | +} | |
| 32 | + | |
| 33 | +static __attribute__((unused)) | |
| 34 | +void warn(const char *fmt, ...) | |
| 35 | +{ | |
| 36 | + va_list args; | |
| 37 | + | |
| 38 | + va_start(args, fmt); | |
| 39 | + vwarn(fmt, args); | |
| 40 | + va_end(args); | |
| 41 | +} | |
| 42 | + | |
| 43 | +static __attribute__((unused)) | |
| 44 | +void warnx(const char *fmt, ...) | |
| 45 | +{ | |
| 46 | + va_list args; | |
| 47 | + | |
| 48 | + va_start(args, fmt); | |
| 49 | + vwarnx(fmt, args); | |
| 50 | + va_end(args); | |
| 51 | +} | |
| 52 | + | |
| 53 | +static __attribute__((noreturn, unused)) | |
| 54 | +void verr(int eval, const char *fmt, va_list args) | |
| 55 | +{ | |
| 56 | + vwarn(fmt, args); | |
| 57 | + exit(eval); | |
| 58 | +} | |
| 59 | + | |
| 60 | +static __attribute__((noreturn, unused)) | |
| 61 | +void verrx(int eval, const char *fmt, va_list args) | |
| 62 | +{ | |
| 63 | + warnx(fmt, args); | |
| 64 | + exit(eval); | |
| 65 | +} | |
| 66 | + | |
| 67 | +static __attribute__((noreturn, unused)) | |
| 68 | +void err(int eval, const char *fmt, ...) | |
| 69 | +{ | |
| 70 | + va_list args; | |
| 71 | + | |
| 72 | + va_start(args, fmt); | |
| 73 | + verr(eval, fmt, args); | |
| 74 | + va_end(args); | |
| 75 | +} | |
| 76 | + | |
| 77 | +static __attribute__((noreturn, unused)) | |
| 78 | +void errx(int eval, const char *fmt, ...) | |
| 79 | +{ | |
| 80 | + va_list args; | |
| 81 | + | |
| 82 | + va_start(args, fmt); | |
| 83 | + verrx(eval, fmt, args); | |
| 84 | + va_end(args); | |
| 85 | +} | |
| 86 | + | |
| 87 | +#endif /* _NOLIBC_ERR_H */ | |
| @@ -15,8 +15,12 @@ · 14 unmodified lines | ||
| 15 | 15 | #ifndef NOLIBC_IGNORE_ERRNO |
| 16 | 16 | #define SET_ERRNO(v) do { errno = (v); } while (0) |
| 17 | 17 | int errno __attribute__((weak)); |
| 18 | +char *program_invocation_name __attribute__((weak)) = ""; | |
| 19 | +char *program_invocation_short_name __attribute__((weak)) = ""; | |
| 18 | 20 | #else |
| 19 | 21 | #define SET_ERRNO(v) do { } while (0) |
| 22 | +#define program_invocation_name "" | |
| 23 | +#define program_invocation_short_name "" | |
| 20 | 24 | #endif |
| 21 | 25 | |
| 22 | 26 | |
| @@ -19,9 +19,9 @@ · 18 unmodified lines | ||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | static __attribute__((unused)) |
| 22 | −int sys_openat(int dirfd, const char *path, int flags, mode_t mode) | |
| 22 | +int _sys_openat(int dirfd, const char *path, int flags, mode_t mode) | |
| 23 | 23 | { |
| 24 | − return my_syscall4(__NR_openat, dirfd, path, flags, mode); | |
| 24 | + return __nolibc_syscall4(__NR_openat, dirfd, path, flags, mode); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | static __attribute__((unused)) |
| @@ -37,7 +37,7 @@ int openat(int dirfd, const char *path, int flags, ...) · 9 unmodified lines | ||
| 37 | 37 | va_end(args); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | − return __sysret(sys_openat(dirfd, path, flags, mode)); | |
| 40 | + return __sysret(_sys_openat(dirfd, path, flags, mode)); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /* |
| @@ -45,9 +45,9 @@ int openat(int dirfd, const char *path, int flags, ...) · 1 unmodified line | ||
| 45 | 45 | */ |
| 46 | 46 | |
| 47 | 47 | static __attribute__((unused)) |
| 48 | −int sys_open(const char *path, int flags, mode_t mode) | |
| 48 | +int _sys_open(const char *path, int flags, mode_t mode) | |
| 49 | 49 | { |
| 50 | − return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode); | |
| 50 | + return __nolibc_syscall4(__NR_openat, AT_FDCWD, path, flags, mode); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | static __attribute__((unused)) |
| @@ -63,7 +63,7 @@ int open(const char *path, int flags, ...) · 9 unmodified lines | ||
| 63 | 63 | va_end(args); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | − return __sysret(sys_open(path, flags, mode)); | |
| 66 | + return __sysret(_sys_open(path, flags, mode)); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | #endif /* _NOLIBC_FCNTL_H */ |
| @@ -12,24 +12,24 @@ · 11 unmodified lines | ||
| 12 | 12 | * |
| 13 | 13 | * Syscalls are split into 3 levels: |
| 14 | 14 | * - The lower level is the arch-specific syscall() definition, consisting in |
| 15 | − * assembly code in compound expressions. These are called my_syscall0() to | |
| 16 | − * my_syscall6() depending on the number of arguments. All input arguments | |
| 15 | + * assembly code in compound expressions. These are called __nolibc_syscall0() to | |
| 16 | + * __nolibc_syscall6() depending on the number of arguments. All input arguments | |
| 17 | 17 | * are castto a long stored in a register. These expressions always return |
| 18 | 18 | * the syscall's return value as a signed long value which is often either |
| 19 | 19 | * a pointer or the negated errno value. |
| 20 | 20 | * |
| 21 | 21 | * - The second level is mostly architecture-independent. It is made of |
| 22 | − * static functions called sys_<name>() which rely on my_syscallN() | |
| 22 | + * static functions called _sys_<name>() which rely on __nolibc_syscallN() | |
| 23 | 23 | * depending on the syscall definition. These functions are responsible |
| 24 | 24 | * for exposing the appropriate types for the syscall arguments (int, |
| 25 | 25 | * pointers, etc) and for setting the appropriate return type (often int). |
| 26 | 26 | * A few of them are architecture-specific because the syscalls are not all |
| 27 | 27 | * mapped exactly the same among architectures. For example, some archs do |
| 28 | − * not implement select() and need pselect6() instead, so the sys_select() | |
| 28 | + * not implement select() and need pselect6() instead, so the _sys_select() | |
| 29 | 29 | * function will have to abstract this. |
| 30 | 30 | * |
| 31 | 31 | * - The third level is the libc call definition. It exposes the lower raw |
| 32 | − * sys_<name>() calls in a way that looks like what a libc usually does, | |
| 32 | + * _sys_<name>() calls in a way that looks like what a libc usually does, | |
| 33 | 33 | * takes care of specific input values, and of setting errno upon error. |
| 34 | 34 | * There can be minor variations compared to standard libc calls. |
| 35 | 35 | * |
| @@ -130,6 +130,9 @@ · 94 unmodified lines | ||
| 130 | 130 | #include "getopt.h" |
| 131 | 131 | #include "poll.h" |
| 132 | 132 | #include "math.h" |
| 133 | +#include "err.h" | |
| 134 | +#include "byteswap.h" | |
| 135 | +#include "endian.h" | |
| 133 | 136 | |
| 134 | 137 | /* Used by programs to avoid std includes */ |
| 135 | 138 | #define NOLIBC |
| @@ -21,7 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | static __attribute__((unused)) |
| 24 | −int sys_poll(struct pollfd *fds, int nfds, int timeout) | |
| 24 | +int _sys_poll(struct pollfd *fds, int nfds, int timeout) | |
| 25 | 25 | { |
| 26 | 26 | #if defined(__NR_ppoll_time64) |
| 27 | 27 | struct __kernel_timespec t; |
| @@ -30,7 +30,7 @@ int sys_poll(struct pollfd *fds, int nfds, int timeout) · 2 unmodified lines | ||
| 30 | 30 | t.tv_sec = timeout / 1000; |
| 31 | 31 | t.tv_nsec = (timeout % 1000) * 1000000; |
| 32 | 32 | } |
| 33 | − return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); | |
| 33 | + return __nolibc_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); | |
| 34 | 34 | #else |
| 35 | 35 | struct __kernel_old_timespec t; |
| 36 | 36 | |
| @@ -38,14 +38,14 @@ int sys_poll(struct pollfd *fds, int nfds, int timeout) · 1 unmodified line | ||
| 38 | 38 | t.tv_sec = timeout / 1000; |
| 39 | 39 | t.tv_nsec = (timeout % 1000) * 1000000; |
| 40 | 40 | } |
| 41 | − return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); | |
| 41 | + return __nolibc_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); | |
| 42 | 42 | #endif |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | static __attribute__((unused)) |
| 46 | 46 | int poll(struct pollfd *fds, int nfds, int timeout) |
| 47 | 47 | { |
| 48 | − return __sysret(sys_poll(fds, nfds, timeout)); | |
| 48 | + return __sysret(_sys_poll(fds, nfds, timeout)); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | #endif /* _NOLIBC_POLL_H */ |
| @@ -19,15 +19,15 @@ · 18 unmodified lines | ||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | static __attribute__((unused)) |
| 22 | −int sys_setns(int fd, int nstype) | |
| 22 | +int _sys_setns(int fd, int nstype) | |
| 23 | 23 | { |
| 24 | − return my_syscall2(__NR_setns, fd, nstype); | |
| 24 | + return __nolibc_syscall2(__NR_setns, fd, nstype); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | static __attribute__((unused)) |
| 28 | 28 | int setns(int fd, int nstype) |
| 29 | 29 | { |
| 30 | − return __sysret(sys_setns(fd, nstype)); | |
| 30 | + return __sysret(_sys_setns(fd, nstype)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
| @@ -36,15 +36,15 @@ int setns(int fd, int nstype) · 2 unmodified lines | ||
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | 38 | static __attribute__((unused)) |
| 39 | −int sys_unshare(int flags) | |
| 39 | +int _sys_unshare(int flags) | |
| 40 | 40 | { |
| 41 | − return my_syscall1(__NR_unshare, flags); | |
| 41 | + return __nolibc_syscall1(__NR_unshare, flags); | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | static __attribute__((unused)) |
| 45 | 45 | int unshare(int flags) |
| 46 | 46 | { |
| 47 | − return __sysret(sys_unshare(flags)); | |
| 47 | + return __sysret(_sys_unshare(flags)); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | #endif /* _NOLIBC_SCHED_H */ |
| @@ -20,7 +20,7 @@ int raise(int signal); · 19 unmodified lines | ||
| 20 | 20 | __attribute__((weak,unused,section(".text.nolibc_raise"))) |
| 21 | 21 | int raise(int signal) |
| 22 | 22 | { |
| 23 | − return sys_kill(sys_getpid(), signal); | |
| 23 | + return _sys_kill(_sys_getpid(), signal); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | #endif /* _NOLIBC_SIGNAL_H */ |
| @@ -24,9 +24,9 @@ __attribute__((weak,used,noreturn,section(".text.nolibc_stack_chk"))) · 23 unmodified lines | ||
| 24 | 24 | void __stack_chk_fail(void) |
| 25 | 25 | { |
| 26 | 26 | pid_t pid; |
| 27 | − my_syscall3(__NR_write, STDERR_FILENO, "!!Stack smashing detected!!\n", 28); | |
| 28 | − pid = my_syscall0(__NR_getpid); | |
| 29 | − my_syscall2(__NR_kill, pid, SIGABRT); | |
| 27 | + __nolibc_syscall3(__NR_write, STDERR_FILENO, "!!Stack smashing detected!!\n", 28); | |
| 28 | + pid = __nolibc_syscall0(__NR_getpid); | |
| 29 | + __nolibc_syscall2(__NR_kill, pid, SIGABRT); | |
| 30 | 30 | for (;;); |
| 31 | 31 | } |
| 32 | 32 | |
| @@ -42,7 +42,7 @@ uintptr_t __stack_chk_guard; · 9 unmodified lines | ||
| 42 | 42 | |
| 43 | 43 | static __no_stack_protector void __stack_chk_init(void) |
| 44 | 44 | { |
| 45 | − my_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0); | |
| 45 | + __nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0); | |
| 46 | 46 | /* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */ |
| 47 | 47 | if (__stack_chk_guard != (uintptr_t) &__stack_chk_guard) |
| 48 | 48 | __stack_chk_guard ^= (uintptr_t) &__stack_chk_guard; |
| @@ -19,7 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | #include <linux/types.h> |
| 20 | 20 | |
| 21 | 21 | /* those are commonly provided by sys/types.h */ |
| 22 | −typedef unsigned int dev_t; | |
| 22 | +typedef uint64_t dev_t; | |
| 23 | 23 | typedef uint64_t ino_t; |
| 24 | 24 | typedef unsigned int mode_t; |
| 25 | 25 | typedef signed int pid_t; |
| @@ -18,7 +18,7 @@ · 17 unmodified lines | ||
| 18 | 18 | #endif |
| 19 | 19 | |
| 20 | 20 | #ifndef offsetof |
| 21 | −#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) | |
| 21 | +#define offsetof(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD) | |
| 22 | 22 | #endif |
| 23 | 23 | |
| 24 | 24 | #endif /* _NOLIBC_STDDEF_H */ |
| @@ -291,156 +291,371 @@ int fseek(FILE *stream, long offset, int whence) · 290 unmodified lines | ||
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | |
| 294 | −/* minimal printf(). It supports the following formats: | |
| 295 | − * - %[l*]{d,u,c,x,p} | |
| 296 | − * - %s | |
| 297 | − * - unknown modifiers are ignored. | |
| 294 | +/* printf(). Supports most of the normal integer and string formats. | |
| 295 | + * - %[#0-+ ][width|*[.precision|*}][{l,t,z,ll,L,j,q}]{c,d,i,u,o,x,X,p,s,m,%} | |
| 296 | + * - %% generates a single % | |
| 297 | + * - %m outputs strerror(errno). | |
| 298 | + * - %X outputs a..f the same as %x. | |
| 299 | + * - No support for floating point or wide characters. | |
| 300 | + * - Invalid formats are copied to the output buffer. | |
| 301 | + * | |
| 302 | + * Called by vfprintf() and snprintf() to do the actual formatting. | |
| 303 | + * The callers provide a callback function to save the formatted data. | |
| 304 | + * The callback function is called multiple times: | |
| 305 | + * - for each group of literal characters in the format string. | |
| 306 | + * - for field padding. | |
| 307 | + * - for each conversion specifier. | |
| 308 | + * - with (NULL, 0) at the end of the __nolibc_printf. | |
| 309 | + * If the callback returns non-zero __nolibc_printf() immediately returns -1. | |
| 298 | 310 | */ |
| 299 | −typedef int (*__nolibc_printf_cb)(intptr_t state, const char *buf, size_t size); | |
| 300 | 311 | |
| 301 | −static __attribute__((unused, format(printf, 4, 0))) | |
| 302 | −int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char *fmt, va_list args) | |
| 312 | +typedef int (*__nolibc_printf_cb)(void *state, const char *buf, size_t size); | |
| 313 | + | |
| 314 | +/* This code uses 'flag' variables that are indexed by the low 6 bits | |
| 315 | + * of characters to optimise checks for multiple characters. | |
| 316 | + * | |
| 317 | + * _NOLIBC_PF_FLAGS_CONTAIN(flags, 'a', 'b'. ...) | |
| 318 | + * returns non-zero if the bit for any of the specified characters is set. | |
| 319 | + * | |
| 320 | + * _NOLIBC_PF_CHAR_IS_ONE_OF(ch, 'a', 'b'. ...) | |
| 321 | + * returns the flag bit for ch if it is one of the specified characters. | |
| 322 | + * All the characters must be in the same 32 character block (non-alphabetic, | |
| 323 | + * upper case, or lower case) of the ASCII character set. | |
| 324 | + */ | |
| 325 | +#define _NOLIBC_PF_FLAG(ch) (1u << ((ch) & 0x1f)) | |
| 326 | +#define _NOLIBC_PF_FLAG_NZ(ch) ((ch) ? _NOLIBC_PF_FLAG(ch) : 0) | |
| 327 | +#define _NOLIBC_PF_FLAG8(cmp_1, cmp_2, cmp_3, cmp_4, cmp_5, cmp_6, cmp_7, cmp_8, ...) \ | |
| 328 | + (_NOLIBC_PF_FLAG_NZ(cmp_1) | _NOLIBC_PF_FLAG_NZ(cmp_2) | \ | |
| 329 | + _NOLIBC_PF_FLAG_NZ(cmp_3) | _NOLIBC_PF_FLAG_NZ(cmp_4) | \ | |
| 330 | + _NOLIBC_PF_FLAG_NZ(cmp_5) | _NOLIBC_PF_FLAG_NZ(cmp_6) | \ | |
| 331 | + _NOLIBC_PF_FLAG_NZ(cmp_7) | _NOLIBC_PF_FLAG_NZ(cmp_8)) | |
| 332 | +#define _NOLIBC_PF_FLAGS_CONTAIN(flags, ...) \ | |
| 333 | + ((flags) & _NOLIBC_PF_FLAG8(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0)) | |
| 334 | +#define _NOLIBC_PF_CHAR_IS_ONE_OF(ch, cmp_1, ...) \ | |
| 335 | + ((unsigned int)(ch) - (cmp_1 & 0xe0) > 0x1f ? 0 : \ | |
| 336 | + _NOLIBC_PF_FLAGS_CONTAIN(_NOLIBC_PF_FLAG(ch), cmp_1, __VA_ARGS__)) | |
| 337 | + | |
| 338 | +static __attribute__((unused, format(printf, 3, 0))) | |
| 339 | +int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list args) | |
| 303 | 340 | { |
| 304 | − char escape, lpref, c; | |
| 341 | + char ch; | |
| 305 | 342 | unsigned long long v; |
| 306 | − unsigned int written, width; | |
| 307 | − size_t len, ofs, w; | |
| 308 | − char tmpbuf[21]; | |
| 343 | + long long signed_v; | |
| 344 | + int written, width, precision, len; | |
| 345 | + unsigned int flags, ch_flag; | |
| 346 | + char outbuf[2 + 31 + 22 + 1]; | |
| 347 | + char *out; | |
| 309 | 348 | const char *outstr; |
| 349 | + unsigned int sign_prefix; | |
| 350 | + int got_width; | |
| 310 | 351 | |
| 311 | − written = ofs = escape = lpref = 0; | |
| 352 | + written = 0; | |
| 312 | 353 | while (1) { |
| 313 | − c = fmt[ofs++]; | |
| 354 | + outstr = fmt; | |
| 355 | + ch = *fmt++; | |
| 356 | + if (!ch) | |
| 357 | + break; | |
| 358 | + | |
| 314 | 359 | width = 0; |
| 360 | + flags = 0; | |
| 361 | + if (ch != '%') { | |
| 362 | + while (*fmt && *fmt != '%') | |
| 363 | + fmt++; | |
| 364 | + /* Output characters from the format string. */ | |
| 365 | + len = fmt - outstr; | |
| 366 | + goto do_output; | |
| 367 | + } | |
| 315 | 368 | |
| 316 | − if (escape) { | |
| 317 | − /* we're in an escape sequence, ofs == 1 */ | |
| 318 | − escape = 0; | |
| 369 | + /* we're in a format sequence */ | |
| 319 | 370 | |
| 320 | − /* width */ | |
| 321 | − while (c >= '0' && c <= '9') { | |
| 322 | − width *= 10; | |
| 323 | − width += c - '0'; | |
| 371 | + /* Conversion flag characters */ | |
| 372 | + while (1) { | |
| 373 | + ch = *fmt++; | |
| 374 | + ch_flag = _NOLIBC_PF_CHAR_IS_ONE_OF(ch, ' ', '#', '+', '-', '0'); | |
| 375 | + if (!ch_flag) | |
| 376 | + break; | |
| 377 | + flags |= ch_flag; | |
| 378 | + } | |
| 324 | 379 | |
| 325 | − c = fmt[ofs++]; | |
| 380 | + /* Width and precision */ | |
| 381 | + for (got_width = 0;; ch = *fmt++) { | |
| 382 | + if (ch == '*') { | |
| 383 | + precision = va_arg(args, int); | |
| 384 | + ch = *fmt++; | |
| 385 | + } else { | |
| 386 | + for (precision = 0; ch >= '0' && ch <= '9'; ch = *fmt++) | |
| 387 | + precision = precision * 10 + (ch - '0'); | |
| 388 | + } | |
| 389 | + if (got_width) | |
| 390 | + break; | |
| 391 | + width = precision; | |
| 392 | + if (ch != '.') { | |
| 393 | + /* Default precision for strings */ | |
| 394 | + precision = -1; | |
| 395 | + break; | |
| 396 | + } | |
| 397 | + got_width = 1; | |
| 398 | + } | |
| 399 | + /* A negative width (e.g. from "%*s") requests left justify. */ | |
| 400 | + if (width < 0) { | |
| 401 | + width = -width; | |
| 402 | + flags |= _NOLIBC_PF_FLAG('-'); | |
| 403 | + } | |
| 404 | + | |
| 405 | + /* Length modifier. | |
| 406 | + * They miss the conversion flags characters " #+-0" so can go into flags. | |
| 407 | + * Change both L and ll to j (all always 64bit). | |
| 408 | + */ | |
| 409 | + if (ch == 'L') | |
| 410 | + ch = 'j'; | |
| 411 | + ch_flag = _NOLIBC_PF_CHAR_IS_ONE_OF(ch, 'l', 't', 'z', 'j', 'q'); | |
| 412 | + if (ch_flag != 0) { | |
| 413 | + if (ch == 'l' && fmt[0] == 'l') { | |
| 414 | + fmt++; | |
| 415 | + ch_flag = _NOLIBC_PF_FLAG('j'); | |
| 416 | + } | |
| 417 | + flags |= ch_flag; | |
| 418 | + ch = *fmt++; | |
| 419 | + } | |
| 420 | + | |
| 421 | + /* Conversion specifiers. */ | |
| 422 | + | |
| 423 | + /* Numeric and pointer conversion specifiers. | |
| 424 | + * | |
| 425 | + * Use an explicit bound check (rather than _NOLIBC_PF_CHAR_IS_ONE_OF()) | |
| 426 | + * so that 'X' can be allowed through. | |
| 427 | + * 'X' gets treated and 'x' because _NOLIBC_PF_FLAG() returns the same | |
| 428 | + * value for both. | |
| 429 | + * | |
| 430 | + * We need to check for "%p" or "%#x" later, merging here gives better code. | |
| 431 | + * But '#' collides with 'c' so shift right. | |
| 432 | + */ | |
| 433 | + ch_flag = _NOLIBC_PF_FLAG(ch) | (flags & _NOLIBC_PF_FLAG('#')) >> 1; | |
| 434 | + if (((ch >= 'a' && ch <= 'z') || ch == 'X') && | |
| 435 | + _NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'c', 'd', 'i', 'u', 'o', 'x', 'p', 's')) { | |
| 436 | + /* 'long' is needed for pointer/string conversions and ltz lengths. | |
| 437 | + * A single test can be used provided 'p' (the same bit as '0') | |
| 438 | + * is masked from flags. | |
| 439 | + */ | |
| 440 | + if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag | (flags & ~_NOLIBC_PF_FLAG('p')), | |
| 441 | + 'p', 's', 'l', 't', 'z')) { | |
| 442 | + v = va_arg(args, unsigned long); | |
| 443 | + signed_v = (long)v; | |
| 444 | + } else if (_NOLIBC_PF_FLAGS_CONTAIN(flags, 'j', 'q')) { | |
| 445 | + v = va_arg(args, unsigned long long); | |
| 446 | + signed_v = v; | |
| 447 | + } else { | |
| 448 | + v = va_arg(args, unsigned int); | |
| 449 | + signed_v = (int)v; | |
| 450 | + } | |
| 451 | + | |
| 452 | + if (ch == 'c') { | |
| 453 | + /* "%c" - single character. */ | |
| 454 | + outbuf[0] = v; | |
| 455 | + len = 1; | |
| 456 | + outstr = outbuf; | |
| 457 | + goto do_output; | |
| 326 | 458 | } |
| 327 | 459 | |
| 328 | − if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') { | |
| 329 | − char *out = tmpbuf; | |
| 330 | − | |
| 331 | − if (c == 'p') | |
| 332 | − v = va_arg(args, unsigned long); | |
| 333 | − else if (lpref) { | |
| 334 | − if (lpref > 1) | |
| 335 | − v = va_arg(args, unsigned long long); | |
| 336 | − else | |
| 337 | − v = va_arg(args, unsigned long); | |
| 338 | − } else | |
| 339 | − v = va_arg(args, unsigned int); | |
| 340 | − | |
| 341 | − if (c == 'd') { | |
| 342 | − /* sign-extend the value */ | |
| 343 | − if (lpref == 0) | |
| 344 | − v = (long long)(int)v; | |
| 345 | − else if (lpref == 1) | |
| 346 | − v = (long long)(long)v; | |
| 460 | + if (ch == 's') { | |
| 461 | + /* "%s" - character string. */ | |
| 462 | + outstr = (const char *)(uintptr_t)v; | |
| 463 | + if (!outstr) { | |
| 464 | + outstr = "(null)"; | |
| 465 | + /* Match glibc, nothing output if precision too small */ | |
| 466 | + len = precision < 0 || precision >= 6 ? 6 : 0; | |
| 467 | + goto do_output; | |
| 347 | 468 | } |
| 469 | + goto do_strlen_output; | |
| 470 | + } | |
| 348 | 471 | |
| 349 | − switch (c) { | |
| 350 | − case 'c': | |
| 351 | − out[0] = v; | |
| 352 | − out[1] = 0; | |
| 353 | − break; | |
| 354 | − case 'd': | |
| 355 | − i64toa_r(v, out); | |
| 356 | − break; | |
| 357 | − case 'u': | |
| 358 | − u64toa_r(v, out); | |
| 359 | − break; | |
| 360 | − case 'p': | |
| 361 | − *(out++) = '0'; | |
| 362 | − *(out++) = 'x'; | |
| 363 | − __nolibc_fallthrough; | |
| 364 | − default: /* 'x' and 'p' above */ | |
| 365 | − u64toh_r(v, out); | |
| 366 | − break; | |
| 472 | + /* The 'sign_prefix' can be zero, one or two ("0x") characters. | |
| 473 | + * Prepended least significant byte first stopping on a zero byte. | |
| 474 | + */ | |
| 475 | + sign_prefix = 0; | |
| 476 | + | |
| 477 | + if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'd', 'i')) { | |
| 478 | + /* "%d" and "%i" - signed decimal numbers. */ | |
| 479 | + if (signed_v < 0) { | |
| 480 | + sign_prefix = '-'; | |
| 481 | + v = -(signed_v + 1); | |
| 482 | + v++; | |
| 483 | + } else if (_NOLIBC_PF_FLAGS_CONTAIN(flags, '+')) { | |
| 484 | + sign_prefix = '+'; | |
| 485 | + } else if (_NOLIBC_PF_FLAGS_CONTAIN(flags, ' ')) { | |
| 486 | + sign_prefix = ' '; | |
| 367 | 487 | } |
| 368 | − outstr = tmpbuf; | |
| 488 | + } else { | |
| 489 | + /* "#o" requires that the output always starts with a '0'. | |
| 490 | + * This needs another check after any zero padding to avoid | |
| 491 | + * adding an extra leading '0'. | |
| 492 | + */ | |
| 493 | + if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'o') && | |
| 494 | + _NOLIBC_PF_FLAGS_CONTAIN(ch_flag, '#' - 1)) | |
| 495 | + sign_prefix = '0'; | |
| 369 | 496 | } |
| 370 | − else if (c == 's') { | |
| 371 | − outstr = va_arg(args, char *); | |
| 372 | − if (!outstr) | |
| 373 | − outstr="(null)"; | |
| 497 | + | |
| 498 | + /* The value is converted offset into the buffer so that | |
| 499 | + * 31 zero pad characters and the sign/prefix can be added in front. | |
| 500 | + * The longest digit string is 22 + 1 for octal conversions. | |
| 501 | + */ | |
| 502 | + out = outbuf + 2 + 31; | |
| 503 | + | |
| 504 | + if (v == 0) { | |
| 505 | + /* There are special rules for zero. */ | |
| 506 | + if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'p')) { | |
| 507 | + /* "%p" match glibc, precision is ignored */ | |
| 508 | + outstr = "(nil)"; | |
| 509 | + len = 5; | |
| 510 | + goto do_output; | |
| 511 | + } | |
| 512 | + if (!precision) { | |
| 513 | + /* Explicit %nn.0d, no digits output (except for %#.0o) */ | |
| 514 | + len = 0; | |
| 515 | + goto prepend_sign; | |
| 516 | + } | |
| 517 | + /* All other formats (including "%#x") just output "0". */ | |
| 518 | + out[0] = '0'; | |
| 519 | + len = 1; | |
| 520 | + } else { | |
| 521 | + /* Convert the number to ascii in the required base. */ | |
| 522 | + unsigned long long recip; | |
| 523 | + unsigned int base; | |
| 524 | + if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'd', 'i', 'u')) { | |
| 525 | + base = 10; | |
| 526 | + recip = _NOLIBC_U64TOA_RECIP(10); | |
| 527 | + } else if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'o')) { | |
| 528 | + base = 8; | |
| 529 | + recip = _NOLIBC_U64TOA_RECIP(8); | |
| 530 | + } else { | |
| 531 | + base = 16; | |
| 532 | + recip = _NOLIBC_U64TOA_RECIP(16); | |
| 533 | + if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'p', '#' - 1)) { | |
| 534 | + /* "%p" and "%#x" need "0x" prepending. */ | |
| 535 | + sign_prefix = '0' << 8 | 'x'; | |
| 536 | + } | |
| 537 | + } | |
| 538 | + len = _nolibc_u64toa_base(v, out, base, recip); | |
| 374 | 539 | } |
| 375 | − else if (c == 'm') { | |
| 376 | −#ifdef NOLIBC_IGNORE_ERRNO | |
| 377 | − outstr = "unknown error"; | |
| 378 | −#else | |
| 379 | − outstr = strerror(errno); | |
| 380 | −#endif /* NOLIBC_IGNORE_ERRNO */ | |
| 540 | + | |
| 541 | + /* Add zero padding */ | |
| 542 | + if (precision < 0) { | |
| 543 | + /* No explicit precision (or negative from "%.*s"). */ | |
| 544 | + if (!_NOLIBC_PF_FLAGS_CONTAIN(flags, '0')) | |
| 545 | + goto no_zero_padding; | |
| 546 | + if (_NOLIBC_PF_FLAGS_CONTAIN(flags, '-')) | |
| 547 | + /* Left justify overrides zero pad */ | |
| 548 | + goto no_zero_padding; | |
| 549 | + /* eg "%05d", Zero pad to field width less sign. | |
| 550 | + * Note that precision can end up negative so all | |
| 551 | + * the variables have to be 'signed int'. | |
| 552 | + */ | |
| 553 | + precision = width; | |
| 554 | + if (sign_prefix) { | |
| 555 | + precision--; | |
| 556 | + if (sign_prefix >= 256) | |
| 557 | + precision--; | |
| 558 | + } | |
| 381 | 559 | } |
| 382 | − else if (c == '%') { | |
| 383 | − /* queue it verbatim */ | |
| 384 | − continue; | |
| 560 | + if (precision > 31) | |
| 561 | + /* Don't run off the start of outbuf[], arbitrary limit | |
| 562 | + * longer than the longest number field. */ | |
| 563 | + precision = 31; | |
| 564 | + for (; len < precision; len++) { | |
| 565 | + /* Stop gcc generating horrid code and memset(). */ | |
| 566 | + _NOLIBC_OPTIMIZER_HIDE_VAR(len); | |
| 567 | + *--out = '0'; | |
| 385 | 568 | } |
| 386 | − else { | |
| 387 | − /* modifiers or final 0 */ | |
| 388 | − if (c == 'l') { | |
| 389 | − /* long format prefix, maintain the escape */ | |
| 390 | − lpref++; | |
| 391 | − } else if (c == 'j') { | |
| 392 | − lpref = 2; | |
| 569 | +no_zero_padding: | |
| 570 | + | |
| 571 | + /* %#o has set sign_prefix to '0', but we don't want so add an extra | |
| 572 | + * leading zero here. | |
| 573 | + * Since the only other byte values of sign_prefix are ' ', '+' and '-' | |
| 574 | + * it is enough to check that out[] doesn't already start with sign_prefix. | |
| 575 | + */ | |
| 576 | + if (sign_prefix - *out) { | |
| 577 | +prepend_sign: | |
| 578 | + /* Add the 0, 1 or 2 ("0x") sign/prefix characters at the front. */ | |
| 579 | + for (; sign_prefix; sign_prefix >>= 8) { | |
| 580 | + /* Force gcc to increment len inside the loop. */ | |
| 581 | + _NOLIBC_OPTIMIZER_HIDE_VAR(len); | |
| 582 | + len++; | |
| 583 | + *--out = sign_prefix; | |
| 393 | 584 | } |
| 394 | − escape = 1; | |
| 395 | − goto do_escape; | |
| 396 | 585 | } |
| 397 | − len = strlen(outstr); | |
| 398 | − goto flush_str; | |
| 586 | + outstr = out; | |
| 587 | + goto do_output; | |
| 399 | 588 | } |
| 400 | 589 | |
| 401 | − /* not an escape sequence */ | |
| 402 | − if (c == 0 || c == '%') { | |
| 403 | − /* flush pending data on escape or end */ | |
| 404 | − escape = 1; | |
| 405 | − lpref = 0; | |
| 406 | − outstr = fmt; | |
| 407 | − len = ofs - 1; | |
| 408 | − flush_str: | |
| 409 | − if (n) { | |
| 410 | − w = len < n ? len : n; | |
| 411 | − n -= w; | |
| 412 | − while (width-- > w) { | |
| 413 | − if (cb(state, " ", 1) != 0) | |
| 414 | − return -1; | |
| 415 | − written += 1; | |
| 416 | − } | |
| 417 | − if (cb(state, outstr, w) != 0) | |
| 418 | − return -1; | |
| 419 | − } | |
| 590 | + if (ch == 'm') { | |
| 591 | +#ifdef NOLIBC_IGNORE_ERRNO | |
| 592 | + outstr = "unknown error"; | |
| 593 | +#else | |
| 594 | + outstr = strerror(errno); | |
| 595 | +#endif /* NOLIBC_IGNORE_ERRNO */ | |
| 596 | + goto do_strlen_output; | |
| 597 | + } | |
| 420 | 598 | |
| 421 | − written += len; | |
| 422 | − do_escape: | |
| 423 | − if (c == 0) | |
| 424 | − break; | |
| 425 | − fmt += ofs; | |
| 426 | − ofs = 0; | |
| 427 | − continue; | |
| 599 | + if (ch != '%') { | |
| 600 | + /* Invalid format: back up to output the format characters */ | |
| 601 | + fmt = outstr + 1; | |
| 602 | + /* and output a '%' now. */ | |
| 428 | 603 | } |
| 604 | + /* %% is documented as a 'conversion specifier'. | |
| 605 | + * Any flags, precision or length modifier are ignored. | |
| 606 | + */ | |
| 607 | + len = 1; | |
| 608 | + width = 0; | |
| 609 | + outstr = fmt - 1; | |
| 610 | + goto do_output; | |
| 611 | + | |
| 612 | +do_strlen_output: | |
| 613 | + /* Open coded strnlen() (slightly smaller). */ | |
| 614 | + for (len = 0; precision < 0 || len < precision; len++) | |
| 615 | + if (!outstr[len]) | |
| 616 | + break; | |
| 429 | 617 | |
| 430 | − /* literal char, just queue it */ | |
| 618 | +do_output: | |
| 619 | + written += len; | |
| 620 | + | |
| 621 | + /* Stop gcc back-merging this code into one of the conditionals above. */ | |
| 622 | + _NOLIBC_OPTIMIZER_HIDE_VAR(len); | |
| 623 | + | |
| 624 | + /* Output the characters on the required side of any padding. */ | |
| 625 | + width -= len; | |
| 626 | + flags = _NOLIBC_PF_FLAGS_CONTAIN(flags, '-'); | |
| 627 | + if (flags && cb(state, outstr, len) != 0) | |
| 628 | + return -1; | |
| 629 | + while (width > 0) { | |
| 630 | + /* Output pad in 16 byte blocks with the small block first. */ | |
| 631 | + int pad_len = ((width - 1) & 15) + 1; | |
| 632 | + width -= pad_len; | |
| 633 | + written += pad_len; | |
| 634 | + if (cb(state, " ", pad_len) != 0) | |
| 635 | + return -1; | |
| 636 | + } | |
| 637 | + if (!flags && cb(state, outstr, len) != 0) | |
| 638 | + return -1; | |
| 431 | 639 | } |
| 640 | + | |
| 641 | + /* Request a final '\0' be added to the snprintf() output. | |
| 642 | + * This may be the only call of the cb() function. | |
| 643 | + */ | |
| 644 | + if (cb(state, NULL, 0) != 0) | |
| 645 | + return -1; | |
| 646 | + | |
| 432 | 647 | return written; |
| 433 | 648 | } |
| 434 | 649 | |
| 435 | −static int __nolibc_fprintf_cb(intptr_t state, const char *buf, size_t size) | |
| 650 | +static int __nolibc_fprintf_cb(void *stream, const char *buf, size_t size) | |
| 436 | 651 | { |
| 437 | − return _fwrite(buf, size, (FILE *)state); | |
| 652 | + return _fwrite(buf, size, stream); | |
| 438 | 653 | } |
| 439 | 654 | |
| 440 | 655 | static __attribute__((unused, format(printf, 2, 0))) |
| 441 | 656 | int vfprintf(FILE *stream, const char *fmt, va_list args) |
| 442 | 657 | { |
| 443 | − return __nolibc_printf(__nolibc_fprintf_cb, (intptr_t)stream, SIZE_MAX, fmt, args); | |
| 658 | + return __nolibc_printf(__nolibc_fprintf_cb, stream, fmt, args); | |
| 444 | 659 | } |
| 445 | 660 | |
| 446 | 661 | static __attribute__((unused, format(printf, 1, 0))) |
| @@ -498,26 +713,54 @@ int dprintf(int fd, const char *fmt, ...) · 51 unmodified lines | ||
| 498 | 713 | return ret; |
| 499 | 714 | } |
| 500 | 715 | |
| 501 | −static int __nolibc_sprintf_cb(intptr_t _state, const char *buf, size_t size) | |
| 716 | +struct __nolibc_sprintf_cb_state { | |
| 717 | + char *buf; | |
| 718 | + size_t space; | |
| 719 | +}; | |
| 720 | + | |
| 721 | +static int __nolibc_sprintf_cb(void *v_state, const char *buf, size_t size) | |
| 502 | 722 | { |
| 503 | − char **state = (char **)_state; | |
| 723 | + struct __nolibc_sprintf_cb_state *state = v_state; | |
| 724 | + size_t space = state->space; | |
| 725 | + char *tgt; | |
| 726 | + | |
| 727 | + /* Truncate the request to fit in the output buffer space. | |
| 728 | + * The last byte is reserved for the terminating '\0'. | |
| 729 | + * state->space can only be zero for snprintf(NULL, 0, fmt, args) | |
| 730 | + * so this normally lets through calls with 'size == 0'. | |
| 731 | + */ | |
| 732 | + if (size >= space) { | |
| 733 | + if (space <= 1) | |
| 734 | + return 0; | |
| 735 | + size = space - 1; | |
| 736 | + } | |
| 737 | + tgt = state->buf; | |
| 738 | + | |
| 739 | + /* __nolibc_printf() ends with cb(state, NULL, 0) to request the output | |
| 740 | + * buffer be '\0' terminated. | |
| 741 | + * That will be the only cb() call for, eg, snprintf(buf, sz, ""). | |
| 742 | + * Zero lengths can occur at other times (eg "%s" for an empty string). | |
| 743 | + * Unconditionally write the '\0' byte to reduce code size, it is | |
| 744 | + * normally overwritten by the data being output. | |
| 745 | + * There is no point adding a '\0' after copied data - there is always | |
| 746 | + * another call. | |
| 747 | + */ | |
| 748 | + *tgt = '\0'; | |
| 749 | + if (size) { | |
| 750 | + state->space = space - size; | |
| 751 | + state->buf = tgt + size; | |
| 752 | + memcpy(tgt, buf, size); | |
| 753 | + } | |
| 504 | 754 | |
| 505 | − memcpy(*state, buf, size); | |
| 506 | − *state += size; | |
| 507 | 755 | return 0; |
| 508 | 756 | } |
| 509 | 757 | |
| 510 | 758 | static __attribute__((unused, format(printf, 3, 0))) |
| 511 | 759 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
| 512 | 760 | { |
| 513 | − char *state = buf; | |
| 514 | − int ret; | |
| 761 | + struct __nolibc_sprintf_cb_state state = { .buf = buf, .space = size }; | |
| 515 | 762 | |
| 516 | − ret = __nolibc_printf(__nolibc_sprintf_cb, (intptr_t)&state, size, fmt, args); | |
| 517 | − if (ret < 0) | |
| 518 | − return ret; | |
| 519 | − buf[(size_t)ret < size ? (size_t)ret : size - 1] = '\0'; | |
| 520 | − return ret; | |
| 763 | + return __nolibc_printf(__nolibc_sprintf_cb, &state, fmt, args); | |
| 521 | 764 | } |
| 522 | 765 | |
| 523 | 766 | static __attribute__((unused, format(printf, 3, 4))) |
| @@ -552,6 +795,56 @@ int sprintf(char *buf, const char *fmt, ...) · 28 unmodified lines | ||
| 552 | 795 | return ret; |
| 553 | 796 | } |
| 554 | 797 | |
| 798 | +static __attribute__((unused, format(printf, 2, 0))) | |
| 799 | +int __nolibc_vasprintf(char **strp, const char *fmt, va_list args1, va_list args2) | |
| 800 | +{ | |
| 801 | + int len1, len2; | |
| 802 | + char *buf; | |
| 803 | + | |
| 804 | + len1 = vsnprintf(NULL, 0, fmt, args1); | |
| 805 | + if (len1 < 0) | |
| 806 | + return -1; | |
| 807 | + | |
| 808 | + buf = malloc(len1 + 1); | |
| 809 | + if (!buf) | |
| 810 | + return -1; | |
| 811 | + | |
| 812 | + len2 = vsnprintf(buf, len1 + 1, fmt, args2); | |
| 813 | + if (len2 < 0) { | |
| 814 | + free(buf); | |
| 815 | + return -1; | |
| 816 | + } | |
| 817 | + | |
| 818 | + *strp = buf; | |
| 819 | + return len1; | |
| 820 | +} | |
| 821 | + | |
| 822 | +static __attribute__((unused, format(printf, 2, 0))) | |
| 823 | +int vasprintf(char **strp, const char *fmt, va_list args) | |
| 824 | +{ | |
| 825 | + va_list args2; | |
| 826 | + int ret; | |
| 827 | + | |
| 828 | + va_copy(args2, args); | |
| 829 | + ret = __nolibc_vasprintf(strp, fmt, args, args2); | |
| 830 | + va_end(args2); | |
| 831 | + | |
| 832 | + return ret; | |
| 833 | +} | |
| 834 | + | |
| 835 | +static __attribute__((unused, format(printf, 2, 3))) | |
| 836 | +int asprintf(char **strp, const char *fmt, ...) | |
| 837 | +{ | |
| 838 | + va_list args; | |
| 839 | + int ret; | |
| 840 | + | |
| 841 | + va_start(args, fmt); | |
| 842 | + ret = vasprintf(strp, fmt, args); | |
| 843 | + va_end(args); | |
| 844 | + | |
| 845 | + return ret; | |
| 846 | +} | |
| 847 | + | |
| 555 | 848 | static __attribute__((unused)) |
| 556 | 849 | int vsscanf(const char *str, const char *format, va_list args) |
| 557 | 850 | { |
| @@ -683,13 +976,29 @@ int setvbuf(FILE *stream __attribute__((unused)), · 125 unmodified lines | ||
| 683 | 976 | } |
| 684 | 977 | |
| 685 | 978 | static __attribute__((unused)) |
| 686 | −const char *strerror(int errno) | |
| 979 | +int strerror_r(int errnum, char *buf, size_t buflen) | |
| 980 | +{ | |
| 981 | + if (buflen < 18) | |
| 982 | + return ERANGE; | |
| 983 | + | |
| 984 | + __builtin_memcpy(buf, "errno=", 6); | |
| 985 | + i64toa_r(errnum, buf + 6); | |
| 986 | + return 0; | |
| 987 | +} | |
| 988 | + | |
| 989 | +static __attribute__((unused)) | |
| 990 | +const char *strerror(int errnum) | |
| 687 | 991 | { |
| 688 | − static char buf[18] = "errno="; | |
| 992 | + static char buf[18]; | |
| 993 | + char *b = buf; | |
| 994 | + | |
| 995 | + /* Force gcc to use 'register offset' to access buf[]. */ | |
| 996 | + _NOLIBC_OPTIMIZER_HIDE_VAR(b); | |
| 689 | 997 | |
| 690 | − i64toa_r(errno, &buf[6]); | |
| 998 | + /* Use strerror_r() to avoid having the only .data in small programs. */ | |
| 999 | + strerror_r(errnum, b, sizeof(buf)); | |
| 691 | 1000 | |
| 692 | − return buf; | |
| 1001 | + return b; | |
| 693 | 1002 | } |
| 694 | 1003 | |
| 695 | 1004 | #endif /* _NOLIBC_STDIO_H */ |
| @@ -55,7 +55,7 @@ void abort(void); · 54 unmodified lines | ||
| 55 | 55 | __attribute__((weak,unused,noreturn,section(".text.nolibc_abort"))) |
| 56 | 56 | void abort(void) |
| 57 | 57 | { |
| 58 | − sys_kill(sys_getpid(), SIGABRT); | |
| 58 | + _sys_kill(_sys_getpid(), SIGABRT); | |
| 59 | 59 | for (;;); |
| 60 | 60 | } |
| 61 | 61 | |
| @@ -145,9 +145,9 @@ void *malloc(size_t len) · 83 unmodified lines | ||
| 145 | 145 | static __attribute__((unused)) |
| 146 | 146 | void *calloc(size_t size, size_t nmemb) |
| 147 | 147 | { |
| 148 | − size_t x = size * nmemb; | |
| 148 | + size_t x; | |
| 149 | 149 | |
| 150 | − if (__builtin_expect(size && ((x / size) != nmemb), 0)) { | |
| 150 | + if (__builtin_expect(__builtin_mul_overflow(size, nmemb, &x), 0)) { | |
| 151 | 151 | SET_ERRNO(ENOMEM); |
| 152 | 152 | return NULL; |
| 153 | 153 | } |
| @@ -188,36 +188,91 @@ void *realloc(void *old_ptr, size_t new_size) · 34 unmodified lines | ||
| 188 | 188 | return ret; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | −/* Converts the unsigned long integer <in> to its hex representation into | |
| 191 | +/* Converts the unsigned 64bit integer <in> to base <base> ascii into | |
| 192 | 192 | * buffer <buffer>, which must be long enough to store the number and the |
| 193 | − * trailing zero (17 bytes for "ffffffffffffffff" or 9 for "ffffffff"). The | |
| 194 | − * buffer is filled from the first byte, and the number of characters emitted | |
| 195 | − * (not counting the trailing zero) is returned. The function is constructed | |
| 196 | − * in a way to optimize the code size and avoid any divide that could add a | |
| 197 | − * dependency on large external functions. | |
| 193 | + * trailing zero. The buffer is filled from the first byte, and the number | |
| 194 | + * of characters emitted (not counting the trailing zero) is returned. | |
| 195 | + * The function uses 'multiply by reciprocal' for the divisions and | |
| 196 | + * requires the caller pass the correct reciprocal. | |
| 197 | + * | |
| 198 | + * Note that unlike __div64_const32() in asm-generic/div64.h there isn't | |
| 199 | + * an extra shift done (by ___p), the reciprocal has to be lower resulting | |
| 200 | + * in a slightly low quotient. | |
| 201 | + * Keep things simple by correcting for the error. | |
| 202 | + * This also saves calculating the 'low * low' product (e2 below) which is | |
| 203 | + * very unlikely to be significant. | |
| 204 | + * | |
| 205 | + * Some maths: | |
| 206 | + * recip = p2 / base - e1; // With e1 < base. | |
| 207 | + * q = (recip * in - e2) / p2; // With e2 < p2. | |
| 208 | + * = base / in - (e1 * in + e2) / p2; | |
| 209 | + * > base / in - (e1 * p2 + p2) / p2; | |
| 210 | + * = base / in - ((e1 + 1) * p2) / p2; | |
| 211 | + * > base / in - base; | |
| 212 | + * So the maximum error is less than 'base'. | |
| 213 | + * Hence the largest possible digit is '2 * base - 1'. | |
| 214 | + * For base 10 e1 is 6 and you can get digits of 15 (eg from 2**64-1). | |
| 215 | + * Error e1 is largest for a base that is a factor of 2**64+1, the smallest is 274177 | |
| 216 | + * and converting 2**42-1 in base 274177 does generate a digit of 274177+274175. | |
| 217 | + * This all means only a single correction is needed rather than a loop. | |
| 218 | + * | |
| 219 | + * __int128 isn't used for mips because gcc prior to 10.0 will call | |
| 220 | + * __multi3 for MIPS64r6. The same also happens for SPARC and clang. | |
| 198 | 221 | */ |
| 199 | −static __attribute__((unused)) | |
| 200 | −int utoh_r(unsigned long in, char *buffer) | |
| 222 | +#define _NOLIBC_U64TOA_RECIP(base) ((base) & 1 ? ~0ull / (base) : (1ull << 63) / ((base) / 2)) | |
| 223 | +static __attribute__((unused, noinline)) | |
| 224 | +int _nolibc_u64toa_base(uint64_t in, char *buffer, unsigned int base, uint64_t recip) | |
| 201 | 225 | { |
| 202 | − signed char pos = (~0UL > 0xfffffffful) ? 60 : 28; | |
| 203 | − int digits = 0; | |
| 204 | − int dig; | |
| 226 | + unsigned int digits = 0; | |
| 227 | + unsigned int dig; | |
| 228 | + uint64_t q; | |
| 229 | + char *p; | |
| 205 | 230 | |
| 231 | + /* Generate least significant digit first */ | |
| 206 | 232 | do { |
| 207 | − dig = in >> pos; | |
| 208 | − in -= (uint64_t)dig << pos; | |
| 209 | − pos -= 4; | |
| 210 | − if (dig || digits || pos < 0) { | |
| 211 | − if (dig > 9) | |
| 212 | − dig += 'a' - '0' - 10; | |
| 213 | − buffer[digits++] = '0' + dig; | |
| 233 | +#if defined(__SIZEOF_INT128__) && !defined(__mips__) && !defined(__sparc__) | |
| 234 | + q = ((unsigned __int128)in * recip) >> 64; | |
| 235 | +#else | |
| 236 | + uint64_t p = (uint32_t)in * (recip >> 32); | |
| 237 | + q = (in >> 32) * (recip >> 32) + (p >> 32); | |
| 238 | + p = (uint32_t)p + (in >> 32) * (uint32_t)recip; | |
| 239 | + q += p >> 32; | |
| 240 | +#endif | |
| 241 | + dig = in - q * base; | |
| 242 | + /* Correct for any rounding errors */ | |
| 243 | + if (dig >= base) { | |
| 244 | + dig -= base; | |
| 245 | + q++; | |
| 214 | 246 | } |
| 215 | − } while (pos >= 0); | |
| 247 | + if (dig > 9) | |
| 248 | + dig += 'a' - '0' - 10; | |
| 249 | + buffer[digits++] = '0' + dig; | |
| 250 | + } while ((in = q)); | |
| 216 | 251 | |
| 217 | 252 | buffer[digits] = 0; |
| 253 | + | |
| 254 | + /* Order reverse to result */ | |
| 255 | + for (p = buffer + digits - 1; p > buffer; buffer++, p--) { | |
| 256 | + dig = *buffer; | |
| 257 | + *buffer = *p; | |
| 258 | + *p = dig; | |
| 259 | + } | |
| 260 | + | |
| 218 | 261 | return digits; |
| 219 | 262 | } |
| 220 | 263 | |
| 264 | +/* Converts the unsigned long integer <in> to its hex representation into | |
| 265 | + * buffer <buffer>, which must be long enough to store the number and the | |
| 266 | + * trailing zero (17 bytes for "ffffffffffffffff" or 9 for "ffffffff"). The | |
| 267 | + * buffer is filled from the first byte, and the number of characters emitted | |
| 268 | + * (not counting the trailing zero) is returned. | |
| 269 | + */ | |
| 270 | +static __inline__ __attribute__((unused)) | |
| 271 | +int utoh_r(unsigned long in, char *buffer) | |
| 272 | +{ | |
| 273 | + return _nolibc_u64toa_base(in, buffer, 16, _NOLIBC_U64TOA_RECIP(16)); | |
| 274 | +} | |
| 275 | + | |
| 221 | 276 | /* converts unsigned long <in> to an hex string using the static itoa_buffer |
| 222 | 277 | * and returns the pointer to that string. |
| 223 | 278 | */ |
| @@ -233,30 +288,11 @@ char *utoh(unsigned long in) · 9 unmodified lines | ||
| 233 | 288 | * trailing zero (21 bytes for 18446744073709551615 in 64-bit, 11 for |
| 234 | 289 | * 4294967295 in 32-bit). The buffer is filled from the first byte, and the |
| 235 | 290 | * number of characters emitted (not counting the trailing zero) is returned. |
| 236 | − * The function is constructed in a way to optimize the code size and avoid | |
| 237 | − * any divide that could add a dependency on large external functions. | |
| 238 | 291 | */ |
| 239 | −static __attribute__((unused)) | |
| 292 | +static __inline__ __attribute__((unused)) | |
| 240 | 293 | int utoa_r(unsigned long in, char *buffer) |
| 241 | 294 | { |
| 242 | − unsigned long lim; | |
| 243 | − int digits = 0; | |
| 244 | − int pos = (~0UL > 0xfffffffful) ? 19 : 9; | |
| 245 | − int dig; | |
| 246 | − | |
| 247 | − do { | |
| 248 | − for (dig = 0, lim = 1; dig < pos; dig++) | |
| 249 | − lim *= 10; | |
| 250 | − | |
| 251 | − if (digits || in >= lim || !pos) { | |
| 252 | − for (dig = 0; in >= lim; dig++) | |
| 253 | − in -= lim; | |
| 254 | − buffer[digits++] = '0' + dig; | |
| 255 | − } | |
| 256 | − } while (pos--); | |
| 257 | − | |
| 258 | − buffer[digits] = 0; | |
| 259 | − return digits; | |
| 295 | + return _nolibc_u64toa_base(in, buffer, 10, _NOLIBC_U64TOA_RECIP(10)); | |
| 260 | 296 | } |
| 261 | 297 | |
| 262 | 298 | /* Converts the signed long integer <in> to its string representation into |
| @@ -324,34 +360,12 @@ char *utoa(unsigned long in) · 61 unmodified lines | ||
| 324 | 360 | * buffer <buffer>, which must be long enough to store the number and the |
| 325 | 361 | * trailing zero (17 bytes for "ffffffffffffffff"). The buffer is filled from |
| 326 | 362 | * the first byte, and the number of characters emitted (not counting the |
| 327 | − * trailing zero) is returned. The function is constructed in a way to optimize | |
| 328 | − * the code size and avoid any divide that could add a dependency on large | |
| 329 | − * external functions. | |
| 363 | + * trailing zero) is returned. | |
| 330 | 364 | */ |
| 331 | −static __attribute__((unused)) | |
| 365 | +static __inline__ __attribute__((unused)) | |
| 332 | 366 | int u64toh_r(uint64_t in, char *buffer) |
| 333 | 367 | { |
| 334 | − signed char pos = 60; | |
| 335 | − int digits = 0; | |
| 336 | − int dig; | |
| 337 | − | |
| 338 | − do { | |
| 339 | − if (sizeof(long) >= 8) { | |
| 340 | − dig = (in >> pos) & 0xF; | |
| 341 | − } else { | |
| 342 | − /* 32-bit platforms: avoid a 64-bit shift */ | |
| 343 | − uint32_t d = (pos >= 32) ? (in >> 32) : in; | |
| 344 | − dig = (d >> (pos & 31)) & 0xF; | |
| 345 | − } | |
| 346 | − if (dig > 9) | |
| 347 | − dig += 'a' - '0' - 10; | |
| 348 | − pos -= 4; | |
| 349 | − if (dig || digits || pos < 0) | |
| 350 | − buffer[digits++] = '0' + dig; | |
| 351 | − } while (pos >= 0); | |
| 352 | − | |
| 353 | − buffer[digits] = 0; | |
| 354 | − return digits; | |
| 368 | + return _nolibc_u64toa_base(in, buffer, 16, _NOLIBC_U64TOA_RECIP(16)); | |
| 355 | 369 | } |
| 356 | 370 | |
| 357 | 371 | /* converts uint64_t <in> to an hex string using the static itoa_buffer and |
| @@ -368,31 +382,12 @@ char *u64toh(uint64_t in) · 10 unmodified lines | ||
| 368 | 382 | * buffer <buffer>, which must be long enough to store the number and the |
| 369 | 383 | * trailing zero (21 bytes for 18446744073709551615). The buffer is filled from |
| 370 | 384 | * the first byte, and the number of characters emitted (not counting the |
| 371 | − * trailing zero) is returned. The function is constructed in a way to optimize | |
| 372 | − * the code size and avoid any divide that could add a dependency on large | |
| 373 | − * external functions. | |
| 385 | + * trailing zero) is returned. | |
| 374 | 386 | */ |
| 375 | −static __attribute__((unused)) | |
| 387 | +static __inline__ __attribute__((unused)) | |
| 376 | 388 | int u64toa_r(uint64_t in, char *buffer) |
| 377 | 389 | { |
| 378 | − unsigned long long lim; | |
| 379 | − int digits = 0; | |
| 380 | − int pos = 19; /* start with the highest possible digit */ | |
| 381 | − int dig; | |
| 382 | − | |
| 383 | − do { | |
| 384 | − for (dig = 0, lim = 1; dig < pos; dig++) | |
| 385 | − lim *= 10; | |
| 386 | − | |
| 387 | − if (digits || in >= lim || !pos) { | |
| 388 | − for (dig = 0; in >= lim; dig++) | |
| 389 | − in -= lim; | |
| 390 | − buffer[digits++] = '0' + dig; | |
| 391 | − } | |
| 392 | − } while (pos--); | |
| 393 | − | |
| 394 | − buffer[digits] = 0; | |
| 395 | − return digits; | |
| 390 | + return _nolibc_u64toa_base(in, buffer, 10, _NOLIBC_U64TOA_RECIP(10)); | |
| 396 | 391 | } |
| 397 | 392 | |
| 398 | 393 | /* Converts the signed 64-bit integer <in> to its string representation into |
| @@ -63,7 +63,7 @@ static __inline__ int __nolibc_enosys(const char *syscall, ...) · 62 unmodified lines | ||
| 63 | 63 | * - the "internal" ones, which matches the raw syscall interface at the |
| 64 | 64 | * kernel level, which may sometimes slightly differ from the documented |
| 65 | 65 | * libc-level ones. For example most of them return either a valid value |
| 66 | − * or -errno. All of these are prefixed with "sys_". They may be called | |
| 66 | + * or -errno. All of these are prefixed with "_sys_". They may be called | |
| 67 | 67 | * by non-portable applications if desired. |
| 68 | 68 | * |
| 69 | 69 | * - the "exported" ones, whose interface must closely match the one |
| @@ -85,15 +85,15 @@ static __inline__ int __nolibc_enosys(const char *syscall, ...) · 15 unmodified lines | ||
| 85 | 85 | */ |
| 86 | 86 | |
| 87 | 87 | static __attribute__((unused)) |
| 88 | −void *sys_brk(void *addr) | |
| 88 | +void *_sys_brk(void *addr) | |
| 89 | 89 | { |
| 90 | − return (void *)my_syscall1(__NR_brk, addr); | |
| 90 | + return (void *)__nolibc_syscall1(__NR_brk, addr); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | static __attribute__((unused)) |
| 94 | 94 | int brk(void *addr) |
| 95 | 95 | { |
| 96 | − void *ret = sys_brk(addr); | |
| 96 | + void *ret = _sys_brk(addr); | |
| 97 | 97 | |
| 98 | 98 | if (!ret) { |
| 99 | 99 | SET_ERRNO(ENOMEM); |
| @@ -106,9 +106,9 @@ static __attribute__((unused)) · 6 unmodified lines | ||
| 106 | 106 | void *sbrk(intptr_t inc) |
| 107 | 107 | { |
| 108 | 108 | /* first call to find current end */ |
| 109 | − void *ret = sys_brk(NULL); | |
| 109 | + void *ret = _sys_brk(NULL); | |
| 110 | 110 | |
| 111 | − if (ret && sys_brk(ret + inc) == ret + inc) | |
| 111 | + if (ret && _sys_brk(ret + inc) == ret + inc) | |
| 112 | 112 | return ret + inc; |
| 113 | 113 | |
| 114 | 114 | SET_ERRNO(ENOMEM); |
| @@ -122,27 +122,27 @@ void *sbrk(intptr_t inc) · 7 unmodified lines | ||
| 122 | 122 | */ |
| 123 | 123 | |
| 124 | 124 | static __attribute__((unused)) |
| 125 | −int sys_chdir(const char *path) | |
| 125 | +int _sys_chdir(const char *path) | |
| 126 | 126 | { |
| 127 | − return my_syscall1(__NR_chdir, path); | |
| 127 | + return __nolibc_syscall1(__NR_chdir, path); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | static __attribute__((unused)) |
| 131 | 131 | int chdir(const char *path) |
| 132 | 132 | { |
| 133 | − return __sysret(sys_chdir(path)); | |
| 133 | + return __sysret(_sys_chdir(path)); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | static __attribute__((unused)) |
| 137 | −int sys_fchdir(int fildes) | |
| 137 | +int _sys_fchdir(int fildes) | |
| 138 | 138 | { |
| 139 | − return my_syscall1(__NR_fchdir, fildes); | |
| 139 | + return __nolibc_syscall1(__NR_fchdir, fildes); | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | static __attribute__((unused)) |
| 143 | 143 | int fchdir(int fildes) |
| 144 | 144 | { |
| 145 | − return __sysret(sys_fchdir(fildes)); | |
| 145 | + return __sysret(_sys_fchdir(fildes)); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
| @@ -151,19 +151,19 @@ int fchdir(int fildes) · 2 unmodified lines | ||
| 151 | 151 | */ |
| 152 | 152 | |
| 153 | 153 | static __attribute__((unused)) |
| 154 | −int sys_chmod(const char *path, mode_t mode) | |
| 154 | +int _sys_chmod(const char *path, mode_t mode) | |
| 155 | 155 | { |
| 156 | 156 | #if defined(__NR_fchmodat) |
| 157 | − return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0); | |
| 157 | + return __nolibc_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0); | |
| 158 | 158 | #else |
| 159 | − return my_syscall2(__NR_chmod, path, mode); | |
| 159 | + return __nolibc_syscall2(__NR_chmod, path, mode); | |
| 160 | 160 | #endif |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | static __attribute__((unused)) |
| 164 | 164 | int chmod(const char *path, mode_t mode) |
| 165 | 165 | { |
| 166 | − return __sysret(sys_chmod(path, mode)); | |
| 166 | + return __sysret(_sys_chmod(path, mode)); | |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
| @@ -172,19 +172,19 @@ int chmod(const char *path, mode_t mode) · 2 unmodified lines | ||
| 172 | 172 | */ |
| 173 | 173 | |
| 174 | 174 | static __attribute__((unused)) |
| 175 | −int sys_chown(const char *path, uid_t owner, gid_t group) | |
| 175 | +int _sys_chown(const char *path, uid_t owner, gid_t group) | |
| 176 | 176 | { |
| 177 | 177 | #if defined(__NR_fchownat) |
| 178 | − return my_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0); | |
| 178 | + return __nolibc_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0); | |
| 179 | 179 | #else |
| 180 | − return my_syscall3(__NR_chown, path, owner, group); | |
| 180 | + return __nolibc_syscall3(__NR_chown, path, owner, group); | |
| 181 | 181 | #endif |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | static __attribute__((unused)) |
| 185 | 185 | int chown(const char *path, uid_t owner, gid_t group) |
| 186 | 186 | { |
| 187 | − return __sysret(sys_chown(path, owner, group)); | |
| 187 | + return __sysret(_sys_chown(path, owner, group)); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
| @@ -193,15 +193,15 @@ int chown(const char *path, uid_t owner, gid_t group) · 2 unmodified lines | ||
| 193 | 193 | */ |
| 194 | 194 | |
| 195 | 195 | static __attribute__((unused)) |
| 196 | −int sys_chroot(const char *path) | |
| 196 | +int _sys_chroot(const char *path) | |
| 197 | 197 | { |
| 198 | − return my_syscall1(__NR_chroot, path); | |
| 198 | + return __nolibc_syscall1(__NR_chroot, path); | |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | static __attribute__((unused)) |
| 202 | 202 | int chroot(const char *path) |
| 203 | 203 | { |
| 204 | − return __sysret(sys_chroot(path)); | |
| 204 | + return __sysret(_sys_chroot(path)); | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
| @@ -210,15 +210,15 @@ int chroot(const char *path) · 2 unmodified lines | ||
| 210 | 210 | */ |
| 211 | 211 | |
| 212 | 212 | static __attribute__((unused)) |
| 213 | −int sys_close(int fd) | |
| 213 | +int _sys_close(int fd) | |
| 214 | 214 | { |
| 215 | − return my_syscall1(__NR_close, fd); | |
| 215 | + return __nolibc_syscall1(__NR_close, fd); | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | static __attribute__((unused)) |
| 219 | 219 | int close(int fd) |
| 220 | 220 | { |
| 221 | − return __sysret(sys_close(fd)); | |
| 221 | + return __sysret(_sys_close(fd)); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
| @@ -227,15 +227,15 @@ int close(int fd) · 2 unmodified lines | ||
| 227 | 227 | */ |
| 228 | 228 | |
| 229 | 229 | static __attribute__((unused)) |
| 230 | −int sys_dup(int fd) | |
| 230 | +int _sys_dup(int fd) | |
| 231 | 231 | { |
| 232 | − return my_syscall1(__NR_dup, fd); | |
| 232 | + return __nolibc_syscall1(__NR_dup, fd); | |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | static __attribute__((unused)) |
| 236 | 236 | int dup(int fd) |
| 237 | 237 | { |
| 238 | − return __sysret(sys_dup(fd)); | |
| 238 | + return __sysret(_sys_dup(fd)); | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
| @@ -244,7 +244,7 @@ int dup(int fd) · 2 unmodified lines | ||
| 244 | 244 | */ |
| 245 | 245 | |
| 246 | 246 | static __attribute__((unused)) |
| 247 | −int sys_dup2(int old, int new) | |
| 247 | +int _sys_dup2(int old, int new) | |
| 248 | 248 | { |
| 249 | 249 | #if defined(__NR_dup3) |
| 250 | 250 | int ret, nr_fcntl; |
| @@ -256,20 +256,20 @@ int sys_dup2(int old, int new) · 5 unmodified lines | ||
| 256 | 256 | #endif |
| 257 | 257 | |
| 258 | 258 | if (old == new) { |
| 259 | − ret = my_syscall2(nr_fcntl, old, F_GETFD); | |
| 259 | + ret = __nolibc_syscall2(nr_fcntl, old, F_GETFD); | |
| 260 | 260 | return ret < 0 ? ret : old; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | − return my_syscall3(__NR_dup3, old, new, 0); | |
| 263 | + return __nolibc_syscall3(__NR_dup3, old, new, 0); | |
| 264 | 264 | #else |
| 265 | − return my_syscall2(__NR_dup2, old, new); | |
| 265 | + return __nolibc_syscall2(__NR_dup2, old, new); | |
| 266 | 266 | #endif |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | static __attribute__((unused)) |
| 270 | 270 | int dup2(int old, int new) |
| 271 | 271 | { |
| 272 | − return __sysret(sys_dup2(old, new)); | |
| 272 | + return __sysret(_sys_dup2(old, new)); | |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | |
| @@ -279,15 +279,15 @@ int dup2(int old, int new) · 3 unmodified lines | ||
| 279 | 279 | |
| 280 | 280 | #if defined(__NR_dup3) |
| 281 | 281 | static __attribute__((unused)) |
| 282 | −int sys_dup3(int old, int new, int flags) | |
| 282 | +int _sys_dup3(int old, int new, int flags) | |
| 283 | 283 | { |
| 284 | − return my_syscall3(__NR_dup3, old, new, flags); | |
| 284 | + return __nolibc_syscall3(__NR_dup3, old, new, flags); | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | static __attribute__((unused)) |
| 288 | 288 | int dup3(int old, int new, int flags) |
| 289 | 289 | { |
| 290 | − return __sysret(sys_dup3(old, new, flags)); | |
| 290 | + return __sysret(_sys_dup3(old, new, flags)); | |
| 291 | 291 | } |
| 292 | 292 | #endif |
| 293 | 293 | |
| @@ -297,15 +297,15 @@ int dup3(int old, int new, int flags) · 3 unmodified lines | ||
| 297 | 297 | */ |
| 298 | 298 | |
| 299 | 299 | static __attribute__((unused)) |
| 300 | −int sys_execve(const char *filename, char *const argv[], char *const envp[]) | |
| 300 | +int _sys_execve(const char *filename, char *const argv[], char *const envp[]) | |
| 301 | 301 | { |
| 302 | − return my_syscall3(__NR_execve, filename, argv, envp); | |
| 302 | + return __nolibc_syscall3(__NR_execve, filename, argv, envp); | |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | static __attribute__((unused)) |
| 306 | 306 | int execve(const char *filename, char *const argv[], char *const envp[]) |
| 307 | 307 | { |
| 308 | − return __sysret(sys_execve(filename, argv, envp)); | |
| 308 | + return __sysret(_sys_execve(filename, argv, envp)); | |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
| @@ -314,16 +314,16 @@ int execve(const char *filename, char *const argv[], char *const envp[]) · 2 unmodified lines | ||
| 314 | 314 | */ |
| 315 | 315 | |
| 316 | 316 | static __attribute__((noreturn,unused)) |
| 317 | −void sys_exit(int status) | |
| 317 | +void _sys_exit(int status) | |
| 318 | 318 | { |
| 319 | − my_syscall1(__NR_exit, status & 255); | |
| 319 | + __nolibc_syscall1(__NR_exit, status & 255); | |
| 320 | 320 | while(1); /* shut the "noreturn" warnings. */ |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | static __attribute__((noreturn,unused)) |
| 324 | 324 | void _exit(int status) |
| 325 | 325 | { |
| 326 | − sys_exit(status); | |
| 326 | + _sys_exit(status); | |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | static __attribute__((noreturn,unused)) |
| @@ -337,18 +337,18 @@ void exit(int status) · 7 unmodified lines | ||
| 337 | 337 | * pid_t fork(void); |
| 338 | 338 | */ |
| 339 | 339 | |
| 340 | −#ifndef sys_fork | |
| 340 | +#ifndef _sys_fork | |
| 341 | 341 | static __attribute__((unused)) |
| 342 | −pid_t sys_fork(void) | |
| 342 | +pid_t _sys_fork(void) | |
| 343 | 343 | { |
| 344 | 344 | #if defined(__NR_clone) |
| 345 | 345 | /* note: some archs only have clone() and not fork(). Different archs |
| 346 | 346 | * have a different API, but most archs have the flags on first arg and |
| 347 | 347 | * will not use the rest with no other flag. |
| 348 | 348 | */ |
| 349 | − return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0); | |
| 349 | + return __nolibc_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0); | |
| 350 | 350 | #else |
| 351 | − return my_syscall0(__NR_fork); | |
| 351 | + return __nolibc_syscall0(__NR_fork); | |
| 352 | 352 | #endif |
| 353 | 353 | } |
| 354 | 354 | #endif |
| @@ -356,18 +356,18 @@ pid_t sys_fork(void) · 1 unmodified line | ||
| 356 | 356 | static __attribute__((unused)) |
| 357 | 357 | pid_t fork(void) |
| 358 | 358 | { |
| 359 | − return __sysret(sys_fork()); | |
| 359 | + return __sysret(_sys_fork()); | |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | −#ifndef sys_vfork | |
| 362 | +#ifndef _sys_vfork | |
| 363 | 363 | static __attribute__((unused)) |
| 364 | −pid_t sys_vfork(void) | |
| 364 | +pid_t _sys_vfork(void) | |
| 365 | 365 | { |
| 366 | 366 | #if defined(__NR_clone) |
| 367 | − /* See the note in sys_fork(). */ | |
| 368 | − return my_syscall5(__NR_clone, CLONE_VM | CLONE_VFORK | SIGCHLD, 0, 0, 0, 0); | |
| 367 | + /* See the note in _sys_fork(). */ | |
| 368 | + return __nolibc_syscall5(__NR_clone, CLONE_VM | CLONE_VFORK | SIGCHLD, 0, 0, 0, 0); | |
| 369 | 369 | #elif defined(__NR_vfork) |
| 370 | − return my_syscall0(__NR_vfork); | |
| 370 | + return __nolibc_syscall0(__NR_vfork); | |
| 371 | 371 | #endif |
| 372 | 372 | } |
| 373 | 373 | #endif |
| @@ -375,7 +375,7 @@ pid_t sys_vfork(void) · 1 unmodified line | ||
| 375 | 375 | static __attribute__((unused)) |
| 376 | 376 | pid_t vfork(void) |
| 377 | 377 | { |
| 378 | − return __sysret(sys_vfork()); | |
| 378 | + return __sysret(_sys_vfork()); | |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /* |
| @@ -383,15 +383,15 @@ pid_t vfork(void) · 1 unmodified line | ||
| 383 | 383 | */ |
| 384 | 384 | |
| 385 | 385 | static __attribute__((unused)) |
| 386 | −int sys_fsync(int fd) | |
| 386 | +int _sys_fsync(int fd) | |
| 387 | 387 | { |
| 388 | − return my_syscall1(__NR_fsync, fd); | |
| 388 | + return __nolibc_syscall1(__NR_fsync, fd); | |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | static __attribute__((unused)) |
| 392 | 392 | int fsync(int fd) |
| 393 | 393 | { |
| 394 | − return __sysret(sys_fsync(fd)); | |
| 394 | + return __sysret(_sys_fsync(fd)); | |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
| @@ -400,15 +400,15 @@ int fsync(int fd) · 2 unmodified lines | ||
| 400 | 400 | */ |
| 401 | 401 | |
| 402 | 402 | static __attribute__((unused)) |
| 403 | −int sys_getdents64(int fd, struct linux_dirent64 *dirp, int count) | |
| 403 | +int _sys_getdents64(int fd, struct linux_dirent64 *dirp, int count) | |
| 404 | 404 | { |
| 405 | − return my_syscall3(__NR_getdents64, fd, dirp, count); | |
| 405 | + return __nolibc_syscall3(__NR_getdents64, fd, dirp, count); | |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | static __attribute__((unused)) |
| 409 | 409 | int getdents64(int fd, struct linux_dirent64 *dirp, int count) |
| 410 | 410 | { |
| 411 | − return __sysret(sys_getdents64(fd, dirp, count)); | |
| 411 | + return __sysret(_sys_getdents64(fd, dirp, count)); | |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
| @@ -417,19 +417,19 @@ int getdents64(int fd, struct linux_dirent64 *dirp, int count) · 2 unmodified lines | ||
| 417 | 417 | */ |
| 418 | 418 | |
| 419 | 419 | static __attribute__((unused)) |
| 420 | −uid_t sys_geteuid(void) | |
| 420 | +uid_t _sys_geteuid(void) | |
| 421 | 421 | { |
| 422 | 422 | #if defined(__NR_geteuid32) |
| 423 | − return my_syscall0(__NR_geteuid32); | |
| 423 | + return __nolibc_syscall0(__NR_geteuid32); | |
| 424 | 424 | #else |
| 425 | − return my_syscall0(__NR_geteuid); | |
| 425 | + return __nolibc_syscall0(__NR_geteuid); | |
| 426 | 426 | #endif |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | static __attribute__((unused)) |
| 430 | 430 | uid_t geteuid(void) |
| 431 | 431 | { |
| 432 | − return sys_geteuid(); | |
| 432 | + return _sys_geteuid(); | |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
| @@ -438,15 +438,15 @@ uid_t geteuid(void) · 2 unmodified lines | ||
| 438 | 438 | */ |
| 439 | 439 | |
| 440 | 440 | static __attribute__((unused)) |
| 441 | −pid_t sys_getpgid(pid_t pid) | |
| 441 | +pid_t _sys_getpgid(pid_t pid) | |
| 442 | 442 | { |
| 443 | − return my_syscall1(__NR_getpgid, pid); | |
| 443 | + return __nolibc_syscall1(__NR_getpgid, pid); | |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | static __attribute__((unused)) |
| 447 | 447 | pid_t getpgid(pid_t pid) |
| 448 | 448 | { |
| 449 | − return __sysret(sys_getpgid(pid)); | |
| 449 | + return __sysret(_sys_getpgid(pid)); | |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
| @@ -455,15 +455,15 @@ pid_t getpgid(pid_t pid) · 2 unmodified lines | ||
| 455 | 455 | */ |
| 456 | 456 | |
| 457 | 457 | static __attribute__((unused)) |
| 458 | −pid_t sys_getpgrp(void) | |
| 458 | +pid_t _sys_getpgrp(void) | |
| 459 | 459 | { |
| 460 | − return sys_getpgid(0); | |
| 460 | + return _sys_getpgid(0); | |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | static __attribute__((unused)) |
| 464 | 464 | pid_t getpgrp(void) |
| 465 | 465 | { |
| 466 | − return sys_getpgrp(); | |
| 466 | + return _sys_getpgrp(); | |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
| @@ -472,15 +472,15 @@ pid_t getpgrp(void) · 2 unmodified lines | ||
| 472 | 472 | */ |
| 473 | 473 | |
| 474 | 474 | static __attribute__((unused)) |
| 475 | −pid_t sys_getpid(void) | |
| 475 | +pid_t _sys_getpid(void) | |
| 476 | 476 | { |
| 477 | − return my_syscall0(__NR_getpid); | |
| 477 | + return __nolibc_syscall0(__NR_getpid); | |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | static __attribute__((unused)) |
| 481 | 481 | pid_t getpid(void) |
| 482 | 482 | { |
| 483 | − return sys_getpid(); | |
| 483 | + return _sys_getpid(); | |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
| @@ -489,15 +489,15 @@ pid_t getpid(void) · 2 unmodified lines | ||
| 489 | 489 | */ |
| 490 | 490 | |
| 491 | 491 | static __attribute__((unused)) |
| 492 | −pid_t sys_getppid(void) | |
| 492 | +pid_t _sys_getppid(void) | |
| 493 | 493 | { |
| 494 | − return my_syscall0(__NR_getppid); | |
| 494 | + return __nolibc_syscall0(__NR_getppid); | |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | static __attribute__((unused)) |
| 498 | 498 | pid_t getppid(void) |
| 499 | 499 | { |
| 500 | − return sys_getppid(); | |
| 500 | + return _sys_getppid(); | |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | |
| @@ -506,15 +506,15 @@ pid_t getppid(void) · 2 unmodified lines | ||
| 506 | 506 | */ |
| 507 | 507 | |
| 508 | 508 | static __attribute__((unused)) |
| 509 | −pid_t sys_gettid(void) | |
| 509 | +pid_t _sys_gettid(void) | |
| 510 | 510 | { |
| 511 | − return my_syscall0(__NR_gettid); | |
| 511 | + return __nolibc_syscall0(__NR_gettid); | |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | static __attribute__((unused)) |
| 515 | 515 | pid_t gettid(void) |
| 516 | 516 | { |
| 517 | − return sys_gettid(); | |
| 517 | + return _sys_gettid(); | |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | #ifndef NOLIBC_NO_RUNTIME |
| @@ -536,19 +536,19 @@ int getpagesize(void) · 15 unmodified lines | ||
| 536 | 536 | */ |
| 537 | 537 | |
| 538 | 538 | static __attribute__((unused)) |
| 539 | −uid_t sys_getuid(void) | |
| 539 | +uid_t _sys_getuid(void) | |
| 540 | 540 | { |
| 541 | 541 | #if defined(__NR_getuid32) |
| 542 | − return my_syscall0(__NR_getuid32); | |
| 542 | + return __nolibc_syscall0(__NR_getuid32); | |
| 543 | 543 | #else |
| 544 | − return my_syscall0(__NR_getuid); | |
| 544 | + return __nolibc_syscall0(__NR_getuid); | |
| 545 | 545 | #endif |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | static __attribute__((unused)) |
| 549 | 549 | uid_t getuid(void) |
| 550 | 550 | { |
| 551 | − return sys_getuid(); | |
| 551 | + return _sys_getuid(); | |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
| @@ -557,15 +557,15 @@ uid_t getuid(void) · 2 unmodified lines | ||
| 557 | 557 | */ |
| 558 | 558 | |
| 559 | 559 | static __attribute__((unused)) |
| 560 | −int sys_kill(pid_t pid, int signal) | |
| 560 | +int _sys_kill(pid_t pid, int signal) | |
| 561 | 561 | { |
| 562 | − return my_syscall2(__NR_kill, pid, signal); | |
| 562 | + return __nolibc_syscall2(__NR_kill, pid, signal); | |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | static __attribute__((unused)) |
| 566 | 566 | int kill(pid_t pid, int signal) |
| 567 | 567 | { |
| 568 | − return __sysret(sys_kill(pid, signal)); | |
| 568 | + return __sysret(_sys_kill(pid, signal)); | |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
| @@ -574,19 +574,19 @@ int kill(pid_t pid, int signal) · 2 unmodified lines | ||
| 574 | 574 | */ |
| 575 | 575 | |
| 576 | 576 | static __attribute__((unused)) |
| 577 | −int sys_link(const char *old, const char *new) | |
| 577 | +int _sys_link(const char *old, const char *new) | |
| 578 | 578 | { |
| 579 | 579 | #if defined(__NR_linkat) |
| 580 | − return my_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0); | |
| 580 | + return __nolibc_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0); | |
| 581 | 581 | #else |
| 582 | − return my_syscall2(__NR_link, old, new); | |
| 582 | + return __nolibc_syscall2(__NR_link, old, new); | |
| 583 | 583 | #endif |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | static __attribute__((unused)) |
| 587 | 587 | int link(const char *old, const char *new) |
| 588 | 588 | { |
| 589 | − return __sysret(sys_link(old, new)); | |
| 589 | + return __sysret(_sys_link(old, new)); | |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
| @@ -595,14 +595,14 @@ int link(const char *old, const char *new) · 2 unmodified lines | ||
| 595 | 595 | */ |
| 596 | 596 | |
| 597 | 597 | static __attribute__((unused)) |
| 598 | −off_t sys_lseek(int fd, off_t offset, int whence) | |
| 598 | +off_t _sys_lseek(int fd, off_t offset, int whence) | |
| 599 | 599 | { |
| 600 | 600 | #if defined(__NR_llseek) |
| 601 | 601 | __kernel_loff_t loff = 0; |
| 602 | 602 | off_t result; |
| 603 | 603 | int ret; |
| 604 | 604 | |
| 605 | − ret = my_syscall5(__NR_llseek, fd, offset >> 32, (uint32_t)offset, &loff, whence); | |
| 605 | + ret = __nolibc_syscall5(__NR_llseek, fd, offset >> 32, (uint32_t)offset, &loff, whence); | |
| 606 | 606 | if (ret < 0) |
| 607 | 607 | result = ret; |
| 608 | 608 | else |
| @@ -610,14 +610,14 @@ off_t sys_lseek(int fd, off_t offset, int whence) · 1 unmodified line | ||
| 610 | 610 | |
| 611 | 611 | return result; |
| 612 | 612 | #else |
| 613 | − return my_syscall3(__NR_lseek, fd, offset, whence); | |
| 613 | + return __nolibc_syscall3(__NR_lseek, fd, offset, whence); | |
| 614 | 614 | #endif |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | static __attribute__((unused)) |
| 618 | 618 | off_t lseek(int fd, off_t offset, int whence) |
| 619 | 619 | { |
| 620 | − return __sysret(sys_lseek(fd, offset, whence)); | |
| 620 | + return __sysret(_sys_lseek(fd, offset, whence)); | |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | |
| @@ -626,19 +626,19 @@ off_t lseek(int fd, off_t offset, int whence) · 2 unmodified lines | ||
| 626 | 626 | */ |
| 627 | 627 | |
| 628 | 628 | static __attribute__((unused)) |
| 629 | −int sys_mkdir(const char *path, mode_t mode) | |
| 629 | +int _sys_mkdir(const char *path, mode_t mode) | |
| 630 | 630 | { |
| 631 | 631 | #if defined(__NR_mkdirat) |
| 632 | − return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode); | |
| 632 | + return __nolibc_syscall3(__NR_mkdirat, AT_FDCWD, path, mode); | |
| 633 | 633 | #else |
| 634 | − return my_syscall2(__NR_mkdir, path, mode); | |
| 634 | + return __nolibc_syscall2(__NR_mkdir, path, mode); | |
| 635 | 635 | #endif |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | static __attribute__((unused)) |
| 639 | 639 | int mkdir(const char *path, mode_t mode) |
| 640 | 640 | { |
| 641 | − return __sysret(sys_mkdir(path, mode)); | |
| 641 | + return __sysret(_sys_mkdir(path, mode)); | |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /* |
| @@ -646,19 +646,19 @@ int mkdir(const char *path, mode_t mode) · 1 unmodified line | ||
| 646 | 646 | */ |
| 647 | 647 | |
| 648 | 648 | static __attribute__((unused)) |
| 649 | −int sys_rmdir(const char *path) | |
| 649 | +int _sys_rmdir(const char *path) | |
| 650 | 650 | { |
| 651 | 651 | #if defined(__NR_rmdir) |
| 652 | − return my_syscall1(__NR_rmdir, path); | |
| 652 | + return __nolibc_syscall1(__NR_rmdir, path); | |
| 653 | 653 | #else |
| 654 | − return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); | |
| 654 | + return __nolibc_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); | |
| 655 | 655 | #endif |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | static __attribute__((unused)) |
| 659 | 659 | int rmdir(const char *path) |
| 660 | 660 | { |
| 661 | − return __sysret(sys_rmdir(path)); | |
| 661 | + return __sysret(_sys_rmdir(path)); | |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
| @@ -667,19 +667,19 @@ int rmdir(const char *path) · 2 unmodified lines | ||
| 667 | 667 | */ |
| 668 | 668 | |
| 669 | 669 | static __attribute__((unused)) |
| 670 | −long sys_mknod(const char *path, mode_t mode, dev_t dev) | |
| 670 | +long _sys_mknod(const char *path, mode_t mode, dev_t dev) | |
| 671 | 671 | { |
| 672 | 672 | #if defined(__NR_mknodat) |
| 673 | − return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev); | |
| 673 | + return __nolibc_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev); | |
| 674 | 674 | #else |
| 675 | − return my_syscall3(__NR_mknod, path, mode, dev); | |
| 675 | + return __nolibc_syscall3(__NR_mknod, path, mode, dev); | |
| 676 | 676 | #endif |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | static __attribute__((unused)) |
| 680 | 680 | int mknod(const char *path, mode_t mode, dev_t dev) |
| 681 | 681 | { |
| 682 | − return __sysret(sys_mknod(path, mode, dev)); | |
| 682 | + return __sysret(_sys_mknod(path, mode, dev)); | |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | |
| @@ -689,15 +689,15 @@ int mknod(const char *path, mode_t mode, dev_t dev) · 3 unmodified lines | ||
| 689 | 689 | */ |
| 690 | 690 | |
| 691 | 691 | static __attribute__((unused)) |
| 692 | −int sys_pipe2(int pipefd[2], int flags) | |
| 692 | +int _sys_pipe2(int pipefd[2], int flags) | |
| 693 | 693 | { |
| 694 | − return my_syscall2(__NR_pipe2, pipefd, flags); | |
| 694 | + return __nolibc_syscall2(__NR_pipe2, pipefd, flags); | |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | static __attribute__((unused)) |
| 698 | 698 | int pipe2(int pipefd[2], int flags) |
| 699 | 699 | { |
| 700 | − return __sysret(sys_pipe2(pipefd, flags)); | |
| 700 | + return __sysret(_sys_pipe2(pipefd, flags)); | |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | static __attribute__((unused)) |
| @@ -712,15 +712,15 @@ int pipe(int pipefd[2]) · 8 unmodified lines | ||
| 712 | 712 | */ |
| 713 | 713 | |
| 714 | 714 | static __attribute__((unused)) |
| 715 | −int sys_pivot_root(const char *new, const char *old) | |
| 715 | +int _sys_pivot_root(const char *new, const char *old) | |
| 716 | 716 | { |
| 717 | − return my_syscall2(__NR_pivot_root, new, old); | |
| 717 | + return __nolibc_syscall2(__NR_pivot_root, new, old); | |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | static __attribute__((unused)) |
| 721 | 721 | int pivot_root(const char *new, const char *old) |
| 722 | 722 | { |
| 723 | − return __sysret(sys_pivot_root(new, old)); | |
| 723 | + return __sysret(_sys_pivot_root(new, old)); | |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | |
| @@ -729,15 +729,15 @@ int pivot_root(const char *new, const char *old) · 2 unmodified lines | ||
| 729 | 729 | */ |
| 730 | 730 | |
| 731 | 731 | static __attribute__((unused)) |
| 732 | −ssize_t sys_read(int fd, void *buf, size_t count) | |
| 732 | +ssize_t _sys_read(int fd, void *buf, size_t count) | |
| 733 | 733 | { |
| 734 | − return my_syscall3(__NR_read, fd, buf, count); | |
| 734 | + return __nolibc_syscall3(__NR_read, fd, buf, count); | |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | static __attribute__((unused)) |
| 738 | 738 | ssize_t read(int fd, void *buf, size_t count) |
| 739 | 739 | { |
| 740 | − return __sysret(sys_read(fd, buf, count)); | |
| 740 | + return __sysret(_sys_read(fd, buf, count)); | |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
| @@ -746,15 +746,15 @@ ssize_t read(int fd, void *buf, size_t count) · 2 unmodified lines | ||
| 746 | 746 | */ |
| 747 | 747 | |
| 748 | 748 | static __attribute__((unused)) |
| 749 | −int sys_sched_yield(void) | |
| 749 | +int _sys_sched_yield(void) | |
| 750 | 750 | { |
| 751 | − return my_syscall0(__NR_sched_yield); | |
| 751 | + return __nolibc_syscall0(__NR_sched_yield); | |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | static __attribute__((unused)) |
| 755 | 755 | int sched_yield(void) |
| 756 | 756 | { |
| 757 | − return __sysret(sys_sched_yield()); | |
| 757 | + return __sysret(_sys_sched_yield()); | |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | |
| @@ -763,15 +763,15 @@ int sched_yield(void) · 2 unmodified lines | ||
| 763 | 763 | */ |
| 764 | 764 | |
| 765 | 765 | static __attribute__((unused)) |
| 766 | −int sys_setpgid(pid_t pid, pid_t pgid) | |
| 766 | +int _sys_setpgid(pid_t pid, pid_t pgid) | |
| 767 | 767 | { |
| 768 | − return my_syscall2(__NR_setpgid, pid, pgid); | |
| 768 | + return __nolibc_syscall2(__NR_setpgid, pid, pgid); | |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | static __attribute__((unused)) |
| 772 | 772 | int setpgid(pid_t pid, pid_t pgid) |
| 773 | 773 | { |
| 774 | − return __sysret(sys_setpgid(pid, pgid)); | |
| 774 | + return __sysret(_sys_setpgid(pid, pgid)); | |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | /* |
| @@ -790,15 +790,15 @@ pid_t setpgrp(void) · 12 unmodified lines | ||
| 790 | 790 | */ |
| 791 | 791 | |
| 792 | 792 | static __attribute__((unused)) |
| 793 | −pid_t sys_setsid(void) | |
| 793 | +pid_t _sys_setsid(void) | |
| 794 | 794 | { |
| 795 | − return my_syscall0(__NR_setsid); | |
| 795 | + return __nolibc_syscall0(__NR_setsid); | |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | static __attribute__((unused)) |
| 799 | 799 | pid_t setsid(void) |
| 800 | 800 | { |
| 801 | − return __sysret(sys_setsid()); | |
| 801 | + return __sysret(_sys_setsid()); | |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | |
| @@ -807,19 +807,19 @@ pid_t setsid(void) · 2 unmodified lines | ||
| 807 | 807 | */ |
| 808 | 808 | |
| 809 | 809 | static __attribute__((unused)) |
| 810 | −int sys_symlink(const char *old, const char *new) | |
| 810 | +int _sys_symlink(const char *old, const char *new) | |
| 811 | 811 | { |
| 812 | 812 | #if defined(__NR_symlinkat) |
| 813 | − return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new); | |
| 813 | + return __nolibc_syscall3(__NR_symlinkat, old, AT_FDCWD, new); | |
| 814 | 814 | #else |
| 815 | − return my_syscall2(__NR_symlink, old, new); | |
| 815 | + return __nolibc_syscall2(__NR_symlink, old, new); | |
| 816 | 816 | #endif |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | static __attribute__((unused)) |
| 820 | 820 | int symlink(const char *old, const char *new) |
| 821 | 821 | { |
| 822 | − return __sysret(sys_symlink(old, new)); | |
| 822 | + return __sysret(_sys_symlink(old, new)); | |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | |
| @@ -828,15 +828,15 @@ int symlink(const char *old, const char *new) · 2 unmodified lines | ||
| 828 | 828 | */ |
| 829 | 829 | |
| 830 | 830 | static __attribute__((unused)) |
| 831 | −mode_t sys_umask(mode_t mode) | |
| 831 | +mode_t _sys_umask(mode_t mode) | |
| 832 | 832 | { |
| 833 | − return my_syscall1(__NR_umask, mode); | |
| 833 | + return __nolibc_syscall1(__NR_umask, mode); | |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | static __attribute__((unused)) |
| 837 | 837 | mode_t umask(mode_t mode) |
| 838 | 838 | { |
| 839 | − return sys_umask(mode); | |
| 839 | + return _sys_umask(mode); | |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | |
| @@ -845,15 +845,15 @@ mode_t umask(mode_t mode) · 2 unmodified lines | ||
| 845 | 845 | */ |
| 846 | 846 | |
| 847 | 847 | static __attribute__((unused)) |
| 848 | −int sys_umount2(const char *path, int flags) | |
| 848 | +int _sys_umount2(const char *path, int flags) | |
| 849 | 849 | { |
| 850 | − return my_syscall2(__NR_umount2, path, flags); | |
| 850 | + return __nolibc_syscall2(__NR_umount2, path, flags); | |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | static __attribute__((unused)) |
| 854 | 854 | int umount2(const char *path, int flags) |
| 855 | 855 | { |
| 856 | − return __sysret(sys_umount2(path, flags)); | |
| 856 | + return __sysret(_sys_umount2(path, flags)); | |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | |
| @@ -862,19 +862,19 @@ int umount2(const char *path, int flags) · 2 unmodified lines | ||
| 862 | 862 | */ |
| 863 | 863 | |
| 864 | 864 | static __attribute__((unused)) |
| 865 | −int sys_unlink(const char *path) | |
| 865 | +int _sys_unlink(const char *path) | |
| 866 | 866 | { |
| 867 | 867 | #if defined(__NR_unlinkat) |
| 868 | − return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0); | |
| 868 | + return __nolibc_syscall3(__NR_unlinkat, AT_FDCWD, path, 0); | |
| 869 | 869 | #else |
| 870 | − return my_syscall1(__NR_unlink, path); | |
| 870 | + return __nolibc_syscall1(__NR_unlink, path); | |
| 871 | 871 | #endif |
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | static __attribute__((unused)) |
| 875 | 875 | int unlink(const char *path) |
| 876 | 876 | { |
| 877 | − return __sysret(sys_unlink(path)); | |
| 877 | + return __sysret(_sys_unlink(path)); | |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | |
| @@ -883,15 +883,15 @@ int unlink(const char *path) · 2 unmodified lines | ||
| 883 | 883 | */ |
| 884 | 884 | |
| 885 | 885 | static __attribute__((unused)) |
| 886 | −ssize_t sys_write(int fd, const void *buf, size_t count) | |
| 886 | +ssize_t _sys_write(int fd, const void *buf, size_t count) | |
| 887 | 887 | { |
| 888 | − return my_syscall3(__NR_write, fd, buf, count); | |
| 888 | + return __nolibc_syscall3(__NR_write, fd, buf, count); | |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | static __attribute__((unused)) |
| 892 | 892 | ssize_t write(int fd, const void *buf, size_t count) |
| 893 | 893 | { |
| 894 | − return __sysret(sys_write(fd, buf, count)); | |
| 894 | + return __sysret(_sys_write(fd, buf, count)); | |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | |
| @@ -900,15 +900,15 @@ ssize_t write(int fd, const void *buf, size_t count) · 2 unmodified lines | ||
| 900 | 900 | */ |
| 901 | 901 | |
| 902 | 902 | static __attribute__((unused)) |
| 903 | −int sys_memfd_create(const char *name, unsigned int flags) | |
| 903 | +int _sys_memfd_create(const char *name, unsigned int flags) | |
| 904 | 904 | { |
| 905 | − return my_syscall2(__NR_memfd_create, name, flags); | |
| 905 | + return __nolibc_syscall2(__NR_memfd_create, name, flags); | |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | static __attribute__((unused)) |
| 909 | 909 | int memfd_create(const char *name, unsigned int flags) |
| 910 | 910 | { |
| 911 | − return __sysret(sys_memfd_create(name, flags)); | |
| 911 | + return __sysret(_sys_memfd_create(name, flags)); | |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | #endif /* _NOLIBC_SYS_H */ |
| @@ -19,11 +19,11 @@ · 18 unmodified lines | ||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | static __attribute__((unused)) |
| 22 | −long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) | |
| 22 | +long _sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) | |
| 23 | 23 | { |
| 24 | − return my_syscall3(__NR_ioctl, fd, cmd, arg); | |
| 24 | + return __nolibc_syscall3(__NR_ioctl, fd, cmd, arg); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | −#define ioctl(fd, cmd, arg) __sysret(sys_ioctl(fd, cmd, (unsigned long)(arg))) | |
| 27 | +#define ioctl(fd, cmd, arg) __sysret(_sys_ioctl(fd, cmd, (unsigned long)(arg))) | |
| 28 | 28 | |
| 29 | 29 | #endif /* _NOLIBC_SYS_IOCTL_H */ |
| @@ -13,10 +13,10 @@ · 12 unmodified lines | ||
| 13 | 13 | #include "../arch.h" |
| 14 | 14 | #include "../sys.h" |
| 15 | 15 | |
| 16 | −#ifndef sys_mmap | |
| 16 | +#ifndef _sys_mmap | |
| 17 | 17 | static __attribute__((unused)) |
| 18 | −void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, | |
| 19 | − off_t offset) | |
| 18 | +void *_sys_mmap(void *addr, size_t length, int prot, int flags, int fd, | |
| 19 | + off_t offset) | |
| 20 | 20 | { |
| 21 | 21 | int n; |
| 22 | 22 | |
| @@ -27,14 +27,14 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, · 4 unmodified lines | ||
| 27 | 27 | n = __NR_mmap; |
| 28 | 28 | #endif |
| 29 | 29 | |
| 30 | − return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset); | |
| 30 | + return (void *)__nolibc_syscall6(n, addr, length, prot, flags, fd, offset); | |
| 31 | 31 | } |
| 32 | 32 | #endif |
| 33 | 33 | |
| 34 | 34 | static __attribute__((unused)) |
| 35 | 35 | void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) |
| 36 | 36 | { |
| 37 | − void *ret = sys_mmap(addr, length, prot, flags, fd, offset); | |
| 37 | + void *ret = _sys_mmap(addr, length, prot, flags, fd, offset); | |
| 38 | 38 | |
| 39 | 39 | if ((unsigned long)ret >= -4095UL) { |
| 40 | 40 | SET_ERRNO(-(long)ret); |
| @@ -44,16 +44,16 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) · 3 unmodified lines | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | static __attribute__((unused)) |
| 47 | −void *sys_mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address) | |
| 47 | +void *_sys_mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address) | |
| 48 | 48 | { |
| 49 | − return (void *)my_syscall5(__NR_mremap, old_address, old_size, | |
| 50 | − new_size, flags, new_address); | |
| 49 | + return (void *)__nolibc_syscall5(__NR_mremap, old_address, old_size, | |
| 50 | + new_size, flags, new_address); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | static __attribute__((unused)) |
| 54 | 54 | void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address) |
| 55 | 55 | { |
| 56 | − void *ret = sys_mremap(old_address, old_size, new_size, flags, new_address); | |
| 56 | + void *ret = _sys_mremap(old_address, old_size, new_size, flags, new_address); | |
| 57 | 57 | |
| 58 | 58 | if ((unsigned long)ret >= -4095UL) { |
| 59 | 59 | SET_ERRNO(-(long)ret); |
| @@ -63,15 +63,15 @@ void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, voi · 3 unmodified lines | ||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | static __attribute__((unused)) |
| 66 | −int sys_munmap(void *addr, size_t length) | |
| 66 | +int _sys_munmap(void *addr, size_t length) | |
| 67 | 67 | { |
| 68 | − return my_syscall2(__NR_munmap, addr, length); | |
| 68 | + return __nolibc_syscall2(__NR_munmap, addr, length); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | static __attribute__((unused)) |
| 72 | 72 | int munmap(void *addr, size_t length) |
| 73 | 73 | { |
| 74 | − return __sysret(sys_munmap(addr, length)); | |
| 74 | + return __sysret(_sys_munmap(addr, length)); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | #endif /* _NOLIBC_SYS_MMAN_H */ |
| @@ -20,10 +20,10 @@ · 19 unmodified lines | ||
| 20 | 20 | * const void *data); |
| 21 | 21 | */ |
| 22 | 22 | static __attribute__((unused)) |
| 23 | −int sys_mount(const char *src, const char *tgt, const char *fst, | |
| 24 | − unsigned long flags, const void *data) | |
| 23 | +int _sys_mount(const char *src, const char *tgt, const char *fst, | |
| 24 | + unsigned long flags, const void *data) | |
| 25 | 25 | { |
| 26 | − return my_syscall5(__NR_mount, src, tgt, fst, flags, data); | |
| 26 | + return __nolibc_syscall5(__NR_mount, src, tgt, fst, flags, data); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | static __attribute__((unused)) |
| @@ -31,7 +31,7 @@ int mount(const char *src, const char *tgt, · 1 unmodified line | ||
| 31 | 31 | const char *fst, unsigned long flags, |
| 32 | 32 | const void *data) |
| 33 | 33 | { |
| 34 | − return __sysret(sys_mount(src, tgt, fst, flags, data)); | |
| 34 | + return __sysret(_sys_mount(src, tgt, fst, flags, data)); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | #endif /* _NOLIBC_SYS_MOUNT_H */ |
| @@ -20,17 +20,17 @@ · 19 unmodified lines | ||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | static __attribute__((unused)) |
| 23 | −int sys_prctl(int option, unsigned long arg2, unsigned long arg3, | |
| 24 | − unsigned long arg4, unsigned long arg5) | |
| 23 | +int _sys_prctl(int option, unsigned long arg2, unsigned long arg3, | |
| 24 | + unsigned long arg4, unsigned long arg5) | |
| 25 | 25 | { |
| 26 | − return my_syscall5(__NR_prctl, option, arg2, arg3, arg4, arg5); | |
| 26 | + return __nolibc_syscall5(__NR_prctl, option, arg2, arg3, arg4, arg5); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | static __attribute__((unused)) |
| 30 | 30 | int prctl(int option, unsigned long arg2, unsigned long arg3, |
| 31 | 31 | unsigned long arg4, unsigned long arg5) |
| 32 | 32 | { |
| 33 | − return __sysret(sys_prctl(option, arg2, arg3, arg4, arg5)); | |
| 33 | + return __sysret(_sys_prctl(option, arg2, arg3, arg4, arg5)); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | #endif /* _NOLIBC_SYS_PRCTL_H */ |
| @@ -19,15 +19,15 @@ · 18 unmodified lines | ||
| 19 | 19 | * long ptrace(int op, pid_t pid, void *addr, void *data); |
| 20 | 20 | */ |
| 21 | 21 | static __attribute__((unused)) |
| 22 | −long sys_ptrace(int op, pid_t pid, void *addr, void *data) | |
| 22 | +long _sys_ptrace(int op, pid_t pid, void *addr, void *data) | |
| 23 | 23 | { |
| 24 | − return my_syscall4(__NR_ptrace, op, pid, addr, data); | |
| 24 | + return __nolibc_syscall4(__NR_ptrace, op, pid, addr, data); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | static __attribute__((unused)) |
| 28 | 28 | ssize_t ptrace(int op, pid_t pid, void *addr, void *data) |
| 29 | 29 | { |
| 30 | − return __sysret(sys_ptrace(op, pid, addr, data)); | |
| 30 | + return __sysret(_sys_ptrace(op, pid, addr, data)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | #endif /* _NOLIBC_SYS_PTRACE_H */ |
| @@ -20,15 +20,15 @@ · 19 unmodified lines | ||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | static __attribute__((unused)) |
| 23 | −ssize_t sys_getrandom(void *buf, size_t buflen, unsigned int flags) | |
| 23 | +ssize_t _sys_getrandom(void *buf, size_t buflen, unsigned int flags) | |
| 24 | 24 | { |
| 25 | − return my_syscall3(__NR_getrandom, buf, buflen, flags); | |
| 25 | + return __nolibc_syscall3(__NR_getrandom, buf, buflen, flags); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | static __attribute__((unused)) |
| 29 | 29 | ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) |
| 30 | 30 | { |
| 31 | − return __sysret(sys_getrandom(buf, buflen, flags)); | |
| 31 | + return __sysret(_sys_getrandom(buf, buflen, flags)); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | #endif /* _NOLIBC_SYS_RANDOM_H */ |
| @@ -20,15 +20,15 @@ · 19 unmodified lines | ||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | static __attribute__((unused)) |
| 23 | −ssize_t sys_reboot(int magic1, int magic2, int cmd, void *arg) | |
| 23 | +ssize_t _sys_reboot(int magic1, int magic2, int cmd, void *arg) | |
| 24 | 24 | { |
| 25 | − return my_syscall4(__NR_reboot, magic1, magic2, cmd, arg); | |
| 25 | + return __nolibc_syscall4(__NR_reboot, magic1, magic2, cmd, arg); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | static __attribute__((unused)) |
| 29 | 29 | int reboot(int cmd) |
| 30 | 30 | { |
| 31 | − return __sysret(sys_reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, NULL)); | |
| 31 | + return __sysret(_sys_reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, NULL)); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | #endif /* _NOLIBC_SYS_REBOOT_H */ |
| @@ -20,10 +20,10 @@ · 19 unmodified lines | ||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | static __attribute__((unused)) |
| 23 | −int sys_prlimit64(pid_t pid, int resource, | |
| 24 | − const struct rlimit64 *new_limit, struct rlimit64 *old_limit) | |
| 23 | +int _sys_prlimit64(pid_t pid, int resource, | |
| 24 | + const struct rlimit64 *new_limit, struct rlimit64 *old_limit) | |
| 25 | 25 | { |
| 26 | − return my_syscall4(__NR_prlimit64, pid, resource, new_limit, old_limit); | |
| 26 | + return __nolibc_syscall4(__NR_prlimit64, pid, resource, new_limit, old_limit); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | static __attribute__((unused)) |
| @@ -32,7 +32,7 @@ int getrlimit(int resource, struct rlimit *rlim) · 2 unmodified lines | ||
| 32 | 32 | struct rlimit64 rlim64; |
| 33 | 33 | int ret; |
| 34 | 34 | |
| 35 | − ret = __sysret(sys_prlimit64(0, resource, NULL, &rlim64)); | |
| 35 | + ret = __sysret(_sys_prlimit64(0, resource, NULL, &rlim64)); | |
| 36 | 36 | rlim->rlim_cur = rlim64.rlim_cur; |
| 37 | 37 | rlim->rlim_max = rlim64.rlim_max; |
| 38 | 38 | |
| @@ -47,7 +47,7 @@ int setrlimit(int resource, const struct rlimit *rlim) · 8 unmodified lines | ||
| 47 | 47 | .rlim_max = rlim->rlim_max, |
| 48 | 48 | }; |
| 49 | 49 | |
| 50 | − return __sysret(sys_prlimit64(0, resource, &rlim64, NULL)); | |
| 50 | + return __sysret(_sys_prlimit64(0, resource, &rlim64, NULL)); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | #endif /* _NOLIBC_SYS_RESOURCE_H */ |
| @@ -61,7 +61,7 @@ typedef struct { · 60 unmodified lines | ||
| 61 | 61 | */ |
| 62 | 62 | |
| 63 | 63 | static __attribute__((unused)) |
| 64 | −int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) | |
| 64 | +int _sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) | |
| 65 | 65 | { |
| 66 | 66 | #if defined(__NR_pselect6_time64) |
| 67 | 67 | struct __kernel_timespec t; |
| @@ -70,7 +70,8 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva · 2 unmodified lines | ||
| 70 | 70 | t.tv_sec = timeout->tv_sec; |
| 71 | 71 | t.tv_nsec = (uint32_t)timeout->tv_usec * 1000; |
| 72 | 72 | } |
| 73 | − return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); | |
| 73 | + return __nolibc_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, | |
| 74 | + timeout ? &t : NULL, NULL); | |
| 74 | 75 | #else |
| 75 | 76 | struct __kernel_old_timespec t; |
| 76 | 77 | |
| @@ -78,14 +79,15 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva · 1 unmodified line | ||
| 78 | 79 | t.tv_sec = timeout->tv_sec; |
| 79 | 80 | t.tv_nsec = (uint32_t)timeout->tv_usec * 1000; |
| 80 | 81 | } |
| 81 | − return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); | |
| 82 | + return __nolibc_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, | |
| 83 | + timeout ? &t : NULL, NULL); | |
| 82 | 84 | #endif |
| 83 | 85 | } |
| 84 | 86 | |
| 85 | 87 | static __attribute__((unused)) |
| 86 | 88 | int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) |
| 87 | 89 | { |
| 88 | − return __sysret(sys_select(nfds, rfds, wfds, efds, timeout)); | |
| 90 | + return __sysret(_sys_select(nfds, rfds, wfds, efds, timeout)); | |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | #include "../arch.h" |
| 14 | 14 | #include "../types.h" |
| 15 | 15 | #include "../sys.h" |
| 16 | +#include "../sys/sysmacros.h" | |
| 16 | 17 | |
| 17 | 18 | /* |
| 18 | 19 | * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf); |
| @@ -23,10 +24,10 @@ · 4 unmodified lines | ||
| 23 | 24 | */ |
| 24 | 25 | |
| 25 | 26 | static __attribute__((unused)) |
| 26 | −int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf) | |
| 27 | +int _sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf) | |
| 27 | 28 | { |
| 28 | 29 | #ifdef __NR_statx |
| 29 | − return my_syscall5(__NR_statx, fd, path, flags, mask, buf); | |
| 30 | + return __nolibc_syscall5(__NR_statx, fd, path, flags, mask, buf); | |
| 30 | 31 | #else |
| 31 | 32 | return __nolibc_enosys(__func__, fd, path, flags, mask, buf); |
| 32 | 33 | #endif |
| @@ -35,7 +36,7 @@ int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct sta · 2 unmodified lines | ||
| 35 | 36 | static __attribute__((unused)) |
| 36 | 37 | int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf) |
| 37 | 38 | { |
| 38 | − return __sysret(sys_statx(fd, path, flags, mask, buf)); | |
| 39 | + return __sysret(_sys_statx(fd, path, flags, mask, buf)); | |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | 42 | |
| @@ -45,21 +46,17 @@ int fstatat(int fd, const char *path, struct stat *buf, int flag) · 3 unmodified lines | ||
| 45 | 46 | struct statx statx; |
| 46 | 47 | long ret; |
| 47 | 48 | |
| 48 | − ret = __sysret(sys_statx(fd, path, flag | AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx)); | |
| 49 | + ret = __sysret(_sys_statx(fd, path, flag | AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx)); | |
| 49 | 50 | if (ret == -1) |
| 50 | 51 | return ret; |
| 51 | 52 | |
| 52 | − buf->st_dev = ((statx.stx_dev_minor & 0xff) | |
| 53 | − | (statx.stx_dev_major << 8) | |
| 54 | − | ((statx.stx_dev_minor & ~0xff) << 12)); | |
| 53 | + buf->st_dev = makedev(statx.stx_dev_major, statx.stx_dev_minor); | |
| 55 | 54 | buf->st_ino = statx.stx_ino; |
| 56 | 55 | buf->st_mode = statx.stx_mode; |
| 57 | 56 | buf->st_nlink = statx.stx_nlink; |
| 58 | 57 | buf->st_uid = statx.stx_uid; |
| 59 | 58 | buf->st_gid = statx.stx_gid; |
| 60 | − buf->st_rdev = ((statx.stx_rdev_minor & 0xff) | |
| 61 | − | (statx.stx_rdev_major << 8) | |
| 62 | − | ((statx.stx_rdev_minor & ~0xff) << 12)); | |
| 59 | + buf->st_rdev = makedev(statx.stx_rdev_major, statx.stx_rdev_minor); | |
| 63 | 60 | buf->st_size = statx.stx_size; |
| 64 | 61 | buf->st_blksize = statx.stx_blksize; |
| 65 | 62 | buf->st_blocks = statx.stx_blocks; |
| @@ -10,10 +10,11 @@ · 9 unmodified lines | ||
| 10 | 10 | #ifndef _NOLIBC_SYS_SYSCALL_H |
| 11 | 11 | #define _NOLIBC_SYS_SYSCALL_H |
| 12 | 12 | |
| 13 | −#define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N | |
| 14 | −#define _syscall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0) | |
| 15 | −#define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__)) | |
| 16 | −#define _syscall_n(N, ...) _syscall(N, __VA_ARGS__) | |
| 17 | −#define syscall(...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__) | |
| 13 | +#define ___nolibc_syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N | |
| 14 | +#define __nolibc_syscall_narg(...) ___nolibc_syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0) | |
| 15 | +#define __nolibc_syscall(N, ...) __nolibc_syscall##N(__VA_ARGS__) | |
| 16 | +#define __nolibc_syscall_n(N, ...) __nolibc_syscall(N, __VA_ARGS__) | |
| 17 | +#define _syscall(...) __nolibc_syscall_n(__nolibc_syscall_narg(__VA_ARGS__), ##__VA_ARGS__) | |
| 18 | +#define syscall(...) __sysret(_syscall(__VA_ARGS__)) | |
| 18 | 19 | |
| 19 | 20 | #endif /* _NOLIBC_SYS_SYSCALL_H */ |
| @@ -12,9 +12,26 @@ · 11 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | #include "../std.h" |
| 14 | 14 | |
| 15 | −/* WARNING, it only deals with the 4096 first majors and 256 first minors */ | |
| 16 | −#define makedev(major, minor) ((dev_t)((((major) & 0xfff) << 8) | ((minor) & 0xff))) | |
| 17 | −#define major(dev) ((unsigned int)(((dev) >> 8) & 0xfff)) | |
| 18 | −#define minor(dev) ((unsigned int)((dev) & 0xff)) | |
| 15 | +static __inline__ dev_t __nolibc_makedev(unsigned int maj, unsigned int min) | |
| 16 | +{ | |
| 17 | + return (((dev_t)maj & ~0xfff) << 32) | ((maj & 0xfff) << 8) | | |
| 18 | + (((dev_t)min & ~0xff) << 12) | (min & 0xff); | |
| 19 | +} | |
| 20 | + | |
| 21 | +#define makedev(maj, min) __nolibc_makedev(maj, min) | |
| 22 | + | |
| 23 | +static __inline__ unsigned int __nolibc_major(dev_t dev) | |
| 24 | +{ | |
| 25 | + return ((dev >> 32) & ~0xfff) | ((dev >> 8) & 0xfff); | |
| 26 | +} | |
| 27 | + | |
| 28 | +#define major(dev) __nolibc_major(dev) | |
| 29 | + | |
| 30 | +static __inline__ unsigned int __nolibc_minor(dev_t dev) | |
| 31 | +{ | |
| 32 | + return ((dev >> 12) & ~0xff) | (dev & 0xff); | |
| 33 | +} | |
| 34 | + | |
| 35 | +#define minor(dev) __nolibc_minor(dev) | |
| 19 | 36 | |
| 20 | 37 | #endif /* _NOLIBC_SYS_SYSMACROS_H */ |
| @@ -13,21 +13,21 @@ · 12 unmodified lines | ||
| 13 | 13 | #include "../arch.h" |
| 14 | 14 | #include "../sys.h" |
| 15 | 15 | |
| 16 | −static int sys_clock_gettime(clockid_t clockid, struct timespec *tp); | |
| 16 | +static int _sys_clock_gettime(clockid_t clockid, struct timespec *tp); | |
| 17 | 17 | |
| 18 | 18 | /* |
| 19 | 19 | * int gettimeofday(struct timeval *tv, struct timezone *tz); |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | static __attribute__((unused)) |
| 23 | −int sys_gettimeofday(struct timeval *tv, struct timezone *tz) | |
| 23 | +int _sys_gettimeofday(struct timeval *tv, struct timezone *tz) | |
| 24 | 24 | { |
| 25 | 25 | (void) tz; /* Non-NULL tz is undefined behaviour */ |
| 26 | 26 | |
| 27 | 27 | struct timespec tp; |
| 28 | 28 | int ret; |
| 29 | 29 | |
| 30 | − ret = sys_clock_gettime(CLOCK_REALTIME, &tp); | |
| 30 | + ret = _sys_clock_gettime(CLOCK_REALTIME, &tp); | |
| 31 | 31 | if (!ret && tv) { |
| 32 | 32 | tv->tv_sec = tp.tv_sec; |
| 33 | 33 | tv->tv_usec = (uint32_t)tp.tv_nsec / 1000; |
| @@ -39,7 +39,7 @@ int sys_gettimeofday(struct timeval *tv, struct timezone *tz) · 5 unmodified lines | ||
| 39 | 39 | static __attribute__((unused)) |
| 40 | 40 | int gettimeofday(struct timeval *tv, struct timezone *tz) |
| 41 | 41 | { |
| 42 | − return __sysret(sys_gettimeofday(tv, tz)); | |
| 42 | + return __sysret(_sys_gettimeofday(tv, tz)); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | #endif /* _NOLIBC_SYS_TIME_H */ |
| @@ -17,47 +17,47 @@ · 16 unmodified lines | ||
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | static __attribute__((unused)) |
| 20 | −int sys_timerfd_create(int clockid, int flags) | |
| 20 | +int _sys_timerfd_create(int clockid, int flags) | |
| 21 | 21 | { |
| 22 | − return my_syscall2(__NR_timerfd_create, clockid, flags); | |
| 22 | + return __nolibc_syscall2(__NR_timerfd_create, clockid, flags); | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | static __attribute__((unused)) |
| 26 | 26 | int timerfd_create(int clockid, int flags) |
| 27 | 27 | { |
| 28 | − return __sysret(sys_timerfd_create(clockid, flags)); | |
| 28 | + return __sysret(_sys_timerfd_create(clockid, flags)); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | static __attribute__((unused)) |
| 33 | −int sys_timerfd_gettime(int fd, struct itimerspec *curr_value) | |
| 33 | +int _sys_timerfd_gettime(int fd, struct itimerspec *curr_value) | |
| 34 | 34 | { |
| 35 | 35 | #if defined(__NR_timerfd_gettime64) |
| 36 | 36 | __nolibc_assert_time64_type(curr_value->it_value.tv_sec); |
| 37 | − return my_syscall2(__NR_timerfd_gettime64, fd, curr_value); | |
| 37 | + return __nolibc_syscall2(__NR_timerfd_gettime64, fd, curr_value); | |
| 38 | 38 | #else |
| 39 | 39 | __nolibc_assert_native_time64(); |
| 40 | − return my_syscall2(__NR_timerfd_gettime, fd, curr_value); | |
| 40 | + return __nolibc_syscall2(__NR_timerfd_gettime, fd, curr_value); | |
| 41 | 41 | #endif |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | static __attribute__((unused)) |
| 45 | 45 | int timerfd_gettime(int fd, struct itimerspec *curr_value) |
| 46 | 46 | { |
| 47 | − return __sysret(sys_timerfd_gettime(fd, curr_value)); | |
| 47 | + return __sysret(_sys_timerfd_gettime(fd, curr_value)); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | static __attribute__((unused)) |
| 52 | −int sys_timerfd_settime(int fd, int flags, | |
| 53 | − const struct itimerspec *new_value, struct itimerspec *old_value) | |
| 52 | +int _sys_timerfd_settime(int fd, int flags, | |
| 53 | + const struct itimerspec *new_value, struct itimerspec *old_value) | |
| 54 | 54 | { |
| 55 | 55 | #if defined(__NR_timerfd_settime64) |
| 56 | 56 | __nolibc_assert_time64_type(new_value->it_value.tv_sec); |
| 57 | − return my_syscall4(__NR_timerfd_settime64, fd, flags, new_value, old_value); | |
| 57 | + return __nolibc_syscall4(__NR_timerfd_settime64, fd, flags, new_value, old_value); | |
| 58 | 58 | #else |
| 59 | 59 | __nolibc_assert_native_time64(); |
| 60 | − return my_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value); | |
| 60 | + return __nolibc_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value); | |
| 61 | 61 | #endif |
| 62 | 62 | } |
| 63 | 63 | |
| @@ -65,7 +65,7 @@ static __attribute__((unused)) · 1 unmodified line | ||
| 65 | 65 | int timerfd_settime(int fd, int flags, |
| 66 | 66 | const struct itimerspec *new_value, struct itimerspec *old_value) |
| 67 | 67 | { |
| 68 | − return __sysret(sys_timerfd_settime(fd, flags, new_value, old_value)); | |
| 68 | + return __sysret(_sys_timerfd_settime(fd, flags, new_value, old_value)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | #endif /* _NOLIBC_SYS_TIMERFD_H */ |
| @@ -19,30 +19,30 @@ · 18 unmodified lines | ||
| 19 | 19 | * ssize_t readv(int fd, const struct iovec *iovec, int count); |
| 20 | 20 | */ |
| 21 | 21 | static __attribute__((unused)) |
| 22 | −ssize_t sys_readv(int fd, const struct iovec *iovec, int count) | |
| 22 | +ssize_t _sys_readv(int fd, const struct iovec *iovec, int count) | |
| 23 | 23 | { |
| 24 | − return my_syscall3(__NR_readv, fd, iovec, count); | |
| 24 | + return __nolibc_syscall3(__NR_readv, fd, iovec, count); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | static __attribute__((unused)) |
| 28 | 28 | ssize_t readv(int fd, const struct iovec *iovec, int count) |
| 29 | 29 | { |
| 30 | − return __sysret(sys_readv(fd, iovec, count)); | |
| 30 | + return __sysret(_sys_readv(fd, iovec, count)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /* |
| 34 | 34 | * ssize_t writev(int fd, const struct iovec *iovec, int count); |
| 35 | 35 | */ |
| 36 | 36 | static __attribute__((unused)) |
| 37 | −ssize_t sys_writev(int fd, const struct iovec *iovec, int count) | |
| 37 | +ssize_t _sys_writev(int fd, const struct iovec *iovec, int count) | |
| 38 | 38 | { |
| 39 | − return my_syscall3(__NR_writev, fd, iovec, count); | |
| 39 | + return __nolibc_syscall3(__NR_writev, fd, iovec, count); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | static __attribute__((unused)) |
| 43 | 43 | ssize_t writev(int fd, const struct iovec *iovec, int count) |
| 44 | 44 | { |
| 45 | − return __sysret(sys_writev(fd, iovec, count)); | |
| 45 | + return __sysret(_sys_writev(fd, iovec, count)); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
| @@ -28,15 +28,15 @@ struct utsname { · 27 unmodified lines | ||
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | 30 | static __attribute__((unused)) |
| 31 | −int sys_uname(struct utsname *buf) | |
| 31 | +int _sys_uname(struct utsname *buf) | |
| 32 | 32 | { |
| 33 | − return my_syscall1(__NR_uname, buf); | |
| 33 | + return __nolibc_syscall1(__NR_uname, buf); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | static __attribute__((unused)) |
| 37 | 37 | int uname(struct utsname *buf) |
| 38 | 38 | { |
| 39 | − return __sysret(sys_uname(buf)); | |
| 39 | + return __sysret(_sys_uname(buf)); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | #endif /* _NOLIBC_SYS_UTSNAME_H */ |
| @@ -21,15 +21,15 @@ · 20 unmodified lines | ||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | static __attribute__((unused)) |
| 24 | −int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage) | |
| 24 | +int _sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage) | |
| 25 | 25 | { |
| 26 | − return my_syscall5(__NR_waitid, which, pid, infop, options, rusage); | |
| 26 | + return __nolibc_syscall5(__NR_waitid, which, pid, infop, options, rusage); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | static __attribute__((unused)) |
| 30 | 30 | int waitid(int which, pid_t pid, siginfo_t *infop, int options) |
| 31 | 31 | { |
| 32 | − return __sysret(sys_waitid(which, pid, infop, options, NULL)); | |
| 32 | + return __sysret(_sys_waitid(which, pid, infop, options, NULL)); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
| @@ -33,69 +33,69 @@ · 32 unmodified lines | ||
| 33 | 33 | */ |
| 34 | 34 | |
| 35 | 35 | static __attribute__((unused)) |
| 36 | −int sys_clock_getres(clockid_t clockid, struct timespec *res) | |
| 36 | +int _sys_clock_getres(clockid_t clockid, struct timespec *res) | |
| 37 | 37 | { |
| 38 | 38 | #if defined(__NR_clock_getres_time64) |
| 39 | 39 | __nolibc_assert_time64_type(res->tv_sec); |
| 40 | − return my_syscall2(__NR_clock_getres_time64, clockid, res); | |
| 40 | + return __nolibc_syscall2(__NR_clock_getres_time64, clockid, res); | |
| 41 | 41 | #else |
| 42 | 42 | __nolibc_assert_native_time64(); |
| 43 | − return my_syscall2(__NR_clock_getres, clockid, res); | |
| 43 | + return __nolibc_syscall2(__NR_clock_getres, clockid, res); | |
| 44 | 44 | #endif |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | static __attribute__((unused)) |
| 48 | 48 | int clock_getres(clockid_t clockid, struct timespec *res) |
| 49 | 49 | { |
| 50 | − return __sysret(sys_clock_getres(clockid, res)); | |
| 50 | + return __sysret(_sys_clock_getres(clockid, res)); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | static __attribute__((unused)) |
| 54 | −int sys_clock_gettime(clockid_t clockid, struct timespec *tp) | |
| 54 | +int _sys_clock_gettime(clockid_t clockid, struct timespec *tp) | |
| 55 | 55 | { |
| 56 | 56 | #if defined(__NR_clock_gettime64) |
| 57 | 57 | __nolibc_assert_time64_type(tp->tv_sec); |
| 58 | − return my_syscall2(__NR_clock_gettime64, clockid, tp); | |
| 58 | + return __nolibc_syscall2(__NR_clock_gettime64, clockid, tp); | |
| 59 | 59 | #else |
| 60 | 60 | __nolibc_assert_native_time64(); |
| 61 | − return my_syscall2(__NR_clock_gettime, clockid, tp); | |
| 61 | + return __nolibc_syscall2(__NR_clock_gettime, clockid, tp); | |
| 62 | 62 | #endif |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | static __attribute__((unused)) |
| 66 | 66 | int clock_gettime(clockid_t clockid, struct timespec *tp) |
| 67 | 67 | { |
| 68 | − return __sysret(sys_clock_gettime(clockid, tp)); | |
| 68 | + return __sysret(_sys_clock_gettime(clockid, tp)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | static __attribute__((unused)) |
| 72 | −int sys_clock_settime(clockid_t clockid, struct timespec *tp) | |
| 72 | +int _sys_clock_settime(clockid_t clockid, struct timespec *tp) | |
| 73 | 73 | { |
| 74 | 74 | #if defined(__NR_clock_settime64) |
| 75 | 75 | __nolibc_assert_time64_type(tp->tv_sec); |
| 76 | − return my_syscall2(__NR_clock_settime64, clockid, tp); | |
| 76 | + return __nolibc_syscall2(__NR_clock_settime64, clockid, tp); | |
| 77 | 77 | #else |
| 78 | 78 | __nolibc_assert_native_time64(); |
| 79 | − return my_syscall2(__NR_clock_settime, clockid, tp); | |
| 79 | + return __nolibc_syscall2(__NR_clock_settime, clockid, tp); | |
| 80 | 80 | #endif |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | static __attribute__((unused)) |
| 84 | 84 | int clock_settime(clockid_t clockid, struct timespec *tp) |
| 85 | 85 | { |
| 86 | − return __sysret(sys_clock_settime(clockid, tp)); | |
| 86 | + return __sysret(_sys_clock_settime(clockid, tp)); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | static __attribute__((unused)) |
| 90 | −int sys_clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, | |
| 91 | − struct timespec *rmtp) | |
| 90 | +int _sys_clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, | |
| 91 | + struct timespec *rmtp) | |
| 92 | 92 | { |
| 93 | 93 | #if defined(__NR_clock_nanosleep_time64) |
| 94 | 94 | __nolibc_assert_time64_type(rqtp->tv_sec); |
| 95 | − return my_syscall4(__NR_clock_nanosleep_time64, clockid, flags, rqtp, rmtp); | |
| 95 | + return __nolibc_syscall4(__NR_clock_nanosleep_time64, clockid, flags, rqtp, rmtp); | |
| 96 | 96 | #else |
| 97 | 97 | __nolibc_assert_native_time64(); |
| 98 | − return my_syscall4(__NR_clock_nanosleep, clockid, flags, rqtp, rmtp); | |
| 98 | + return __nolibc_syscall4(__NR_clock_nanosleep, clockid, flags, rqtp, rmtp); | |
| 99 | 99 | #endif |
| 100 | 100 | } |
| 101 | 101 | |
| @@ -104,7 +104,7 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, · 2 unmodified lines | ||
| 104 | 104 | struct timespec *rmtp) |
| 105 | 105 | { |
| 106 | 106 | /* Directly return a positive error number */ |
| 107 | − return -sys_clock_nanosleep(clockid, flags, rqtp, rmtp); | |
| 107 | + return -_sys_clock_nanosleep(clockid, flags, rqtp, rmtp); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | static __inline__ |
| @@ -116,7 +116,7 @@ double difftime(time_t time1, time_t time2) · 5 unmodified lines | ||
| 116 | 116 | static __inline__ |
| 117 | 117 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) |
| 118 | 118 | { |
| 119 | − return __sysret(sys_clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp)); | |
| 119 | + return __sysret(_sys_clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp)); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
| @@ -126,7 +126,7 @@ time_t time(time_t *tptr) · 3 unmodified lines | ||
| 126 | 126 | struct timeval tv; |
| 127 | 127 | |
| 128 | 128 | /* note, cannot fail here */ |
| 129 | − sys_gettimeofday(&tv, NULL); | |
| 129 | + _sys_gettimeofday(&tv, NULL); | |
| 130 | 130 | |
| 131 | 131 | if (tptr) |
| 132 | 132 | *tptr = tv.tv_sec; |
| @@ -141,57 +141,57 @@ time_t time(time_t *tptr) · 8 unmodified lines | ||
| 141 | 141 | */ |
| 142 | 142 | |
| 143 | 143 | static __attribute__((unused)) |
| 144 | −int sys_timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) | |
| 144 | +int _sys_timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) | |
| 145 | 145 | { |
| 146 | − return my_syscall3(__NR_timer_create, clockid, evp, timerid); | |
| 146 | + return __nolibc_syscall3(__NR_timer_create, clockid, evp, timerid); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | static __attribute__((unused)) |
| 150 | 150 | int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) |
| 151 | 151 | { |
| 152 | − return __sysret(sys_timer_create(clockid, evp, timerid)); | |
| 152 | + return __sysret(_sys_timer_create(clockid, evp, timerid)); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | static __attribute__((unused)) |
| 156 | −int sys_timer_delete(timer_t timerid) | |
| 156 | +int _sys_timer_delete(timer_t timerid) | |
| 157 | 157 | { |
| 158 | − return my_syscall1(__NR_timer_delete, timerid); | |
| 158 | + return __nolibc_syscall1(__NR_timer_delete, timerid); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | static __attribute__((unused)) |
| 162 | 162 | int timer_delete(timer_t timerid) |
| 163 | 163 | { |
| 164 | − return __sysret(sys_timer_delete(timerid)); | |
| 164 | + return __sysret(_sys_timer_delete(timerid)); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | static __attribute__((unused)) |
| 168 | −int sys_timer_gettime(timer_t timerid, struct itimerspec *curr_value) | |
| 168 | +int _sys_timer_gettime(timer_t timerid, struct itimerspec *curr_value) | |
| 169 | 169 | { |
| 170 | 170 | #if defined(__NR_timer_gettime64) |
| 171 | 171 | __nolibc_assert_time64_type(curr_value->it_value.tv_sec); |
| 172 | − return my_syscall2(__NR_timer_gettime64, timerid, curr_value); | |
| 172 | + return __nolibc_syscall2(__NR_timer_gettime64, timerid, curr_value); | |
| 173 | 173 | #else |
| 174 | 174 | __nolibc_assert_native_time64(); |
| 175 | − return my_syscall2(__NR_timer_gettime, timerid, curr_value); | |
| 175 | + return __nolibc_syscall2(__NR_timer_gettime, timerid, curr_value); | |
| 176 | 176 | #endif |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | static __attribute__((unused)) |
| 180 | 180 | int timer_gettime(timer_t timerid, struct itimerspec *curr_value) |
| 181 | 181 | { |
| 182 | − return __sysret(sys_timer_gettime(timerid, curr_value)); | |
| 182 | + return __sysret(_sys_timer_gettime(timerid, curr_value)); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | static __attribute__((unused)) |
| 186 | −int sys_timer_settime(timer_t timerid, int flags, | |
| 187 | − const struct itimerspec *new_value, struct itimerspec *old_value) | |
| 186 | +int _sys_timer_settime(timer_t timerid, int flags, | |
| 187 | + const struct itimerspec *new_value, struct itimerspec *old_value) | |
| 188 | 188 | { |
| 189 | 189 | #if defined(__NR_timer_settime64) |
| 190 | 190 | __nolibc_assert_time64_type(new_value->it_value.tv_sec); |
| 191 | − return my_syscall4(__NR_timer_settime64, timerid, flags, new_value, old_value); | |
| 191 | + return __nolibc_syscall4(__NR_timer_settime64, timerid, flags, new_value, old_value); | |
| 192 | 192 | #else |
| 193 | 193 | __nolibc_assert_native_time64(); |
| 194 | − return my_syscall4(__NR_timer_settime, timerid, flags, new_value, old_value); | |
| 194 | + return __nolibc_syscall4(__NR_timer_settime, timerid, flags, new_value, old_value); | |
| 195 | 195 | #endif |
| 196 | 196 | } |
| 197 | 197 | |
| @@ -199,7 +199,7 @@ static __attribute__((unused)) · 1 unmodified line | ||
| 199 | 199 | int timer_settime(timer_t timerid, int flags, |
| 200 | 200 | const struct itimerspec *new_value, struct itimerspec *old_value) |
| 201 | 201 | { |
| 202 | − return __sysret(sys_timer_settime(timerid, flags, new_value, old_value)); | |
| 202 | + return __sysret(_sys_timer_settime(timerid, flags, new_value, old_value)); | |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | #endif /* _NOLIBC_TIME_H */ |
| @@ -31,15 +31,15 @@ · 30 unmodified lines | ||
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | 33 | static __attribute__((unused)) |
| 34 | −int sys_faccessat(int fd, const char *path, int amode, int flag) | |
| 34 | +int _sys_faccessat(int fd, const char *path, int amode, int flag) | |
| 35 | 35 | { |
| 36 | − return my_syscall4(__NR_faccessat, fd, path, amode, flag); | |
| 36 | + return __nolibc_syscall4(__NR_faccessat, fd, path, amode, flag); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | static __attribute__((unused)) |
| 40 | 40 | int faccessat(int fd, const char *path, int amode, int flag) |
| 41 | 41 | { |
| 42 | − return __sysret(sys_faccessat(fd, path, amode, flag)); | |
| 42 | + return __sysret(_sys_faccessat(fd, path, amode, flag)); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | static __attribute__((unused)) |
| @@ -54,7 +54,7 @@ int msleep(unsigned int msecs) · 8 unmodified lines | ||
| 54 | 54 | { |
| 55 | 55 | struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 }; |
| 56 | 56 | |
| 57 | − if (sys_select(0, NULL, NULL, NULL, &my_timeval) < 0) | |
| 57 | + if (_sys_select(0, NULL, NULL, NULL, &my_timeval) < 0) | |
| 58 | 58 | return (my_timeval.tv_sec * 1000) + |
| 59 | 59 | (my_timeval.tv_usec / 1000) + |
| 60 | 60 | !!(my_timeval.tv_usec % 1000); |
| @@ -67,7 +67,7 @@ unsigned int sleep(unsigned int seconds) · 6 unmodified lines | ||
| 67 | 67 | { |
| 68 | 68 | struct timeval my_timeval = { seconds, 0 }; |
| 69 | 69 | |
| 70 | − if (sys_select(0, NULL, NULL, NULL, &my_timeval) < 0) | |
| 70 | + if (_sys_select(0, NULL, NULL, NULL, &my_timeval) < 0) | |
| 71 | 71 | return my_timeval.tv_sec + !!my_timeval.tv_usec; |
| 72 | 72 | else |
| 73 | 73 | return 0; |
| @@ -78,7 +78,7 @@ int usleep(unsigned int usecs) · 4 unmodified lines | ||
| 78 | 78 | { |
| 79 | 79 | struct timeval my_timeval = { usecs / 1000000, usecs % 1000000 }; |
| 80 | 80 | |
| 81 | − return sys_select(0, NULL, NULL, NULL, &my_timeval); | |
| 81 | + return _sys_select(0, NULL, NULL, NULL, &my_timeval); | |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | static __attribute__((unused)) |
| @@ -13,9 +13,9 @@ $(OUTPUT)/nolibc-test: CFLAGS = -nostdlib -nostdinc -static \ · 12 unmodified lines | ||
| 13 | 13 | -isystem $(top_srcdir)/tools/include/nolibc -isystem $(top_srcdir)/usr/include \ |
| 14 | 14 | $(CFLAGS_NOLIBC_TEST) |
| 15 | 15 | $(OUTPUT)/nolibc-test: LDLIBS = $(if $(LLVM),,-lgcc) |
| 16 | −$(OUTPUT)/nolibc-test: nolibc-test.c nolibc-test-linkage.c | headers | |
| 16 | +$(OUTPUT)/nolibc-test: $(NOLIBC_TEST_SOURCES) | headers | |
| 17 | 17 | |
| 18 | −$(OUTPUT)/libc-test: nolibc-test.c nolibc-test-linkage.c | |
| 18 | +$(OUTPUT)/libc-test: $(NOLIBC_TEST_SOURCES) | |
| 19 | 19 | $(call msg,CC,,$@) |
| 20 | 20 | $(Q)$(LINK.c) $^ -o $@ |
| 21 | 21 | |
| @@ -5,6 +5,9 @@ _CFLAGS_STACKPROTECTOR ?= $(call try-run, \ · 4 unmodified lines | ||
| 5 | 5 | echo 'void foo(void) {}' | $(CC) -x c - -o - -S $(CLANG_CROSS_FLAGS) $(__CFLAGS_STACKPROTECTOR) | grep -q __stack_chk_guard, \ |
| 6 | 6 | $(__CFLAGS_STACKPROTECTOR)) |
| 7 | 7 | _CFLAGS_SANITIZER ?= $(call cc-option,-fsanitize=undefined -fsanitize-trap=all) |
| 8 | −CFLAGS_NOLIBC_TEST ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \ | |
| 8 | +CFLAGS_NOLIBC_TEST ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \ | |
| 9 | + -W -Wall -Wextra -Wundef \ | |
| 9 | 10 | $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \ |
| 10 | 11 | $(_CFLAGS_STACKPROTECTOR) $(_CFLAGS_SANITIZER) |
| 12 | + | |
| 13 | +NOLIBC_TEST_SOURCES := nolibc-test.c nolibc-test-linkage.c nolibc-test-ignore-errno.c | |
| @@ -232,23 +232,14 @@ ifeq ($(origin XARCH),command line) · 231 unmodified lines | ||
| 232 | 232 | CFLAGS_XARCH = $(CFLAGS_$(XARCH)) |
| 233 | 233 | endif |
| 234 | 234 | |
| 235 | +LDLIBS_ppc = $(if $(LLVM),,-lgcc) | |
| 236 | +LDLIBS = $(LDLIBS_$(XARCH)) | |
| 237 | + | |
| 235 | 238 | include Makefile.include |
| 236 | 239 | |
| 237 | 240 | CFLAGS ?= $(CFLAGS_NOLIBC_TEST) $(CFLAGS_XARCH) $(CFLAGS_EXTRA) |
| 238 | 241 | LDFLAGS := |
| 239 | 242 | |
| 240 | −LIBGCC := -lgcc | |
| 241 | − | |
| 242 | −ifeq ($(ARCH),x86) | |
| 243 | −# Not needed on x86, probably not present for x32 | |
| 244 | −LIBGCC := | |
| 245 | −endif | |
| 246 | − | |
| 247 | −ifneq ($(LLVM),) | |
| 248 | −# Not needed for clang | |
| 249 | −LIBGCC := | |
| 250 | −endif | |
| 251 | − | |
| 252 | 243 | # Modify CFLAGS based on LLVM= |
| 253 | 244 | include $(srctree)/tools/scripts/Makefile.include |
| 254 | 245 | |
| @@ -302,12 +293,12 @@ sysroot/$(ARCH)/include: · 47 unmodified lines | ||
| 302 | 293 | $(Q)$(MAKE) -C $(srctree)/tools/include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone headers_check |
| 303 | 294 | $(Q)mv sysroot/sysroot sysroot/$(ARCH) |
| 304 | 295 | |
| 305 | −nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include | |
| 296 | +nolibc-test: $(NOLIBC_TEST_SOURCES) sysroot/$(ARCH)/include | |
| 306 | 297 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ |
| 307 | − -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c $(LIBGCC) | |
| 298 | + -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $(NOLIBC_TEST_SOURCES) $(LDLIBS) | |
| 308 | 299 | |
| 309 | −libc-test: nolibc-test.c nolibc-test-linkage.c | |
| 310 | − $(QUIET_CC)$(HOSTCC) -o $@ nolibc-test.c nolibc-test-linkage.c | |
| 300 | +libc-test: $(NOLIBC_TEST_SOURCES) | |
| 301 | + $(QUIET_CC)$(HOSTCC) -o $@ $(NOLIBC_TEST_SOURCES) | |
| 311 | 302 | |
| 312 | 303 | # local libc-test |
| 313 | 304 | run-libc-test: libc-test |
| @@ -0,0 +1,6 @@ | ||
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
| 2 | + | |
| 3 | +#define NOLIBC_IGNORE_ERRNO | |
| 4 | + | |
| 5 | +/* Include all of nolibc and make sure everything compiles */ | |
| 6 | +#include <stdlib.h> | |
| @@ -42,6 +42,9 @@ · 41 unmodified lines | ||
| 42 | 42 | #include <unistd.h> |
| 43 | 43 | #include <limits.h> |
| 44 | 44 | #include <ctype.h> |
| 45 | +#include <stdbool.h> | |
| 46 | +#include <byteswap.h> | |
| 47 | +#include <endian.h> | |
| 45 | 48 | |
| 46 | 49 | #pragma GCC diagnostic ignored "-Wmissing-prototypes" |
| 47 | 50 | |
| @@ -66,6 +69,8 @@ static const char *argv0; · 18 unmodified lines | ||
| 66 | 69 | /* will be used by constructor tests */ |
| 67 | 70 | static int constructor_test_value; |
| 68 | 71 | |
| 72 | +static const int is_le = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; | |
| 73 | + | |
| 69 | 74 | static const int is_nolibc = |
| 70 | 75 | #ifdef NOLIBC |
| 71 | 76 | 1 |
| @@ -74,6 +79,30 @@ static const int is_nolibc = · 2 unmodified lines | ||
| 74 | 79 | #endif |
| 75 | 80 | ; |
| 76 | 81 | |
| 82 | +static const int is_glibc = | |
| 83 | +#ifdef __GLIBC__ | |
| 84 | + 1 | |
| 85 | +#else | |
| 86 | + 0 | |
| 87 | +#endif | |
| 88 | +; | |
| 89 | + | |
| 90 | +#if !defined(NOLIBC) | |
| 91 | +/* Some disabled tests may not compile. */ | |
| 92 | + | |
| 93 | +/* strlcat() and strlcpy() may not be in the system headers. */ | |
| 94 | +#undef strlcat | |
| 95 | +#undef strlcpy | |
| 96 | +#define strlcat(d, s, l) 0 | |
| 97 | +#define strlcpy(d, s, l) 0 | |
| 98 | + | |
| 99 | +/* readdir_r() is likely to be marked deprecated */ | |
| 100 | +#undef readdir_r | |
| 101 | +#define readdir_r(dir, dirent, result) ((errno = EINVAL), -1) | |
| 102 | + | |
| 103 | +#define _syscall(...) 0 | |
| 104 | +#endif | |
| 105 | + | |
| 77 | 106 | /* definition of a series of tests */ |
| 78 | 107 | struct test { |
| 79 | 108 | const char *name; /* test name */ |
| @@ -142,21 +171,6 @@ static const char *errorname(int err) · 62 unmodified lines | ||
| 142 | 171 | } |
| 143 | 172 | } |
| 144 | 173 | |
| 145 | −static void align_result(size_t llen) | |
| 146 | −{ | |
| 147 | − const size_t align = 64; | |
| 148 | − char buf[align]; | |
| 149 | − size_t n; | |
| 150 | − | |
| 151 | − if (llen >= align) | |
| 152 | − return; | |
| 153 | − | |
| 154 | − n = align - llen; | |
| 155 | − memset(buf, ' ', n); | |
| 156 | − buf[n] = '\0'; | |
| 157 | − fputs(buf, stdout); | |
| 158 | −} | |
| 159 | − | |
| 160 | 174 | enum RESULT { |
| 161 | 175 | OK, |
| 162 | 176 | FAIL, |
| @@ -174,8 +188,10 @@ static void result(int llen, enum RESULT r) · 11 unmodified lines | ||
| 174 | 188 | else |
| 175 | 189 | msg = " [FAIL]"; |
| 176 | 190 | |
| 177 | − align_result(llen); | |
| 178 | − puts(msg); | |
| 191 | + llen = 64 - llen; | |
| 192 | + if (llen < 0) | |
| 193 | + llen = 0; | |
| 194 | + printf("%*s%s\n", llen, "", msg); | |
| 179 | 195 | } |
| 180 | 196 | |
| 181 | 197 | /* The tests below are intended to be used by the macroes, which evaluate |
| @@ -304,10 +320,7 @@ int expect_syszr(int expr, int llen) · 122 unmodified lines | ||
| 304 | 320 | { |
| 305 | 321 | int ret = 0; |
| 306 | 322 | |
| 307 | − if (errno == ENOSYS) { | |
| 308 | − llen += printf(" = ENOSYS"); | |
| 309 | − result(llen, SKIPPED); | |
| 310 | − } else if (expr) { | |
| 323 | + if (expr) { | |
| 311 | 324 | ret = 1; |
| 312 | 325 | llen += printf(" = %d %s ", expr, errorname(errno)); |
| 313 | 326 | result(llen, FAIL); |
| @@ -347,10 +360,7 @@ int expect_sysne(int expr, int llen, int val) · 33 unmodified lines | ||
| 347 | 360 | { |
| 348 | 361 | int ret = 0; |
| 349 | 362 | |
| 350 | − if (errno == ENOSYS) { | |
| 351 | − llen += printf(" = ENOSYS"); | |
| 352 | − result(llen, SKIPPED); | |
| 353 | − } else if (expr == val) { | |
| 363 | + if (expr == val) { | |
| 354 | 364 | ret = 1; |
| 355 | 365 | llen += printf(" = %d %s ", expr, errorname(errno)); |
| 356 | 366 | result(llen, FAIL); |
| @@ -375,9 +385,7 @@ int expect_syserr2(int expr, int expret, int experr1, int experr2, int llen) · 18 unmodified lines | ||
| 375 | 385 | int _errno = errno; |
| 376 | 386 | |
| 377 | 387 | llen += printf(" = %d %s ", expr, errorname(_errno)); |
| 378 | − if (errno == ENOSYS) { | |
| 379 | − result(llen, SKIPPED); | |
| 380 | − } else if (expr != expret || (_errno != experr1 && _errno != experr2)) { | |
| 388 | + if (expr != expret || (_errno != experr1 && _errno != experr2)) { | |
| 381 | 389 | ret = 1; |
| 382 | 390 | if (experr2 == 0) |
| 383 | 391 | llen += printf(" != (%d %s) ", expret, errorname(experr1)); |
| @@ -701,6 +709,37 @@ static void constructor2(int argc, char **argv, char **envp) · 317 unmodified lines | ||
| 701 | 709 | constructor_test_value |= 1 << 1; |
| 702 | 710 | } |
| 703 | 711 | |
| 712 | +int test_program_invocation_name(void) | |
| 713 | +{ | |
| 714 | + char buf[100]; | |
| 715 | + char *dirsep; | |
| 716 | + ssize_t r; | |
| 717 | + int fd; | |
| 718 | + | |
| 719 | + fd = open("/proc/self/cmdline", O_RDONLY); | |
| 720 | + if (fd == -1) | |
| 721 | + return 1; | |
| 722 | + | |
| 723 | + r = read(fd, buf, sizeof(buf)); | |
| 724 | + close(fd); | |
| 725 | + if (r < 1 || r == sizeof(buf)) | |
| 726 | + return 1; | |
| 727 | + | |
| 728 | + buf[r - 1] = '\0'; | |
| 729 | + | |
| 730 | + if (strcmp(program_invocation_name, buf) != 0) | |
| 731 | + return 1; | |
| 732 | + | |
| 733 | + dirsep = strrchr(buf, '/'); | |
| 734 | + if (!dirsep || dirsep[1] == '\0') | |
| 735 | + return 1; | |
| 736 | + | |
| 737 | + if (strcmp(program_invocation_short_name, dirsep + 1) != 0) | |
| 738 | + return 1; | |
| 739 | + | |
| 740 | + return 0; | |
| 741 | +} | |
| 742 | + | |
| 704 | 743 | int run_startup(int min, int max) |
| 705 | 744 | { |
| 706 | 745 | int test; |
| @@ -715,6 +754,7 @@ int run_startup(int min, int max) · 8 unmodified lines | ||
| 715 | 754 | #ifdef NOLIBC |
| 716 | 755 | test_auxv = _auxv; |
| 717 | 756 | #endif |
| 757 | + bool proc = access("/proc", R_OK) == 0; | |
| 718 | 758 | |
| 719 | 759 | for (test = min; test >= 0 && test <= max; test++) { |
| 720 | 760 | int llen = 0; /* line length */ |
| @@ -740,6 +780,7 @@ int run_startup(int min, int max) · 19 unmodified lines | ||
| 740 | 780 | CASE_TEST(constructor); EXPECT_EQ(is_nolibc, constructor_test_value, 0x3); break; |
| 741 | 781 | CASE_TEST(linkage_errno); EXPECT_PTREQ(1, linkage_test_errno_addr(), &errno); break; |
| 742 | 782 | CASE_TEST(linkage_constr); EXPECT_EQ(1, linkage_test_constructor_test_value, 0x3); break; |
| 783 | + CASE_TEST(prog_name); EXPECT_ZR(proc, test_program_invocation_name()); break; | |
| 743 | 784 | case __LINE__: |
| 744 | 785 | return ret; /* must be last */ |
| 745 | 786 | /* note: do not set any defaults so as to permit holes above */ |
| @@ -866,7 +907,7 @@ int test_file_stream(void) · 120 unmodified lines | ||
| 866 | 907 | |
| 867 | 908 | errno = 0; |
| 868 | 909 | r = fwrite("foo", 1, 3, f); |
| 869 | − if (r != 0 || errno != EBADF) { | |
| 910 | + if (r != 0 || ((is_nolibc || is_glibc) && errno != EBADF)) { | |
| 870 | 911 | fclose(f); |
| 871 | 912 | return -1; |
| 872 | 913 | } |
| @@ -1408,7 +1449,7 @@ int run_syscall(int min, int max) · 535 unmodified lines | ||
| 1408 | 1449 | CASE_TEST(fork); EXPECT_SYSZR(1, test_fork(FORK_STANDARD)); break; |
| 1409 | 1450 | CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break; |
| 1410 | 1451 | CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break; |
| 1411 | − CASE_TEST(directories); EXPECT_SYSZR(proc, test_dirent()); break; | |
| 1452 | + CASE_TEST(directories); EXPECT_SYSZR(is_nolibc && proc, test_dirent()); break; | |
| 1412 | 1453 | CASE_TEST(getrandom); EXPECT_SYSZR(1, test_getrandom()); break; |
| 1413 | 1454 | CASE_TEST(gettimeofday_tv); EXPECT_SYSZR(1, gettimeofday(&tv, NULL)); break; |
| 1414 | 1455 | CASE_TEST(gettimeofday_tv_tz);EXPECT_SYSZR(1, gettimeofday(&tv, &tz)); break; |
| @@ -1442,6 +1483,7 @@ int run_syscall(int min, int max) · 27 unmodified lines | ||
| 1442 | 1483 | CASE_TEST(select_fault); EXPECT_SYSER(1, select(1, (void *)1, NULL, NULL, 0), -1, EFAULT); break; |
| 1443 | 1484 | CASE_TEST(stat_blah); EXPECT_SYSER(1, stat("/proc/self/blah", &stat_buf), -1, ENOENT); break; |
| 1444 | 1485 | CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; |
| 1486 | + CASE_TEST(stat_rdev); EXPECT_SYSZR(1, ({ int ret = stat("/dev/null", &stat_buf); ret ?: stat_buf.st_rdev != makedev(1, 3); })); break; | |
| 1445 | 1487 | CASE_TEST(stat_timestamps); EXPECT_SYSZR(1, test_stat_timestamps()); break; |
| 1446 | 1488 | CASE_TEST(symlink_root); EXPECT_SYSER(1, symlink("/", "/"), -1, EEXIST); break; |
| 1447 | 1489 | CASE_TEST(timer); EXPECT_SYSZR(1, test_timer()); break; |
| @@ -1460,9 +1502,11 @@ int run_syscall(int min, int max) · 12 unmodified lines | ||
| 1460 | 1502 | CASE_TEST(readv_zero); EXPECT_SYSZR(1, readv(0, NULL, 0)); break; |
| 1461 | 1503 | CASE_TEST(writev_badf); EXPECT_SYSER(1, writev(-1, &iov_one, 1), -1, EBADF); break; |
| 1462 | 1504 | CASE_TEST(writev_zero); EXPECT_SYSZR(1, writev(1, NULL, 0)); break; |
| 1463 | − CASE_TEST(ptrace); EXPECT_SYSER(1, ptrace(PTRACE_CONT, getpid(), NULL, NULL), -1, ESRCH); break; | |
| 1505 | + CASE_TEST(ptrace); tmp = ptrace(PTRACE_CONT, getpid(), NULL, NULL); EXPECT_SYSER(tmp != -1 && errno != ENOSYS, tmp, -1, EFAULT); break; | |
| 1464 | 1506 | CASE_TEST(syscall_noargs); EXPECT_SYSEQ(1, syscall(__NR_getpid), getpid()); break; |
| 1465 | 1507 | CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break; |
| 1508 | + CASE_TEST(_syscall_noargs); EXPECT_SYSEQ(is_nolibc, _syscall(__NR_getpid), getpid()); break; | |
| 1509 | + CASE_TEST(_syscall_args); EXPECT_SYSEQ(is_nolibc, _syscall(__NR_statx, 0, NULL, 0, 0, NULL), -EFAULT); break; | |
| 1466 | 1510 | CASE_TEST(namespace); EXPECT_SYSZR(euid0 && proc, test_namespace()); break; |
| 1467 | 1511 | case __LINE__: |
| 1468 | 1512 | return ret; /* must be last */ |
| @@ -1511,6 +1555,60 @@ int test_time_types(void) · 42 unmodified lines | ||
| 1511 | 1555 | return 0; |
| 1512 | 1556 | } |
| 1513 | 1557 | |
| 1558 | +int test_malloc(void) | |
| 1559 | +{ | |
| 1560 | + size_t sz_array1, sz_array2, sz_array3; | |
| 1561 | + int *array1, *array2, *array3; | |
| 1562 | + int pagesize = getpagesize(); | |
| 1563 | + size_t idx; | |
| 1564 | + | |
| 1565 | + if (pagesize < 0) | |
| 1566 | + return 1; | |
| 1567 | + | |
| 1568 | + /* Dependent on the page size, as that is the granularity of our allocator. */ | |
| 1569 | + sz_array1 = pagesize / 2; | |
| 1570 | + array1 = malloc(sz_array1 * sizeof(*array1)); | |
| 1571 | + if (!array1) | |
| 1572 | + return 2; | |
| 1573 | + | |
| 1574 | + for (idx = 0; idx < sz_array1; idx++) | |
| 1575 | + array1[idx] = idx; | |
| 1576 | + | |
| 1577 | + sz_array2 = pagesize * 2; | |
| 1578 | + array2 = calloc(sz_array2, sizeof(*array2)); | |
| 1579 | + if (!array2) { | |
| 1580 | + free(array1); | |
| 1581 | + return 3; | |
| 1582 | + } | |
| 1583 | + | |
| 1584 | + for (idx = 0; idx < sz_array2; idx++) { | |
| 1585 | + if (array2[idx] != 0) { | |
| 1586 | + free(array2); | |
| 1587 | + return 4; | |
| 1588 | + } | |
| 1589 | + array2[idx] = idx + sz_array1; | |
| 1590 | + } | |
| 1591 | + | |
| 1592 | + /* Resize array1 into array3 and append array2 at the end. */ | |
| 1593 | + sz_array3 = sz_array1 + sz_array2; | |
| 1594 | + array3 = realloc(array1, sz_array3 * sizeof(*array3)); | |
| 1595 | + if (!array3) { | |
| 1596 | + free(array2); | |
| 1597 | + free(array1); | |
| 1598 | + return 5; | |
| 1599 | + } | |
| 1600 | + memcpy(array3 + sz_array1, array2, sizeof(*array2) * sz_array2); | |
| 1601 | + free(array2); | |
| 1602 | + | |
| 1603 | + /* The contents must be contiguous now. */ | |
| 1604 | + for (idx = 0; idx < sz_array3; idx++) | |
| 1605 | + if (array3[idx] != (int)idx) | |
| 1606 | + return 6; | |
| 1607 | + | |
| 1608 | + free(array3); | |
| 1609 | + return 0; | |
| 1610 | +} | |
| 1611 | + | |
| 1514 | 1612 | int run_stdlib(int min, int max) |
| 1515 | 1613 | { |
| 1516 | 1614 | int test; |
| @@ -1637,6 +1735,22 @@ int run_stdlib(int min, int max) · 120 unmodified lines | ||
| 1637 | 1735 | CASE_TEST(memchr_foobar6_o); EXPECT_STREQ(1, memchr("foobar", 'o', 6), "oobar"); break; |
| 1638 | 1736 | CASE_TEST(memchr_foobar3_b); EXPECT_STRZR(1, memchr("foobar", 'b', 3)); break; |
| 1639 | 1737 | CASE_TEST(time_types); EXPECT_ZR(is_nolibc, test_time_types()); break; |
| 1738 | + CASE_TEST(makedev); EXPECT_EQ(1, makedev(0x12, 0x34), 0x1234); break; | |
| 1739 | + CASE_TEST(major); EXPECT_EQ(1, major(0x1234), 0x12); break; | |
| 1740 | + CASE_TEST(minor); EXPECT_EQ(1, minor(0x1234), 0x34); break; | |
| 1741 | + CASE_TEST(makedev_big); EXPECT_EQ(1, makedev(0x11223344, 0x55667788), 0x1122355667734488); break; | |
| 1742 | + CASE_TEST(major_big); EXPECT_EQ(1, major(0x1122355667734488), 0x11223344); break; | |
| 1743 | + CASE_TEST(minor_big); EXPECT_EQ(1, minor(0x1122355667734488), 0x55667788); break; | |
| 1744 | + CASE_TEST(malloc); EXPECT_ZR(1, test_malloc()); break; | |
| 1745 | + CASE_TEST(bswap_16); EXPECT_EQ(1, bswap_16(0x0123), 0x2301); break; | |
| 1746 | + CASE_TEST(bswap_32); EXPECT_EQ(1, bswap_32(0x01234567), 0x67452301); break; | |
| 1747 | + CASE_TEST(bswap_64); EXPECT_EQ(1, bswap_64(0x0123456789abcdef), 0xefcdab8967452301); break; | |
| 1748 | + CASE_TEST(htobe16); EXPECT_EQ(1, htobe16(is_le ? 0x0123 : 0x2301), 0x2301); break; | |
| 1749 | + CASE_TEST(htole16); EXPECT_EQ(1, htole16(is_le ? 0x0123 : 0x2301), 0x0123); break; | |
| 1750 | + CASE_TEST(htobe32); EXPECT_EQ(1, htobe32(is_le ? 0x01234567 : 0x67452301), 0x67452301); break; | |
| 1751 | + CASE_TEST(htole32); EXPECT_EQ(1, htole32(is_le ? 0x01234567 : 0x67452301), 0x01234567); break; | |
| 1752 | + CASE_TEST(htobe64); EXPECT_EQ(1, htobe64(is_le ? 0x0123456789000000 : 0x8967452301), 0x8967452301); break; | |
| 1753 | + CASE_TEST(htole64); EXPECT_EQ(1, htole64(is_le ? 0x0123456789 : 0x8967452301000000), 0x0123456789); break; | |
| 1640 | 1754 | |
| 1641 | 1755 | case __LINE__: |
| 1642 | 1756 | return ret; /* must be last */ |
| @@ -1646,33 +1760,60 @@ int run_stdlib(int min, int max) · 3 unmodified lines | ||
| 1646 | 1760 | return ret; |
| 1647 | 1761 | } |
| 1648 | 1762 | |
| 1649 | −#define EXPECT_VFPRINTF(c, expected, fmt, ...) \ | |
| 1650 | − ret += expect_vfprintf(llen, c, expected, fmt, ##__VA_ARGS__) | |
| 1763 | +#define EXPECT_VFPRINTF(cond, expected, fmt, ...) \ | |
| 1764 | + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_vfprintf(llen, expected, fmt, ##__VA_ARGS__); } while (0) | |
| 1651 | 1765 | |
| 1652 | −static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...) | |
| 1766 | +#define VFPRINTF_LEN 25 | |
| 1767 | +static int expect_vfprintf(int llen, const char *expected, const char *fmt, ...) | |
| 1653 | 1768 | { |
| 1654 | − char buf[100]; | |
| 1769 | + char buf[VFPRINTF_LEN + 80]; | |
| 1770 | + unsigned int cmp_len; | |
| 1655 | 1771 | va_list args; |
| 1656 | − ssize_t w; | |
| 1657 | − int ret; | |
| 1772 | + ssize_t written, expected_len; | |
| 1658 | 1773 | |
| 1774 | + /* Fill and terminate buf[] to check for overlong/absent writes */ | |
| 1775 | + memset(buf, 0xa5, sizeof(buf) - 1); | |
| 1776 | + buf[sizeof(buf) - 1] = 0; | |
| 1659 | 1777 | |
| 1660 | 1778 | va_start(args, fmt); |
| 1661 | − /* Only allow writing 21 bytes, to test truncation */ | |
| 1662 | − w = vsnprintf(buf, 21, fmt, args); | |
| 1779 | + /* Limit buffer length to test truncation */ | |
| 1780 | + written = vsnprintf(buf, VFPRINTF_LEN + 1, fmt, args); | |
| 1663 | 1781 | va_end(args); |
| 1664 | 1782 | |
| 1665 | − if (w != c) { | |
| 1666 | − llen += printf(" written(%d) != %d", (int)w, c); | |
| 1783 | + llen += printf(" \"%s\"", buf); | |
| 1784 | + | |
| 1785 | + expected_len = strlen(expected); | |
| 1786 | + if (expected_len > VFPRINTF_LEN) { | |
| 1787 | + /* Indicate truncated in test output */ | |
| 1788 | + llen += printf("+"); | |
| 1789 | + cmp_len = VFPRINTF_LEN; | |
| 1790 | + } else { | |
| 1791 | + cmp_len = expected_len; | |
| 1792 | + } | |
| 1793 | + | |
| 1794 | + if (memcmp(expected, buf, cmp_len) || buf[cmp_len]) { | |
| 1795 | + llen += printf(" should be \"%.*s\"", VFPRINTF_LEN, expected); | |
| 1667 | 1796 | result(llen, FAIL); |
| 1668 | 1797 | return 1; |
| 1669 | 1798 | } |
| 1670 | 1799 | |
| 1671 | − llen += printf(" \"%s\" = \"%s\"", expected, buf); | |
| 1672 | − ret = strncmp(expected, buf, c); | |
| 1800 | + if (written != expected_len) { | |
| 1801 | + llen += printf(" written(%d) != %d", (int)written, (int)expected_len); | |
| 1802 | + result(llen, FAIL); | |
| 1803 | + return 1; | |
| 1804 | + } | |
| 1673 | 1805 | |
| 1674 | − result(llen, ret ? FAIL : OK); | |
| 1675 | − return ret; | |
| 1806 | + /* Check for any overwrites after the actual data. */ | |
| 1807 | + while (++cmp_len < sizeof(buf) - 1) { | |
| 1808 | + if ((unsigned char)buf[cmp_len] != 0xa5) { | |
| 1809 | + llen += printf(" overwrote buf[%d] with 0x%x", cmp_len, buf[cmp_len]); | |
| 1810 | + result(llen, FAIL); | |
| 1811 | + return 1; | |
| 1812 | + } | |
| 1813 | + } | |
| 1814 | + | |
| 1815 | + result(llen, OK); | |
| 1816 | + return 0; | |
| 1676 | 1817 | } |
| 1677 | 1818 | |
| 1678 | 1819 | static int test_scanf(void) |
| @@ -1742,23 +1883,6 @@ static int test_scanf(void) · 63 unmodified lines | ||
| 1742 | 1883 | return 0; |
| 1743 | 1884 | } |
| 1744 | 1885 | |
| 1745 | −int test_strerror(void) | |
| 1746 | −{ | |
| 1747 | − char buf[100]; | |
| 1748 | − ssize_t ret; | |
| 1749 | − | |
| 1750 | − memset(buf, 'A', sizeof(buf)); | |
| 1751 | − | |
| 1752 | − errno = EINVAL; | |
| 1753 | − ret = snprintf(buf, sizeof(buf), "%m"); | |
| 1754 | − if (is_nolibc) { | |
| 1755 | − if (ret < 6 || memcmp(buf, "errno=", 6)) | |
| 1756 | − return 1; | |
| 1757 | − } | |
| 1758 | − | |
| 1759 | − return 0; | |
| 1760 | −} | |
| 1761 | − | |
| 1762 | 1886 | static int test_printf_error(void) |
| 1763 | 1887 | { |
| 1764 | 1888 | int fd, ret, saved_errno; |
| @@ -1781,6 +1905,29 @@ static int test_printf_error(void) · 16 unmodified lines | ||
| 1781 | 1905 | return 0; |
| 1782 | 1906 | } |
| 1783 | 1907 | |
| 1908 | +int test_asprintf(void) | |
| 1909 | +{ | |
| 1910 | + char *str; | |
| 1911 | + int ret; | |
| 1912 | + | |
| 1913 | + ret = asprintf(&str, "foo%s", "bar"); | |
| 1914 | + if (ret == -1) | |
| 1915 | + return 1; | |
| 1916 | + | |
| 1917 | + if (ret != 6) { | |
| 1918 | + free(str); | |
| 1919 | + return 2; | |
| 1920 | + } | |
| 1921 | + | |
| 1922 | + if (memcmp(str, "foobar", 6) != 0) { | |
| 1923 | + free(str); | |
| 1924 | + return 3; | |
| 1925 | + } | |
| 1926 | + | |
| 1927 | + free(str); | |
| 1928 | + return 0; | |
| 1929 | +} | |
| 1930 | + | |
| 1784 | 1931 | static int run_printf(int min, int max) |
| 1785 | 1932 | { |
| 1786 | 1933 | int test; |
| @@ -1793,24 +1940,58 @@ static int run_printf(int min, int max) · 6 unmodified lines | ||
| 1793 | 1940 | * test numbers. |
| 1794 | 1941 | */ |
| 1795 | 1942 | switch (test + __LINE__ + 1) { |
| 1796 | − CASE_TEST(empty); EXPECT_VFPRINTF(0, "", ""); break; | |
| 1797 | − CASE_TEST(simple); EXPECT_VFPRINTF(3, "foo", "foo"); break; | |
| 1798 | − CASE_TEST(string); EXPECT_VFPRINTF(3, "foo", "%s", "foo"); break; | |
| 1799 | − CASE_TEST(number); EXPECT_VFPRINTF(4, "1234", "%d", 1234); break; | |
| 1800 | − CASE_TEST(negnumber); EXPECT_VFPRINTF(5, "-1234", "%d", -1234); break; | |
| 1801 | − CASE_TEST(unsigned); EXPECT_VFPRINTF(5, "12345", "%u", 12345); break; | |
| 1802 | − CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break; | |
| 1803 | − CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break; | |
| 1804 | − CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break; | |
| 1805 | − CASE_TEST(uintmax_t); EXPECT_VFPRINTF(20, "18446744073709551615", "%ju", 0xffffffffffffffffULL); break; | |
| 1806 | − CASE_TEST(intmax_t); EXPECT_VFPRINTF(20, "-9223372036854775807", "%jd", 0x8000000000000001LL); break; | |
| 1807 | − CASE_TEST(truncation); EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break; | |
| 1808 | − CASE_TEST(string_width); EXPECT_VFPRINTF(10, " 1", "%10s", "1"); break; | |
| 1809 | − CASE_TEST(number_width); EXPECT_VFPRINTF(10, " 1", "%10d", 1); break; | |
| 1810 | − CASE_TEST(width_trunc); EXPECT_VFPRINTF(25, " ", "%25d", 1); break; | |
| 1943 | + CASE_TEST(empty); EXPECT_VFPRINTF(1, "", ""); break; | |
| 1944 | + CASE_TEST(simple); EXPECT_VFPRINTF(1, "foo", "foo"); break; | |
| 1945 | + CASE_TEST(string); EXPECT_VFPRINTF(1, "foo", "%s", "foo"); break; | |
| 1946 | + CASE_TEST(number); EXPECT_VFPRINTF(1, "1234", "%d", 1234); break; | |
| 1947 | + CASE_TEST(negnumber); EXPECT_VFPRINTF(1, "-1234", "%d", -1234); break; | |
| 1948 | + CASE_TEST(num_sign); EXPECT_VFPRINTF(1, "| 1|+2|+3|+4|5|", "|% d|%+d|% +d|%+ d|%#d|", 1, 2, 3, 4, 5); break; | |
| 1949 | + CASE_TEST(unsigned); EXPECT_VFPRINTF(1, "12345", "%u", 12345); break; | |
| 1950 | + CASE_TEST(signed_max); EXPECT_VFPRINTF(1, "2147483647", "%i", ~0u >> 1); break; | |
| 1951 | + CASE_TEST(signed_min); EXPECT_VFPRINTF(1, "-2147483648", "%i", (~0u >> 1) + 1); break; | |
| 1952 | + CASE_TEST(unsigned_max); EXPECT_VFPRINTF(1, "4294967295", "%u", ~0u); break; | |
| 1953 | + CASE_TEST(char); EXPECT_VFPRINTF(1, "|c|d| e|", "|%c|%.0c|%4c|", 'c', 'd', 'e'); break; | |
| 1954 | + CASE_TEST(octal); EXPECT_VFPRINTF(1, "|17| 0033||", "|%o|%6.4o|%.0o|", 017, 033, 0); break; | |
| 1955 | + CASE_TEST(octal_max); EXPECT_VFPRINTF(1, "1777777777777777777777", "%llo", ~0ULL); break; | |
| 1956 | + CASE_TEST(octal_alt); EXPECT_VFPRINTF(1, "|0|01|02|034|0|0|", "|%#o|%#o|%#02o|%#02o|%#.0o|%0-#o|", 0, 1, 2, 034, 0, 0); break; | |
| 1957 | + CASE_TEST(hex_nolibc); EXPECT_VFPRINTF(is_nolibc, "|f|d|", "|%x|%X|", 0xf, 0xd); break; | |
| 1958 | + CASE_TEST(hex_libc); EXPECT_VFPRINTF(!is_nolibc, "|f|D|", "|%x|%X|", 0xf, 0xd); break; | |
| 1959 | + CASE_TEST(hex_alt); EXPECT_VFPRINTF(1, "|0x1| 0x2| 0|", "|%#x|%#5x|%#5x|", 1, 2, 0); break; | |
| 1960 | + CASE_TEST(hex_alt_prec); EXPECT_VFPRINTF(1, "| 0x02|0x03| 0x123|", "|%#5.2x|%#04x|%#6.2x|", 2, 3, 0x123); break; | |
| 1961 | + CASE_TEST(hex_0_alt); EXPECT_VFPRINTF(1, "|0|0000| 00|", "|%#x|%#04x|%#5.2x|", 0, 0, 0); break; | |
| 1962 | + CASE_TEST(pointer); EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break; | |
| 1963 | + CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(is_nolibc || is_glibc, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break; | |
| 1964 | + CASE_TEST(string_NULL); EXPECT_VFPRINTF(is_nolibc || is_glibc, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break; | |
| 1965 | + CASE_TEST(percent); EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break; | |
| 1966 | + CASE_TEST(perc_qual); EXPECT_VFPRINTF(is_nolibc || is_glibc, "a%d2", "a%-14l%d%d", 2); break; | |
| 1967 | + CASE_TEST(invalid); EXPECT_VFPRINTF(is_nolibc || is_glibc, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break; | |
| 1968 | + CASE_TEST(intmax_max); EXPECT_VFPRINTF(1, "9223372036854775807", "%lld", ~0ULL >> 1); break; | |
| 1969 | + CASE_TEST(intmax_min); EXPECT_VFPRINTF(is_nolibc || is_glibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break; | |
| 1970 | + CASE_TEST(uintmax_max); EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break; | |
| 1971 | + CASE_TEST(truncation); EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break; | |
| 1972 | + CASE_TEST(string_width); EXPECT_VFPRINTF(1, " 1", "%10s", "1"); break; | |
| 1973 | + CASE_TEST(string_trunc); EXPECT_VFPRINTF(1, " 12345", "%10.5s", "1234567890"); break; | |
| 1974 | + CASE_TEST(string_var); EXPECT_VFPRINTF(1, "| ab|ef | ij|kl |", "|%*.*s|%*.*s|%*.*s|%*.*s|", 3, 2, "abcd", -3, 2, "efgh", 3, -1, "ij", -3, -1, "kl"); break; | |
| 1975 | + CASE_TEST(number_width); EXPECT_VFPRINTF(1, " 1", "%10d", 1); break; | |
| 1976 | + CASE_TEST(number_left); EXPECT_VFPRINTF(1, "|-5 |", "|%-8d|", -5); break; | |
| 1977 | + CASE_TEST(string_align); EXPECT_VFPRINTF(1, "|foo |", "|%-8s|", "foo"); break; | |
| 1978 | + CASE_TEST(width_trunc); EXPECT_VFPRINTF(1, " 1", "%30d", 1); break; | |
| 1979 | + CASE_TEST(width_tr_lft); EXPECT_VFPRINTF(1, "1 ", "%-30d", 1); break; | |
| 1980 | + CASE_TEST(number_pad); EXPECT_VFPRINTF(1, "0000000005", "%010d", 5); break; | |
| 1981 | + CASE_TEST(number_pad); EXPECT_VFPRINTF(1, "|0000000005|0x1234|", "|%010d|%#01x|", 5, 0x1234); break; | |
| 1982 | + CASE_TEST(num_pad_neg); EXPECT_VFPRINTF(1, "-000000005", "%010d", -5); break; | |
| 1983 | + CASE_TEST(num_pad_hex); EXPECT_VFPRINTF(1, "00fffffffb", "%010x", -5); break; | |
| 1984 | + CASE_TEST(num_pad_trunc);EXPECT_VFPRINTF(is_nolibc, " 0000000000000000000000000000005", "%035d", 5); break; /* max 31 '0' can be added */ | |
| 1985 | + CASE_TEST(num_p_tr_libc);EXPECT_VFPRINTF(!is_nolibc, "00000000000000000000000000000000005", "%035d", 5); break; | |
| 1986 | + CASE_TEST(number_prec); EXPECT_VFPRINTF(1, " 00005", "%10.5d", 5); break; | |
| 1987 | + CASE_TEST(num_prec_neg); EXPECT_VFPRINTF(1, " -00005", "%10.5d", -5); break; | |
| 1988 | + CASE_TEST(number_var); EXPECT_VFPRINTF(1, "| -00005|5 |", "|%*.*d|%*.*d|", 10, 5, -5, -2, -10, 5); break; | |
| 1989 | + CASE_TEST(num_0_prec_0); EXPECT_VFPRINTF(1, "|| |+||||", "|%.0d|% .0d|%+.0d|%.0u|%.0x|%#.0x|", 0, 0, 0, 0, 0, 0); break; | |
| 1990 | + CASE_TEST(errno); errno = 22; EXPECT_VFPRINTF(is_nolibc, "errno=22", "%m"); break; | |
| 1991 | + CASE_TEST(errno-neg); errno = -22; EXPECT_VFPRINTF(is_nolibc, "errno=-22 ", "%-12m"); break; | |
| 1811 | 1992 | CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; |
| 1812 | − CASE_TEST(strerror); EXPECT_ZR(1, test_strerror()); break; | |
| 1813 | 1993 | CASE_TEST(printf_error); EXPECT_ZR(1, test_printf_error()); break; |
| 1994 | + CASE_TEST(asprintf); EXPECT_ZR(1, test_asprintf()); break; | |
| 1814 | 1995 | case __LINE__: |
| 1815 | 1996 | return ret; /* must be last */ |
| 1816 | 1997 | /* note: do not set any defaults so as to permit holes above */ |
| @@ -7,7 +7,7 @@ set -e · 6 unmodified lines | ||
| 7 | 7 | |
| 8 | 8 | trap 'echo Aborting...' 'ERR' |
| 9 | 9 | |
| 10 | −crosstool_version=13.2.0 | |
| 10 | +crosstool_version=15.2.0 | |
| 11 | 11 | hostarch=x86_64 |
| 12 | 12 | nproc=$(( $(nproc) + 2)) |
| 13 | 13 | cache_dir="${XDG_CACHE_HOME:-"$HOME"/.cache}" |