1 // SPDX-License-Identifier: GPL-2.0 2 3 #include <vmlinux.h> 4 #include <errno.h> 5 #include <bpf/bpf_helpers.h> 6 7 #include "task_local_data.bpf.h" 8 9 struct tld_keys { 10 tld_key_t value0; 11 tld_key_t value1; 12 tld_key_t value2; 13 tld_key_t value_not_exist; 14 }; 15 16 struct test_tld_struct { 17 __u64 a; 18 __u64 b; 19 __u64 c; 20 __u64 d; 21 }; 22 23 int test_value0; 24 int test_value1; 25 struct test_tld_struct test_value2; 26 27 SEC("syscall") 28 int task_main(void *ctx) 29 { 30 struct tld_object tld_obj; 31 struct test_tld_struct *struct_p; 32 struct task_struct *task; 33 int err, *int_p; 34 35 task = bpf_get_current_task_btf(); 36 err = tld_object_init(task, &tld_obj); 37 if (err) 38 return 1; 39 40 int_p = tld_get_data(&tld_obj, value0, "value0", sizeof(int)); 41 if (int_p) 42 test_value0 = *int_p; 43 else 44 return 2; 45 46 int_p = tld_get_data(&tld_obj, value1, "value1", sizeof(int)); 47 if (int_p) 48 test_value1 = *int_p; 49 else 50 return 3; 51 52 struct_p = tld_get_data(&tld_obj, value2, "value2", sizeof(struct test_tld_struct)); 53 if (struct_p) 54 test_value2 = *struct_p; 55 else 56 return 4; 57 58 int_p = tld_get_data(&tld_obj, value_not_exist, "value_not_exist", sizeof(int)); 59 if (int_p) 60 return 5; 61 62 return 0; 63 } 64 65 char _license[] SEC("license") = "GPL"; 66