Skip to content

Commit 3ae4c52

Browse files
alan-maguireborkmann
authored andcommitted
selftests/bpf: More open-coded gettid syscall cleanup
Commit 0e2fb01 ("selftests/bpf: Clean up open-coded gettid syscall invocations") addressed the issue that older libc may not have a gettid() function call wrapper for the associated syscall. A few more instances have crept into tests, use sys_gettid() instead, and poison raw gettid() usage to avoid future issues. Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20250911163056.543071-1-alan.maguire@oracle.com
1 parent 61ee2cc commit 3ae4c52

File tree

6 files changed

+8
-5
lines changed

6 files changed

+8
-5
lines changed

tools/testing/selftests/bpf/bpf_util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ static inline void bpf_strlcpy(char *dst, const char *src, size_t sz)
6767
#define sys_gettid() syscall(SYS_gettid)
6868
#endif
6969

70+
/* and poison usage to ensure it does not creep back in. */
71+
#pragma GCC poison gettid
72+
7073
#ifndef ENOTSUPP
7174
#define ENOTSUPP 524
7275
#endif

tools/testing/selftests/bpf/network_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ int append_tid(char *str, size_t sz)
457457
if (end + 8 > sz)
458458
return -1;
459459

460-
sprintf(&str[end], "%07d", gettid());
460+
sprintf(&str[end], "%07ld", sys_gettid());
461461
str[end + 7] = '\0';
462462

463463
return 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void test_read_cgroup_xattr(void)
4444
if (!ASSERT_OK_PTR(skel, "read_cgroupfs_xattr__open_and_load"))
4545
goto out;
4646

47-
skel->bss->target_pid = gettid();
47+
skel->bss->target_pid = sys_gettid();
4848

4949
if (!ASSERT_OK(read_cgroupfs_xattr__attach(skel), "read_cgroupfs_xattr__attach"))
5050
goto out;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void test_kernel_flag(void)
1616
if (!ASSERT_OK_PTR(lsm_skel, "lsm_skel"))
1717
return;
1818

19-
lsm_skel->bss->monitored_tid = gettid();
19+
lsm_skel->bss->monitored_tid = sys_gettid();
2020

2121
ret = test_kernel_flag__attach(lsm_skel);
2222
if (!ASSERT_OK(ret, "test_kernel_flag__attach"))

tools/testing/selftests/bpf/prog_tests/task_local_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int __tld_init_data_p(int map_fd)
158158
void *data_alloc = NULL;
159159
int err, tid_fd = -1;
160160

161-
tid_fd = syscall(SYS_pidfd_open, gettid(), O_EXCL);
161+
tid_fd = syscall(SYS_pidfd_open, sys_gettid(), O_EXCL);
162162
if (tid_fd < 0) {
163163
err = -errno;
164164
goto out;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void *test_task_local_data_basic_thread(void *arg)
6363
if (!ASSERT_OK_PTR(value2, "tld_get_data"))
6464
goto out;
6565

66-
tid = gettid();
66+
tid = sys_gettid();
6767

6868
*value0 = tid + 0;
6969
*value1 = tid + 1;

0 commit comments

Comments
 (0)