File: test_task_local_data.c

package info (click to toggle)
linux 6.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,742,096 kB
  • sloc: ansic: 26,781,576; asm: 272,087; sh: 148,750; python: 79,244; makefile: 57,741; perl: 36,527; xml: 19,542; cpp: 5,911; yacc: 4,939; lex: 2,950; awk: 1,607; sed: 30; ruby: 25
file content (65 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: GPL-2.0

#include <vmlinux.h>
#include <errno.h>
#include <bpf/bpf_helpers.h>

#include "task_local_data.bpf.h"

struct tld_keys {
	tld_key_t value0;
	tld_key_t value1;
	tld_key_t value2;
	tld_key_t value_not_exist;
};

struct test_tld_struct {
	__u64 a;
	__u64 b;
	__u64 c;
	__u64 d;
};

int test_value0;
int test_value1;
struct test_tld_struct test_value2;

SEC("syscall")
int task_main(void *ctx)
{
	struct tld_object tld_obj;
	struct test_tld_struct *struct_p;
	struct task_struct *task;
	int err, *int_p;

	task = bpf_get_current_task_btf();
	err = tld_object_init(task, &tld_obj);
	if (err)
		return 1;

	int_p = tld_get_data(&tld_obj, value0, "value0", sizeof(int));
	if (int_p)
		test_value0 = *int_p;
	else
		return 2;

	int_p = tld_get_data(&tld_obj, value1, "value1", sizeof(int));
	if (int_p)
		test_value1 = *int_p;
	else
		return 3;

	struct_p = tld_get_data(&tld_obj, value2, "value2", sizeof(struct test_tld_struct));
	if (struct_p)
		test_value2 = *struct_p;
	else
		return 4;

	int_p = tld_get_data(&tld_obj, value_not_exist, "value_not_exist", sizeof(int));
	if (int_p)
		return 5;

	return 0;
}

char _license[] SEC("license") = "GPL";