[LTP] [PATCH] Update clone3 wrapper signature
Chris Wailes
chriswailes@google.com
Wed Mar 4 22:33:30 CET 2026
Apologies for the delayed response. Please find my updated patch below.
---
>From 50564557a72df12d500997dd145cc5376edd8063 Mon Sep 17 00:00:00 2001
From: Chris Wailes <chriswailes@google.com>
Date: Fri, 14 Nov 2025 13:56:39 -0800
Subject: [PATCH] Update clone3 wrapper signature
This CL adds the `ltp_clone3_raw` wrapper for direct testing of the
syscall, conditionally defines `clone_args_minimal`, and adds a
`ltp_clone3` wrapper for libc implementations that provide `clone3`.
Signed-off-by: Chris Wailes <chriswailes@google.com>
---
include/lapi/sched.h | 32 +++++++++++++++------
testcases/kernel/syscalls/clone3/clone301.c | 2 +-
testcases/kernel/syscalls/clone3/clone302.c | 2 +-
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index 0ffe44641..c0fa8dd47 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -49,9 +49,13 @@ static inline int sched_getattr(pid_t pid, struct
sched_attr *attr,
# define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */
#endif
-#ifndef HAVE_CLONE3
-#ifndef HAVE_STRUCT_CLONE_ARGS
-struct clone_args {
+static inline int ltp_clone3_raw(struct clone_args *args, size_t size)
+{
+ return tst_syscall(__NR_clone3, args, size);
+}
+
+#ifndef HAVE_STRUCT_CLONE_ARGS_MINIMAL
+struct clone_args_minimal {
uint64_t __attribute__((aligned(8))) flags;
uint64_t __attribute__((aligned(8))) pidfd;
uint64_t __attribute__((aligned(8))) child_tid;
@@ -60,13 +64,12 @@ struct clone_args {
uint64_t __attribute__((aligned(8))) stack;
uint64_t __attribute__((aligned(8))) stack_size;
uint64_t __attribute__((aligned(8))) tls;
- uint64_t __attribute__((aligned(8))) set_tid;
- uint64_t __attribute__((aligned(8))) set_tid_size;
- uint64_t __attribute__((aligned(8))) cgroup;
};
#endif
-struct clone_args_minimal {
+#ifndef HAVE_CLONE3
+#ifndef HAVE_STRUCT_CLONE_ARGS
+struct clone_args {
uint64_t __attribute__((aligned(8))) flags;
uint64_t __attribute__((aligned(8))) pidfd;
uint64_t __attribute__((aligned(8))) child_tid;
@@ -75,11 +78,22 @@ struct clone_args_minimal {
uint64_t __attribute__((aligned(8))) stack;
uint64_t __attribute__((aligned(8))) stack_size;
uint64_t __attribute__((aligned(8))) tls;
+ uint64_t __attribute__((aligned(8))) set_tid;
+ uint64_t __attribute__((aligned(8))) set_tid_size;
+ uint64_t __attribute__((aligned(8))) cgroup;
};
+#endif
-static inline int clone3(struct clone_args *args, size_t size)
+int ltp_clone3(struct clone_args *cl_args, size_t size,
+ int (*fn)(void *), void *arg) {
+ return clone3(cl_args, size, fn, arg);
+}
+#else
+
+static inline int ltp_clone3(struct clone_args *cl_args, size_t size,
+ int (*fn)(void *), void *arg)
{
- return tst_syscall(__NR_clone3, args, size);
+ return -1;
}
#endif
diff --git a/testcases/kernel/syscalls/clone3/clone301.c
b/testcases/kernel/syscalls/clone3/clone301.c
index deed30b9f..58fc1702e 100644
--- a/testcases/kernel/syscalls/clone3/clone301.c
+++ b/testcases/kernel/syscalls/clone3/clone301.c
@@ -123,7 +123,7 @@ static void run(unsigned int n)
parent_received_signal = 0;
SAFE_SIGACTION(tc->exit_signal, &psig_action, NULL);
- TEST(pid = clone3(args, sizeof(*args)));
+ TEST(pid = ltp_clone3_raw(args, sizeof(*args)));
if (pid < 0) {
tst_res(TFAIL | TTERRNO, "clone3() failed (%d)", n);
return;
diff --git a/testcases/kernel/syscalls/clone3/clone302.c
b/testcases/kernel/syscalls/clone3/clone302.c
index 9e98f1954..883112183 100644
--- a/testcases/kernel/syscalls/clone3/clone302.c
+++ b/testcases/kernel/syscalls/clone3/clone302.c
@@ -83,7 +83,7 @@ static void run(unsigned int n)
args->tls = tc->tls;
}
- TEST(clone3(args, tc->size));
+ TEST(ltp_clone3_raw(args, tc->size));
if (!TST_RET)
exit(EXIT_SUCCESS);
--
2.53.0.473.g4a7958ca14-goog
On Wed, Dec 17, 2025 at 1:43 AM Li Wang <liwang@redhat.com> wrote:
>
>
> On Wed, Dec 17, 2025 at 3:58 PM Anrea Cervesato via ltp <
> ltp@lists.linux.it> wrote:
>
>> Hi Chris,
>>
>> On 12/16/25 6:50 PM, Chris Wailes wrote:
>> > Andrea,
>> >
>> > Thanks for reviewing the change. We're currently adding a `clone3`
>> > wrapper to Android's BIONIC libc implementation. Additionally, this is
>> > the signature used for `glibc`'s `__clone3`
>> > <
>> https://github.com/bminor/glibc/blob/ded9c1e525f2d69a81e61c34c29077fed7df658c/include/clone_internal.h
>> >.
>> >
>> > - Chris
>>
>> At this point, I think we should just adopt tst_clone() instead of
>> clone3() fallback.
>>
>
> Perhaps a simple approach is to define a raw system call for clone3
> and use it in all existing tests, and then add new tests if we plan to
> test the libc-like clone3 wrapper (with four args).
>
> Otherwise the new added 'NULL, NULL' arguments for current hacked
> clone3 makes no sense.
>
> static inline int ltp_clone3_raw(struct clone_args *args, size_t size)
> {
> return tst_syscall(__NR_clone3, args, size);
> }
>
> #ifdef HAVE_CLONE3_WRAPPER
> int ltp_clone3(struct clone_args *cl_args, size_t size,
> int (*fn)(void *), void *arg);
> #else
> static inline int ltp_clone3(struct clone_args *cl_args, size_t size,
> int (*fn)(void *), void *arg)
> {
> return -1;
> }
> #endif
>
> Btw, the above changes should be put in lapi/sched.h if we decide go this.
>
>
> --
> Regards,
> Li Wang
>
More information about the ltp
mailing list