Skip to content

Commit 62c69e8

Browse files
Hou Taoanakryiko
authored andcommitted
selftests/bpf: Use sys_pidfd_open() helper when possible
SYS_pidfd_open may be undefined for old glibc, so using sys_pidfd_open() helper defined in task_local_storage_helpers.h instead to fix potential build failure. And according to commit 7615d9e ("arch: wire-up pidfd_open()"), the syscall number of pidfd_open is always 434 except for alpha architure, so update the definition of __NR_pidfd_open accordingly. Signed-off-by: Hou Tao <houtao1@huawei.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20221011071249.3471760-1-houtao@huaweicloud.com
1 parent e94e0a2 commit 62c69e8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_iter.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <test_progs.h>
44
#include <unistd.h>
55
#include <sys/syscall.h>
6+
#include <task_local_storage_helpers.h>
67
#include "bpf_iter_ipv6_route.skel.h"
78
#include "bpf_iter_netlink.skel.h"
89
#include "bpf_iter_bpf_map.skel.h"
@@ -175,11 +176,6 @@ static void test_bpf_map(void)
175176
bpf_iter_bpf_map__destroy(skel);
176177
}
177178

178-
static int pidfd_open(pid_t pid, unsigned int flags)
179-
{
180-
return syscall(SYS_pidfd_open, pid, flags);
181-
}
182-
183179
static void check_bpf_link_info(const struct bpf_program *prog)
184180
{
185181
LIBBPF_OPTS(bpf_iter_attach_opts, opts);
@@ -295,8 +291,8 @@ static void test_task_pidfd(void)
295291
union bpf_iter_link_info linfo;
296292
int pidfd;
297293

298-
pidfd = pidfd_open(getpid(), 0);
299-
if (!ASSERT_GT(pidfd, 0, "pidfd_open"))
294+
pidfd = sys_pidfd_open(getpid(), 0);
295+
if (!ASSERT_GT(pidfd, 0, "sys_pidfd_open"))
300296
return;
301297

302298
memset(&linfo, 0, sizeof(linfo));

tools/testing/selftests/bpf/task_local_storage_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
#include <sys/types.h>
88

99
#ifndef __NR_pidfd_open
10+
#ifdef __alpha__
11+
#define __NR_pidfd_open 544
12+
#else
1013
#define __NR_pidfd_open 434
1114
#endif
15+
#endif
1216

1317
static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
1418
{

0 commit comments

Comments
 (0)