Path: blob/master/tools/testing/selftests/clone3/clone3_selftests.h
26285 views
/* SPDX-License-Identifier: GPL-2.0 */12#ifndef _CLONE3_SELFTESTS_H3#define _CLONE3_SELFTESTS_H45#define _GNU_SOURCE6#include <sched.h>7#include <linux/sched.h>8#include <linux/types.h>9#include <stdint.h>10#include <syscall.h>11#include <sys/wait.h>1213#include "../kselftest.h"1415#define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr)))1617#ifndef __NR_clone318#define __NR_clone3 43519#endif2021struct __clone_args {22__aligned_u64 flags;23__aligned_u64 pidfd;24__aligned_u64 child_tid;25__aligned_u64 parent_tid;26__aligned_u64 exit_signal;27__aligned_u64 stack;28__aligned_u64 stack_size;29__aligned_u64 tls;30__aligned_u64 set_tid;31__aligned_u64 set_tid_size;32__aligned_u64 cgroup;33};3435static pid_t sys_clone3(struct __clone_args *args, size_t size)36{37fflush(stdout);38fflush(stderr);39return syscall(__NR_clone3, args, size);40}4142static inline void test_clone3_supported(void)43{44pid_t pid;45struct __clone_args args = {};4647if (__NR_clone3 < 0)48ksft_exit_skip("clone3() syscall is not supported\n");4950/* Set to something that will always cause EINVAL. */51args.exit_signal = -1;52pid = sys_clone3(&args, sizeof(args));53if (!pid)54exit(EXIT_SUCCESS);5556if (pid > 0) {57wait(NULL);58ksft_exit_fail_msg(59"Managed to create child process with invalid exit_signal\n");60}6162if (errno == ENOSYS)63ksft_exit_skip("clone3() syscall is not supported\n");6465ksft_print_msg("clone3() syscall supported\n");66}6768#endif /* _CLONE3_SELFTESTS_H */697071