Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Move sys_pidfd_open() into task_local_storage_helpers.h

sys_pidfd_open() is defined twice in both test_bprm_opts.c and
test_local_storage.c, so move it to a common header file. And it will be
used in map_tests as well.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20220901061938.3789460-4-houtao@huaweicloud.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Hou Tao and committed by
Martin KaFai Lau
c710136e c89e843a

+20 -18
+1 -9
tools/testing/selftests/bpf/prog_tests/test_bprm_opts.c
··· 9 9 10 10 #include "bprm_opts.skel.h" 11 11 #include "network_helpers.h" 12 - 13 - #ifndef __NR_pidfd_open 14 - #define __NR_pidfd_open 434 15 - #endif 12 + #include "task_local_storage_helpers.h" 16 13 17 14 static const char * const bash_envp[] = { "TMPDIR=shouldnotbeset", NULL }; 18 - 19 - static inline int sys_pidfd_open(pid_t pid, unsigned int flags) 20 - { 21 - return syscall(__NR_pidfd_open, pid, flags); 22 - } 23 15 24 16 static int update_storage(int map_fd, int secureexec) 25 17 {
+1 -9
tools/testing/selftests/bpf/prog_tests/test_local_storage.c
··· 11 11 12 12 #include "local_storage.skel.h" 13 13 #include "network_helpers.h" 14 - 15 - #ifndef __NR_pidfd_open 16 - #define __NR_pidfd_open 434 17 - #endif 18 - 19 - static inline int sys_pidfd_open(pid_t pid, unsigned int flags) 20 - { 21 - return syscall(__NR_pidfd_open, pid, flags); 22 - } 14 + #include "task_local_storage_helpers.h" 23 15 24 16 static unsigned int duration; 25 17
+18
tools/testing/selftests/bpf/task_local_storage_helpers.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __TASK_LOCAL_STORAGE_HELPER_H 3 + #define __TASK_LOCAL_STORAGE_HELPER_H 4 + 5 + #include <unistd.h> 6 + #include <sys/syscall.h> 7 + #include <sys/types.h> 8 + 9 + #ifndef __NR_pidfd_open 10 + #define __NR_pidfd_open 434 11 + #endif 12 + 13 + static inline int sys_pidfd_open(pid_t pid, unsigned int flags) 14 + { 15 + return syscall(__NR_pidfd_open, pid, flags); 16 + } 17 + 18 + #endif