Add syscall clone3

This commit is contained in:
Jianfeng Jiang
2023-12-14 02:33:23 +00:00
committed by Tate, Hongliang Tian
parent a5707b4ddc
commit 07fbbcfd8c
11 changed files with 220 additions and 39 deletions

View File

@ -10,6 +10,7 @@ REGRESSION_BUILD_DIR ?= $(INITRAMFS)/regression
# These test apps are sorted by name
TEST_APPS := \
clone3 \
eventfd2 \
execve \
file_io \

View File

@ -0,0 +1,5 @@
# SPDX-License-Identifier: MPL-2.0
include ../test_common.mk
EXTRA_C_FLAGS :=

View File

@ -0,0 +1,66 @@
// SPDX-License-Identifier: MPL-2.0
#define _GNU_SOURCE
#include <err.h>
#include <errno.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <sched.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>
#ifndef CLONE_PIDFD
#define CLONE_PIDFD 0x00001000
#endif
static pid_t sys_clone3(struct clone_args *args)
{
return syscall(SYS_clone3, args, sizeof(struct clone_args));
}
#define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr)))
int main(int argc, char *argv[])
{
int pidfd = -1;
pid_t parent_tid = -1, pid = -1;
struct clone_args args = { 0 };
args.parent_tid = ptr_to_u64(&parent_tid); /* CLONE_PARENT_SETTID */
args.flags = CLONE_PARENT_SETTID;
args.exit_signal = SIGCHLD;
pid = sys_clone3(&args);
if (pid < 0) {
printf("%s - Failed to create new process\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (pid == 0) {
printf("Child process with pid %d\n", getpid());
exit(EXIT_SUCCESS);
}
printf("Parent process: child's pid %d\n", pid);
printf("Parent process: child's pid %d in parent_tid\n",
*(pid_t *)args.parent_tid);
waitpid(pid, NULL, 0);
if (pid != *(pid_t *)args.parent_tid)
exit(EXIT_FAILURE);
close(pidfd);
return 0;
}

View File

@ -8,7 +8,22 @@ SCRIPT_DIR=/regression
cd ${SCRIPT_DIR}/..
echo "Start process test......"
tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello pty/open_pty getpid/getpid eventfd2/eventfd2 mmap/map_shared_anon"
# These test programs are sorted by name.
tests="
clone3/clone_process
execve/execve
eventfd2/eventfd2
fork/fork
fork_c/fork
getpid/getpid
hello_pie/hello
hello_world/hello_world
mmap/map_shared_anon
pthread/pthread_test
pty/open_pty
signal_c/signal_test
"
for testcase in ${tests}
do
echo "Running test ${testcase}......"