提交 62c69e89 编写于 作者: H Hou Tao 提交者: Andrii Nakryiko

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 7615d9e1 ("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: NHou Tao <houtao1@huawei.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221011071249.3471760-1-houtao@huaweicloud.com
上级 e94e0a2d
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <test_progs.h> #include <test_progs.h>
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <task_local_storage_helpers.h>
#include "bpf_iter_ipv6_route.skel.h" #include "bpf_iter_ipv6_route.skel.h"
#include "bpf_iter_netlink.skel.h" #include "bpf_iter_netlink.skel.h"
#include "bpf_iter_bpf_map.skel.h" #include "bpf_iter_bpf_map.skel.h"
...@@ -175,11 +176,6 @@ static void test_bpf_map(void) ...@@ -175,11 +176,6 @@ static void test_bpf_map(void)
bpf_iter_bpf_map__destroy(skel); bpf_iter_bpf_map__destroy(skel);
} }
static int pidfd_open(pid_t pid, unsigned int flags)
{
return syscall(SYS_pidfd_open, pid, flags);
}
static void check_bpf_link_info(const struct bpf_program *prog) static void check_bpf_link_info(const struct bpf_program *prog)
{ {
LIBBPF_OPTS(bpf_iter_attach_opts, opts); LIBBPF_OPTS(bpf_iter_attach_opts, opts);
...@@ -295,8 +291,8 @@ static void test_task_pidfd(void) ...@@ -295,8 +291,8 @@ static void test_task_pidfd(void)
union bpf_iter_link_info linfo; union bpf_iter_link_info linfo;
int pidfd; int pidfd;
pidfd = pidfd_open(getpid(), 0); pidfd = sys_pidfd_open(getpid(), 0);
if (!ASSERT_GT(pidfd, 0, "pidfd_open")) if (!ASSERT_GT(pidfd, 0, "sys_pidfd_open"))
return; return;
memset(&linfo, 0, sizeof(linfo)); memset(&linfo, 0, sizeof(linfo));
......
...@@ -7,8 +7,12 @@ ...@@ -7,8 +7,12 @@
#include <sys/types.h> #include <sys/types.h>
#ifndef __NR_pidfd_open #ifndef __NR_pidfd_open
#ifdef __alpha__
#define __NR_pidfd_open 544
#else
#define __NR_pidfd_open 434 #define __NR_pidfd_open 434
#endif #endif
#endif
static inline int sys_pidfd_open(pid_t pid, unsigned int flags) static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册