File: rewrite.c

package info (click to toggle)
golang-github-cilium-ebpf 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, bullseye-backports
  • size: 1,716 kB
  • sloc: ansic: 148; sh: 66; makefile: 24
file content (32 lines) | stat: -rw-r--r-- 684 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
/* This file tests rewriting constants from C compiled code.
 */

#include "common.h"

char __license[] __section("license") = "MIT";

struct bpf_map_def map_val __section("maps") = {
	.type        = 1,
	.key_size    = sizeof(unsigned int),
	.value_size  = sizeof(unsigned int),
	.max_entries = 1,
};

#define CONSTANT "constant"

#define LOAD_CONSTANT(param, var) asm("%0 = " param " ll" : "=r"(var))

__section("socket") int rewrite() {
	unsigned long acc = 0;
	LOAD_CONSTANT(CONSTANT, acc);
	return acc;
}

__section("socket/map") int rewrite_map() {
	unsigned int key    = 0;
	unsigned int *value = map_lookup_elem(&map_val, &key);
	if (!value) {
		return 0;
	}
	return *value;
}