File: variables.c

package info (click to toggle)
golang-github-cilium-ebpf 0.17.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,684 kB
  • sloc: ansic: 1,259; makefile: 127; python: 113; awk: 29; sh: 24
file content (37 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download
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
#include "common.h"

// Should not appear in CollectionSpec.Variables.
__hidden volatile uint32_t hidden;

// Weak variables can be overridden by non-weak symbols when linking BPF
// programs using bpftool. Make sure they appear in CollectionSpec.Variables.
__weak volatile uint32_t weak __section(".data.weak");

// Ensure vars are referenced so they are not culled by the loader.
__section("socket") int set_vars() {
	hidden = 0xbeef1;
	weak   = 0xbeef2;
	return 0;
}

volatile uint32_t var_bss __section(".bss");
__section("socket") int get_bss() {
	return var_bss;
}
volatile uint32_t var_data __section(".data");
__section("socket") int get_data() {
	return var_data;
}
volatile const uint32_t var_rodata __section(".rodata");
__section("socket") int get_rodata() {
	return var_rodata;
}

struct var_struct_t {
	uint64_t a;
	uint64_t b;
};
volatile struct var_struct_t var_struct __section(".data.struct");
__section("socket") int check_struct() {
	return var_struct.a == 0xa && var_struct.b == 0xb;
}