LIBMUSLGLUE_SRCS-y += $(LIBMUSL_BASE)/__uk_init_tls.c
LIBMUSLGLUE_SRCS-y += $(LIBMUSL_BASE)/__uk_unmapself.c
LIBMUSLGLUE_SRCS-y += $(LIBMUSL_BASE)/__set_thread_area.c
+LIBMUSLGLUE_SRCS-y += $(LIBMUSL_BASE)/arch/$(CONFIG_UK_ARCH)/__clone.S
LIBMUSLGLUE_COMPFLAGS-y += -I$(LIBMUSL)/src/include
LIBMUSLGLUE_COMPFLAGS-y += -I$(LIBMUSL)/src/internal
LIBMUSLGLUE_CINCLUDES += -I$(LIBMUSL)/src/internal
ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/clone.s|i386
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/syscall_cp.s|i386
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/tls.s|i386
else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x86_64/clone.s|x86_64
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x86_64/syscall_cp.s|x86_64
else ifeq (arm,$(CONFIG_UK_ARCH))
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/__aeabi_read_tp.s|arm
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/__aeabi_read_tp_c.c|arm
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/atomics.s|arm
-LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/clone.s|arm
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/syscall_cp.s|arm
else ifeq (arm64,$(CONFIG_UK_ARCH))
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/aarch64/__unmapself.s|aarch64
-LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/aarch64/clone.s|aarch64
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/aarch64/syscall_cp.s|aarch64
else
LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/clone.c|thread
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2025, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+
+/*
+ * NOTE: This code here is replicated from the core Unikraft repository's clone
+ * libc wrapper, since that is more tailored towards our way of doing system
+ * calls.
+ */
+.global __clone
+__clone:
+ /* Save fn and arg in callee-saved registers, but first make sure
+ * we can also restore them before returning in the parent.
+ */
+ stp x20, x21, [sp, #-16]
+ mov x20, x0
+ mov x21, x3
+
+ /* Now reorder arguments */
+
+ /* flags */
+ mov x0, x2
+
+ /* stack is already in x1, but we must align it for now due to
+ * a TLS size/alignment bug we have. Musl uses the TLS size to
+ * to make some room on the stack for the child and if the TLS size
+ * is not stack-aligned, subtracting it from the child stack
+ * will result in a misaligned stack
+ */
+ and x1, x1, #~0xf
+
+ /* parent_tid */
+ mov x2, x4
+
+ /* tls */
+ mov x3, x5
+
+ /* child_tid */
+ mov x4, x6
+
+ bl uk_syscall_e_clone
+
+ /* Let the parent just return */
+ cbnz x0, 1f
+
+ /* Mark the outermost frame (avoid unwinding beyond this) */
+ mov x29, xzr
+
+ /* The child should now just call the saved fn(arg) */
+ mov x0, x21
+ blr x20
+
+ /* If managed to return from fn(arg) we must call exit(x0) */
+ bl uk_syscall_e_exit
+
+0:
+ /* Put a wfi safeguard here, just in care, cus exit is noreturn */
+ wfi
+ b 0b
+
+1:
+ /* Restore the registers saved in the beginning */
+ ldp x20, x21, [sp, #-16]
+ ret
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2025, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+
+/*
+ * NOTE: This code here is replicated from the core Unikraft repository's clone
+ * libc wrapper, since that is more tailored towards our way of doing system
+ * calls.
+ */
+.global __clone
+__clone:
+ /* Save fn and arg in callee-saved registers, but first make sure
+ * we can also restore them before returning in the parent.
+ */
+ pushq %rbx
+ pushq %rbp
+ movq %rdi, %rbx
+ movq %rcx, %rbp
+
+ /* Now reorder arguments */
+ /* flags */
+ movq %rdx, %rdi
+
+ /* stack is already in rsi, but we must align it for now due to
+ * a TLS size/alignment bug we have. Musl uses the TLS size to
+ * to make some room on the stack for the child and if the TLS size
+ * is not stack-aligned, subtracting it from the child stack
+ * will result in a misaligned stack
+ */
+ andq $~0xf, %rsi
+
+ /* parent_tid */
+ movq %r8, %rdx
+
+ /* child_tid: this is passed on the stack as it does not fit
+ * in the registers used for the arguments
+ *
+ * NOTE: Although this runs on native builds (syscall == function call),
+ * we mustn't use rcx for the 4th argument like for a regular function
+ * call but instead we will have to use r10 as is supposed to happen
+ * for system calls. This is because `clone` is registered as an
+ * execenv system call and execenv registrations assume that the
+ * 4th argument is that according to the syscall calling convention.
+ */
+ movq 24(%rsp), %r10
+
+ /* tls */
+ movq %r9, %r8
+
+ call uk_syscall_e_clone
+
+ /* Let the parent just return */
+ test %eax, %eax
+ jnz 1f
+
+ /* The child should now just call the saved fn(arg) */
+ movq %rbp, %rdi
+
+ /* Mark the outermost frame (avoid unwinding beyond this) */
+ xorl %ebp, %ebp
+ call *%rbx
+
+ /* If managed to return from fn(arg) we must call exit(rax) */
+ movq %rax, %rdi
+ call uk_syscall_e_exit
+
+0:
+ /* Put a hlt safeguard here, just in care, cus exit is noreturn */
+ hlt
+ jmp 0b
+1:
+ /* Restore the registers saved in the beginning */
+ popq %rbp
+ popq %rbx
+ ret
--- /dev/null
+From 52d58e37701b1433b45721107fa4c143a35ce7d0 Mon Sep 17 00:00:00 2001
+From: Florin Postolache <florin.postolache80@gmail.com>
+Date: Mon, 18 Jul 2022 20:39:32 +0300
+Subject: [PATCH] Comment macros to stop using VDSO
+
+The VDSO is responsible for the virtual system calls in a basic
+linux application and makes so that some system calls will be faster
+because the transition between kernel mode and user mode is eliminated.
+Therefore, it shouldn't be used in Unikraft. At the moment, in musl
+this feature is enabled and functions like __clock_gettime will generate
+a segfault.
+
+Signed-off-by: Florin Postolache <florin.postolache80@gmail.com>
+---
+ arch/aarch64/syscall_arch.h | 2 +-
+ arch/i386/syscall_arch.h | 4 ++--
+ arch/x86_64/syscall_arch.h | 4 ++--
+ 3 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/arch/aarch64/syscall_arch.h b/arch/aarch64/syscall_arch.h
+index 504983a..699df67 100644
+--- a/arch/aarch64/syscall_arch.h
++++ b/arch/aarch64/syscall_arch.h
+@@ -72,7 +72,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
+ }
+
+ #define VDSO_USEFUL
+-#define VDSO_CGT_SYM "__kernel_clock_gettime"
++//#define VDSO_CGT_SYM "__kernel_clock_gettime"
+ #define VDSO_CGT_VER "LINUX_2.6.39"
+
+ #define IPC_64 0
+diff --git a/arch/i386/syscall_arch.h b/arch/i386/syscall_arch.h
+index f92b7aa..b0238ba 100644
+--- a/arch/i386/syscall_arch.h
++++ b/arch/i386/syscall_arch.h
+@@ -83,7 +83,7 @@ static inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a
+ }
+
+ #define VDSO_USEFUL
+-#define VDSO_CGT32_SYM "__vdso_clock_gettime"
++//#define VDSO_CGT32_SYM "__vdso_clock_gettime"
+ #define VDSO_CGT32_VER "LINUX_2.6"
+-#define VDSO_CGT_SYM "__vdso_clock_gettime64"
++//#define VDSO_CGT_SYM "__vdso_clock_gettime64"
+ #define VDSO_CGT_VER "LINUX_2.6"
+diff --git a/arch/x86_64/syscall_arch.h b/arch/x86_64/syscall_arch.h
+index 92d5c17..e99279e 100644
+--- a/arch/x86_64/syscall_arch.h
++++ b/arch/x86_64/syscall_arch.h
+@@ -62,9 +62,9 @@ static __inline long __syscall6(long n, long a1, long a2, long a3, long a4, long
+ }
+
+ #define VDSO_USEFUL
+-#define VDSO_CGT_SYM "__vdso_clock_gettime"
++//#define VDSO_CGT_SYM "__vdso_clock_gettime"
+ #define VDSO_CGT_VER "LINUX_2.6"
+-#define VDSO_GETCPU_SYM "__vdso_getcpu"
++//#define VDSO_GETCPU_SYM "__vdso_getcpu"
+ #define VDSO_GETCPU_VER "LINUX_2.6"
+
+ #define IPC_64 0
+--
+2.38.1
+++ /dev/null
-From c43bbea2beabc6a19da64db250d2fef4a71d760a Mon Sep 17 00:00:00 2001
-From: Dragos Iulian Argint <dragosargint21@gmail.com>
-Date: Sun, 14 Aug 2022 13:44:32 +0300
-Subject: [PATCH] This is the clone wrapper that musl uses for x86_64.
-
-Three crucial changes are in this patch. The first is
-the use of function calls instead of system calls. The
-second is placing the function pointer of the thread onto
-the child's stack. The third is aligning the parent's stack.
-
-Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
----
- src/thread/x86_64/clone.s | 67 +++++++++++++++++++++++++--------------
- 1 file changed, 44 insertions(+), 23 deletions(-)
-
-diff --git a/src/thread/x86_64/clone.s b/src/thread/x86_64/clone.s
-index 6e47bc0..b917159 100644
---- a/src/thread/x86_64/clone.s
-+++ b/src/thread/x86_64/clone.s
-@@ -2,27 +2,48 @@
- .global __clone
- .hidden __clone
- .type __clone,@function
-+/* call conv: rdi rsi rdx rcx r8 r9 8(%rsp) */
-+/* clone wrap: func stack flags arg ptid tls ctid */
-+/* sys_clone: flags stack ptid ctid tls */
-+
- __clone:
-- xor %eax,%eax
-- mov $56,%al
-- mov %rdi,%r11
-- mov %rdx,%rdi
-- mov %r8,%rdx
-- mov %r9,%r8
-- mov 8(%rsp),%r10
-- mov %r11,%r9
-- and $-16,%rsi
-- sub $8,%rsi
-- mov %rcx,(%rsi)
-- syscall
-- test %eax,%eax
-- jnz 1f
-- xor %ebp,%ebp
-- pop %rdi
-- call *%r9
-- mov %eax,%edi
-- xor %eax,%eax
-- mov $60,%al
-- syscall
-- hlt
--1: ret
-+ mov %rdi,%r11
-+ mov %rdx,%rdi /* rdi=flags */
-+ mov %r8,%rdx /* rdx=&ptid */
-+ mov %r9,%r8 /* r8=tls */
-+ mov 8(%rsp),%r10
-+ mov %r11,%r9
-+ and $-16,%rsi /* rsi=stack */
-+ sub $16,%rsi
-+ mov %rcx,8(%rsi) /* push the argument onto the child’s stack */
-+ mov %r9,0(%rsi) /* push the function pointer */
-+ mov %r10,%rcx /* rcx=&ctid */
-+ /*
-+ * Normally this wrapper will execute the clone system call.
-+ * In Linux, when switching to kernel mode, the instructions
-+ * are executed on another stack, the "kernel stack". In Unikraft
-+ * we use the same stack, that's the beauty of single address
-+ * space operating systems. However, there is a catch here. What
-+ * if when we execute `uk_syscall_r_clone()' a `movaps` instruction
-+ * (https://www.felixcloutier.com/x86/movaps) is used. These type
-+ * of instructions assume the stack is aligned. A big error will
-+ * appear in our case because we would not have the stack aligned.
-+ * The function that calls this wrapper puts an argument on the stack,
-+ * i.e. only 8 bytes. To make everyone happy, we align the stack to
-+ * 16 bytes. Please note that we are talking here about the parent's
-+ * stack, not the child's stack which we clearly aligned before.
-+ */
-+ sub $8,%rsp
-+ call uk_syscall_r_clone
-+ test %eax,%eax
-+ jnz 1f /* the parent jumps, the child doesn’t */
-+ xor %ebp,%ebp
-+ pop %r9 /* extract the function in child context */
-+ pop %rdi /* extract the argument */
-+ call *%r9 /* call function */
-+ mov %eax,%edi
-+ xor %eax,%eax
-+ call uk_syscall_r_exit
-+ hlt
-+1: add $8,%rsp
-+ ret
---
-2.38.1
-
+++ /dev/null
-From 52d58e37701b1433b45721107fa4c143a35ce7d0 Mon Sep 17 00:00:00 2001
-From: Florin Postolache <florin.postolache80@gmail.com>
-Date: Mon, 18 Jul 2022 20:39:32 +0300
-Subject: [PATCH] Comment macros to stop using VDSO
-
-The VDSO is responsible for the virtual system calls in a basic
-linux application and makes so that some system calls will be faster
-because the transition between kernel mode and user mode is eliminated.
-Therefore, it shouldn't be used in Unikraft. At the moment, in musl
-this feature is enabled and functions like __clock_gettime will generate
-a segfault.
-
-Signed-off-by: Florin Postolache <florin.postolache80@gmail.com>
----
- arch/aarch64/syscall_arch.h | 2 +-
- arch/i386/syscall_arch.h | 4 ++--
- arch/x86_64/syscall_arch.h | 4 ++--
- 3 files changed, 5 insertions(+), 5 deletions(-)
-
-diff --git a/arch/aarch64/syscall_arch.h b/arch/aarch64/syscall_arch.h
-index 504983a..699df67 100644
---- a/arch/aarch64/syscall_arch.h
-+++ b/arch/aarch64/syscall_arch.h
-@@ -72,7 +72,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
- }
-
- #define VDSO_USEFUL
--#define VDSO_CGT_SYM "__kernel_clock_gettime"
-+//#define VDSO_CGT_SYM "__kernel_clock_gettime"
- #define VDSO_CGT_VER "LINUX_2.6.39"
-
- #define IPC_64 0
-diff --git a/arch/i386/syscall_arch.h b/arch/i386/syscall_arch.h
-index f92b7aa..b0238ba 100644
---- a/arch/i386/syscall_arch.h
-+++ b/arch/i386/syscall_arch.h
-@@ -83,7 +83,7 @@ static inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a
- }
-
- #define VDSO_USEFUL
--#define VDSO_CGT32_SYM "__vdso_clock_gettime"
-+//#define VDSO_CGT32_SYM "__vdso_clock_gettime"
- #define VDSO_CGT32_VER "LINUX_2.6"
--#define VDSO_CGT_SYM "__vdso_clock_gettime64"
-+//#define VDSO_CGT_SYM "__vdso_clock_gettime64"
- #define VDSO_CGT_VER "LINUX_2.6"
-diff --git a/arch/x86_64/syscall_arch.h b/arch/x86_64/syscall_arch.h
-index 92d5c17..e99279e 100644
---- a/arch/x86_64/syscall_arch.h
-+++ b/arch/x86_64/syscall_arch.h
-@@ -62,9 +62,9 @@ static __inline long __syscall6(long n, long a1, long a2, long a3, long a4, long
- }
-
- #define VDSO_USEFUL
--#define VDSO_CGT_SYM "__vdso_clock_gettime"
-+//#define VDSO_CGT_SYM "__vdso_clock_gettime"
- #define VDSO_CGT_VER "LINUX_2.6"
--#define VDSO_GETCPU_SYM "__vdso_getcpu"
-+//#define VDSO_GETCPU_SYM "__vdso_getcpu"
- #define VDSO_GETCPU_VER "LINUX_2.6"
-
- #define IPC_64 0
---
-2.38.1
--- /dev/null
+From 40feadbd7fb360033089787a60b7d58deaae4892 Mon Sep 17 00:00:00 2001
+Message-Id: <40feadbd7fb360033089787a60b7d58deaae4892.1669764551.git.razvand@unikraft.io>
+From: Razvan Deaconescu <razvand@unikraft.io>
+Date: Wed, 30 Nov 2022 01:27:36 +0200
+Subject: [PATCH] include: Use function declaration for getdents64()
+
+When defining `getdents64` as a macro aliasing `getdents`, the syscall
+shim layer complains.
+
+The declaration of `getdents64()`, combined with the `LFS64(getdents)`
+aliasing used in `src/dirent/__getdents.c` solves this.
+
+Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
+---
+ include/dirent.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/dirent.h b/include/dirent.h
+index 650ecf6..b72acaf 100644
+--- a/include/dirent.h
++++ b/include/dirent.h
+@@ -65,7 +65,7 @@ int versionsort(const struct dirent **, const struct dirent **);
+ #define versionsort64 versionsort
+ #define off64_t off_t
+ #define ino64_t ino_t
+-#define getdents64 getdents
++int getdents64(int, struct dirent64 *, size_t);
+ #endif
+
+ #ifdef __cplusplus
+--
+2.38.1
+
+++ /dev/null
-From 2ad50560ffad11f6bc1c7788ae733760f6d85f7f Mon Sep 17 00:00:00 2001
-From: Robert Kuban <robert.kuban@opensynergy.com>
-Date: Thu, 11 Aug 2022 18:03:23 +0200
-Subject: [PATCH] Modify clone wrapper
-
-Signed-off-by: Robert Kuban <robert.kuban@opensynergy.com>
----
- src/thread/aarch64/clone.s | 24 ++++++++++++++++--------
- 1 file changed, 16 insertions(+), 8 deletions(-)
-
-diff --git a/src/thread/aarch64/clone.s b/src/thread/aarch64/clone.s
-index e3c8339..0b8abeb 100644
---- a/src/thread/aarch64/clone.s
-+++ b/src/thread/aarch64/clone.s
-@@ -1,13 +1,20 @@
- // __clone(func, stack, flags, arg, ptid, tls, ctid)
- // x0, x1, w2, x3, x4, x5, x6
-
--// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
--// x8, x0, x1, x2, x3, x4
-+// see: lib/posix-process/clone.c
-+// uk_syscall_r_clone(flags, stack, ptid, tlsp, ctid)
-+// x0, x1, x2, x3, x4
-+
-+// see: lib/posix-process/process.c
-+// uk_syscall_r_exit(status)
-+// x0
-
- .global __clone
- .hidden __clone
- .type __clone,%function
- __clone:
-+ stp x29, x30, [sp, #-16]!
-+
- // align stack and save func,arg
- and x1,x1,#-16
- stp x0,x3,[x1,#-16]!
-@@ -17,14 +24,15 @@ __clone:
- mov x2,x4
- mov x3,x5
- mov x4,x6
-- mov x8,#220 // SYS_clone
-- svc #0
-+ bl uk_syscall_r_clone
-
- cbz x0,1f
- // parent
-+ ldp x29, x30, [sp], #16
- ret
-- // child
-+ // child (SP is X1 from syscall now)
- 1: ldp x1,x0,[sp],#16
-- blr x1
-- mov x8,#93 // SYS_exit
-- svc #0
-+ blr x1 // call func(arg)
-+ mov x0, xzr
-+ bl uk_syscall_r_exit
-+ wfi
---
-2.38.1
-
--- /dev/null
+From e9ad1e7f22c64e6b7a26084ba61c51c45b09a5ca Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Eduard=20Vintil=C4=83?= <eduard.vintila47@gmail.com>
+Date: Fri, 9 Dec 2022 23:28:05 +0200
+Subject: [PATCH 1/2] uk_syscall_r-patch
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Use the `uk_syscall_r()` variant for system call numbers
+known only at runtime.
+
+Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
+---
+ src/internal/syscall.h | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/internal/syscall.h b/src/internal/syscall.h
+index 9419ea9..83fa584 100644
+--- a/src/internal/syscall.h
++++ b/src/internal/syscall.h
+@@ -45,8 +45,8 @@ long __syscall_ret(unsigned long), __syscall(uk_syscall_arg_t, ...),
+ static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, long c, long d, long e, long f)
+ {
+ long r;
+- if (cp) r = __syscall_cp(sys, a, b, c, d, e, f);
+- else r = __syscall(sys, a, b, c, d, e, f);
++ if (cp) r = uk_syscall_r(sys, a, b, c, d, e, f);
++ else r = uk_syscall_r(sys, a, b, c, d, e, f);
+ if (r != -ENOSYS) return r;
+ #ifdef SYS_socketcall
+ if (cp) r = __syscall_cp(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f}));
+--
+2.38.1
+
--- /dev/null
+diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h
+index a9a2346..fed6b30 100644
+--- a/include/sys/ioctl.h
++++ b/include/sys/ioctl.h
+@@ -112,7 +112,7 @@ extern "C" {
+ #define SIOCDEVPRIVATE 0x89F0
+ #define SIOCPROTOPRIVATE 0x89E0
+
+-int ioctl (int, int, ...);
++int ioctl (int, unsigned long, ...);
+
+ #ifdef __cplusplus
+ }
+++ /dev/null
-From 40feadbd7fb360033089787a60b7d58deaae4892 Mon Sep 17 00:00:00 2001
-Message-Id: <40feadbd7fb360033089787a60b7d58deaae4892.1669764551.git.razvand@unikraft.io>
-From: Razvan Deaconescu <razvand@unikraft.io>
-Date: Wed, 30 Nov 2022 01:27:36 +0200
-Subject: [PATCH] include: Use function declaration for getdents64()
-
-When defining `getdents64` as a macro aliasing `getdents`, the syscall
-shim layer complains.
-
-The declaration of `getdents64()`, combined with the `LFS64(getdents)`
-aliasing used in `src/dirent/__getdents.c` solves this.
-
-Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
----
- include/dirent.h | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/include/dirent.h b/include/dirent.h
-index 650ecf6..b72acaf 100644
---- a/include/dirent.h
-+++ b/include/dirent.h
-@@ -65,7 +65,7 @@ int versionsort(const struct dirent **, const struct dirent **);
- #define versionsort64 versionsort
- #define off64_t off_t
- #define ino64_t ino_t
--#define getdents64 getdents
-+int getdents64(int, struct dirent64 *, size_t);
- #endif
-
- #ifdef __cplusplus
---
-2.38.1
-
--- /dev/null
+From 9bde85765c75459a1a43060a69d8dc39e1eaeba0 Mon Sep 17 00:00:00 2001
+From: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
+Date: Tue, 4 Apr 2023 20:07:08 +0000
+Subject: [PATCH] locale/iconv: Add character map option
+
+Musl's `iconv` includes lots of character sets by default. Provide an option
+to disable most of them.
+
+Signed-off-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
+---
+ src/locale/codepages.h | 3 ++-
+ src/locale/iconv.c | 10 ++++++++++
+ 2 files changed, 12 insertions(+), 1 deletion(-)
+
+diff --git a/src/locale/codepages.h b/src/locale/codepages.h
+index 4e236ef..bec76af 100644
+--- a/src/locale/codepages.h
++++ b/src/locale/codepages.h
+@@ -2,6 +2,7 @@
+ "latin1\0"
+ "\0\100"
+
++#if CONFIG_LIBMUSL_LOCALE_LEGACY
+ "iso88592\0"
+ "\0\50"
+ "\240\20\364\127\116\244\334\364\324\51\250\124\65\125\126\156\265\42\27\134"
+@@ -317,4 +318,4 @@
+ "\115\70\361\4\24\121\110\221\313\76\374\344\243\317\77\134\334\63\5\25"
+ "\125\130\161\5\26\131\150\41\13\65\326\110\63\115\65\60\304\40\303\14"
+ "\64\324\140\303\15\70\344\60\313\66\334\144\243\315\47"
+-
++#endif
+diff --git a/src/locale/iconv.c b/src/locale/iconv.c
+index 3047c27..0d17ace 100644
+--- a/src/locale/iconv.c
++++ b/src/locale/iconv.c
+@@ -48,6 +48,7 @@ static const unsigned char charmaps[] =
+ "utf16\0\0\312"
+ "ucs4\0utf32\0\0\313"
+ "ucs2\0\0\314"
++#if CONFIG_LIBMUSL_LOCALE_LEGACY
+ "eucjp\0\0\320"
+ "shiftjis\0sjis\0\0\321"
+ "iso2022jp\0\0\322"
+@@ -56,6 +57,7 @@ static const unsigned char charmaps[] =
+ "gb2312\0\0\332"
+ "big5\0bigfive\0cp950\0big5hkscs\0\0\340"
+ "euckr\0ksc5601\0ksx1001\0cp949\0\0\350"
++#endif
+ #include "codepages.h"
+ ;
+
+@@ -66,6 +68,7 @@ static const unsigned short legacy_chars[] = {
+ #include "legacychars.h"
+ };
+
++#if CONFIG_LIBMUSL_LOCALE_LEGACY
+ static const unsigned short jis0208[84][94] = {
+ #include "jis0208.h"
+ };
+@@ -89,6 +92,7 @@ static const unsigned short ksc[93][94] = {
+ static const unsigned short rev_jis[] = {
+ #include "revjis.h"
+ };
++#endif
+
+ static int fuzzycmp(const unsigned char *a, const unsigned char *b)
+ {
+@@ -205,6 +209,7 @@ static unsigned legacy_map(const unsigned char *map, unsigned c)
+ return x < 256 ? x : legacy_chars[x-256];
+ }
+
++#if CONFIG_LIBMUSL_LOCALE_LEGACY
+ static unsigned uni_to_jis(unsigned c)
+ {
+ unsigned nel = sizeof rev_jis / sizeof *rev_jis;
+@@ -223,6 +228,7 @@ static unsigned uni_to_jis(unsigned c)
+ }
+ }
+ }
++#endif
+
+ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb)
+ {
+@@ -319,6 +325,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
+ }
+ type = scd->state;
+ continue;
++#if CONFIG_LIBMUSL_LOCALE_LEGACY
+ case SHIFT_JIS:
+ if (c < 128) break;
+ if (c-0xa1 <= 0xdf-0xa1) {
+@@ -518,6 +525,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
+ c = ksc[c][d];
+ if (!c) goto ilseq;
+ break;
++#endif
+ default:
+ if (!c) break;
+ c = legacy_map(map, c);
+@@ -559,6 +567,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
+ }
+ }
+ goto subst;
++#if CONFIG_LIBMUSL_LOCALE_LEGACY
+ case SHIFT_JIS:
+ if (c < 128) goto revout;
+ if (c == 0xa5) {
+@@ -632,6 +641,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
+ *(*out)++ = 'B';
+ *outb -= 8;
+ break;
++#endif
+ case UCS2:
+ totype = UCS2BE;
+ case UCS2BE:
+--
+2.34.1
+
+++ /dev/null
-From e9ad1e7f22c64e6b7a26084ba61c51c45b09a5ca Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Eduard=20Vintil=C4=83?= <eduard.vintila47@gmail.com>
-Date: Fri, 9 Dec 2022 23:28:05 +0200
-Subject: [PATCH 1/2] uk_syscall_r-patch
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-Use the `uk_syscall_r()` variant for system call numbers
-known only at runtime.
-
-Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
----
- src/internal/syscall.h | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/src/internal/syscall.h b/src/internal/syscall.h
-index 9419ea9..83fa584 100644
---- a/src/internal/syscall.h
-+++ b/src/internal/syscall.h
-@@ -45,8 +45,8 @@ long __syscall_ret(unsigned long), __syscall(uk_syscall_arg_t, ...),
- static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, long c, long d, long e, long f)
- {
- long r;
-- if (cp) r = __syscall_cp(sys, a, b, c, d, e, f);
-- else r = __syscall(sys, a, b, c, d, e, f);
-+ if (cp) r = uk_syscall_r(sys, a, b, c, d, e, f);
-+ else r = uk_syscall_r(sys, a, b, c, d, e, f);
- if (r != -ENOSYS) return r;
- #ifdef SYS_socketcall
- if (cp) r = __syscall_cp(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f}));
---
-2.38.1
-
--- /dev/null
+diff --git a/src/linux/prlimit.c b/src/linux/prlimit.c
+--- a/src/linux/prlimit.c
++++ b/src/linux/prlimit.c (date 1680775764222)
+@@ -1,6 +1,6 @@
+ #define _GNU_SOURCE
+-#include <sys/resource.h>
+ #include "syscall.h"
++#include <sys/resource.h>
+
+ #define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
+
--- /dev/null
+From 99e8a77e67e5a032f7e299d3c7466de00618d926 Mon Sep 17 00:00:00 2001
+From: Stefan Jumarea <stefanjumarea02@gmail.com>
+Date: Sat, 29 Apr 2023 21:47:59 +0300
+Subject: [PATCH] [PATCH]: Change signature for ioctl
+
+The `ioctl()` function signature should be modified to match the definition
+in Linux, glibc and our own implementation, since using `int` has lead
+to a lot of problems (e.g. overflow into sign bit).
+
+Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
+---
+ src/misc/ioctl.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/misc/ioctl.c b/src/misc/ioctl.c
+index 35804f02..ea4e9111 100644
+--- a/src/misc/ioctl.c
++++ b/src/misc/ioctl.c
+@@ -125,7 +125,7 @@ static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old,
+ else memcpy(new+new_offset, old+old_offset, old_size-old_offset);
+ }
+
+-int ioctl(int fd, int req, ...)
++int ioctl(int fd, unsigned long req, ...)
+ {
+ void *arg;
+ va_list ap;
+--
+2.25.1
+
+++ /dev/null
-diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h
-index a9a2346..fed6b30 100644
---- a/include/sys/ioctl.h
-+++ b/include/sys/ioctl.h
-@@ -112,7 +112,7 @@ extern "C" {
- #define SIOCDEVPRIVATE 0x89F0
- #define SIOCPROTOPRIVATE 0x89E0
-
--int ioctl (int, int, ...);
-+int ioctl (int, unsigned long, ...);
-
- #ifdef __cplusplus
- }
--- /dev/null
+From 301a93267aa20c0820552b7ea036111b15574946 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Eduard=20Vintil=C4=83?= <eduard.vintila47@gmail.com>
+Date: Sat, 15 Jul 2023 10:46:40 +0300
+Subject: [PATCH] patches: Add `syscall()` function prototype
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The `sys/syscall.h` header is missing a declaration for the `syscall()`
+function, which may lead to `implicit declaration` warnings that could
+be treated as errors (i.e. by the GO runtime)
+We also include Unikraft's `syscall_nrs2.h` header which provides
+definitions for the `__NR_` macros needed by some libraries.
+
+Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
+---
+ include/sys/syscall.h | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/include/sys/syscall.h b/include/sys/syscall.h
+index 918de59..de68f07 100644
+--- a/include/sys/syscall.h
++++ b/include/sys/syscall.h
+@@ -2,5 +2,8 @@
+ #define _SYS_SYSCALL_H
+
+ #include <uk/bits/syscall_nrs.h>
++#include <uk/bits/syscall_nrs2.h>
++
++long syscall(long n, ...);
+
+ #endif
+--
+2.40.1
+
+++ /dev/null
-From 99e8a77e67e5a032f7e299d3c7466de00618d926 Mon Sep 17 00:00:00 2001
-From: Stefan Jumarea <stefanjumarea02@gmail.com>
-Date: Sat, 29 Apr 2023 21:47:59 +0300
-Subject: [PATCH] [PATCH]: Change signature for ioctl
-
-The `ioctl()` function signature should be modified to match the definition
-in Linux, glibc and our own implementation, since using `int` has lead
-to a lot of problems (e.g. overflow into sign bit).
-
-Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
----
- src/misc/ioctl.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/misc/ioctl.c b/src/misc/ioctl.c
-index 35804f02..ea4e9111 100644
---- a/src/misc/ioctl.c
-+++ b/src/misc/ioctl.c
-@@ -125,7 +125,7 @@ static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old,
- else memcpy(new+new_offset, old+old_offset, old_size-old_offset);
- }
-
--int ioctl(int fd, int req, ...)
-+int ioctl(int fd, unsigned long req, ...)
- {
- void *arg;
- va_list ap;
---
-2.25.1
-
+++ /dev/null
-From 9bde85765c75459a1a43060a69d8dc39e1eaeba0 Mon Sep 17 00:00:00 2001
-From: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
-Date: Tue, 4 Apr 2023 20:07:08 +0000
-Subject: [PATCH] locale/iconv: Add character map option
-
-Musl's `iconv` includes lots of character sets by default. Provide an option
-to disable most of them.
-
-Signed-off-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
----
- src/locale/codepages.h | 3 ++-
- src/locale/iconv.c | 10 ++++++++++
- 2 files changed, 12 insertions(+), 1 deletion(-)
-
-diff --git a/src/locale/codepages.h b/src/locale/codepages.h
-index 4e236ef..bec76af 100644
---- a/src/locale/codepages.h
-+++ b/src/locale/codepages.h
-@@ -2,6 +2,7 @@
- "latin1\0"
- "\0\100"
-
-+#if CONFIG_LIBMUSL_LOCALE_LEGACY
- "iso88592\0"
- "\0\50"
- "\240\20\364\127\116\244\334\364\324\51\250\124\65\125\126\156\265\42\27\134"
-@@ -317,4 +318,4 @@
- "\115\70\361\4\24\121\110\221\313\76\374\344\243\317\77\134\334\63\5\25"
- "\125\130\161\5\26\131\150\41\13\65\326\110\63\115\65\60\304\40\303\14"
- "\64\324\140\303\15\70\344\60\313\66\334\144\243\315\47"
--
-+#endif
-diff --git a/src/locale/iconv.c b/src/locale/iconv.c
-index 3047c27..0d17ace 100644
---- a/src/locale/iconv.c
-+++ b/src/locale/iconv.c
-@@ -48,6 +48,7 @@ static const unsigned char charmaps[] =
- "utf16\0\0\312"
- "ucs4\0utf32\0\0\313"
- "ucs2\0\0\314"
-+#if CONFIG_LIBMUSL_LOCALE_LEGACY
- "eucjp\0\0\320"
- "shiftjis\0sjis\0\0\321"
- "iso2022jp\0\0\322"
-@@ -56,6 +57,7 @@ static const unsigned char charmaps[] =
- "gb2312\0\0\332"
- "big5\0bigfive\0cp950\0big5hkscs\0\0\340"
- "euckr\0ksc5601\0ksx1001\0cp949\0\0\350"
-+#endif
- #include "codepages.h"
- ;
-
-@@ -66,6 +68,7 @@ static const unsigned short legacy_chars[] = {
- #include "legacychars.h"
- };
-
-+#if CONFIG_LIBMUSL_LOCALE_LEGACY
- static const unsigned short jis0208[84][94] = {
- #include "jis0208.h"
- };
-@@ -89,6 +92,7 @@ static const unsigned short ksc[93][94] = {
- static const unsigned short rev_jis[] = {
- #include "revjis.h"
- };
-+#endif
-
- static int fuzzycmp(const unsigned char *a, const unsigned char *b)
- {
-@@ -205,6 +209,7 @@ static unsigned legacy_map(const unsigned char *map, unsigned c)
- return x < 256 ? x : legacy_chars[x-256];
- }
-
-+#if CONFIG_LIBMUSL_LOCALE_LEGACY
- static unsigned uni_to_jis(unsigned c)
- {
- unsigned nel = sizeof rev_jis / sizeof *rev_jis;
-@@ -223,6 +228,7 @@ static unsigned uni_to_jis(unsigned c)
- }
- }
- }
-+#endif
-
- size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb)
- {
-@@ -319,6 +325,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
- }
- type = scd->state;
- continue;
-+#if CONFIG_LIBMUSL_LOCALE_LEGACY
- case SHIFT_JIS:
- if (c < 128) break;
- if (c-0xa1 <= 0xdf-0xa1) {
-@@ -518,6 +525,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
- c = ksc[c][d];
- if (!c) goto ilseq;
- break;
-+#endif
- default:
- if (!c) break;
- c = legacy_map(map, c);
-@@ -559,6 +567,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
- }
- }
- goto subst;
-+#if CONFIG_LIBMUSL_LOCALE_LEGACY
- case SHIFT_JIS:
- if (c < 128) goto revout;
- if (c == 0xa5) {
-@@ -632,6 +641,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
- *(*out)++ = 'B';
- *outb -= 8;
- break;
-+#endif
- case UCS2:
- totype = UCS2BE;
- case UCS2BE:
---
-2.34.1
-
+++ /dev/null
-diff --git a/src/linux/prlimit.c b/src/linux/prlimit.c
---- a/src/linux/prlimit.c
-+++ b/src/linux/prlimit.c (date 1680775764222)
-@@ -1,6 +1,6 @@
- #define _GNU_SOURCE
--#include <sys/resource.h>
- #include "syscall.h"
-+#include <sys/resource.h>
-
- #define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
-
+++ /dev/null
-From 301a93267aa20c0820552b7ea036111b15574946 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Eduard=20Vintil=C4=83?= <eduard.vintila47@gmail.com>
-Date: Sat, 15 Jul 2023 10:46:40 +0300
-Subject: [PATCH] patches: Add `syscall()` function prototype
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-The `sys/syscall.h` header is missing a declaration for the `syscall()`
-function, which may lead to `implicit declaration` warnings that could
-be treated as errors (i.e. by the GO runtime)
-We also include Unikraft's `syscall_nrs2.h` header which provides
-definitions for the `__NR_` macros needed by some libraries.
-
-Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
----
- include/sys/syscall.h | 3 +++
- 1 file changed, 3 insertions(+)
-
-diff --git a/include/sys/syscall.h b/include/sys/syscall.h
-index 918de59..de68f07 100644
---- a/include/sys/syscall.h
-+++ b/include/sys/syscall.h
-@@ -2,5 +2,8 @@
- #define _SYS_SYSCALL_H
-
- #include <uk/bits/syscall_nrs.h>
-+#include <uk/bits/syscall_nrs2.h>
-+
-+long syscall(long n, ...);
-
- #endif
---
-2.40.1
-