1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021. Huawei Technologies Co., Ltd */
3 #include <linux/types.h>
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
8 #define STRNCMP_STR_SZ 4096
10 /* Will be updated by benchmark before program loading */
11 const volatile unsigned int cmp_str_len = 1;
12 const char target[STRNCMP_STR_SZ];
15 char str[STRNCMP_STR_SZ];
17 char _license[] SEC("license") = "GPL";
19 static __always_inline int local_strncmp(const char *s1, unsigned int sz,
25 for (i = 0; i < sz; i++) {
26 /* E.g. 0xff > 0x31 */
27 ret = (unsigned char)s1[i] - (unsigned char)s2[i];
35 SEC("tp/syscalls/sys_enter_getpgid")
36 int strncmp_no_helper(void *ctx)
38 if (local_strncmp(str, cmp_str_len + 1, target) < 0)
39 __sync_add_and_fetch(&hits, 1);
43 SEC("tp/syscalls/sys_enter_getpgid")
44 int strncmp_helper(void *ctx)
46 if (bpf_strncmp(str, cmp_str_len + 1, target) < 0)
47 __sync_add_and_fetch(&hits, 1);