tools/testing/selftests/bpf/progs/test_signed_loader_map.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_signed_loader_map.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/test_signed_loader_map.c
Extension
.c
Size
727 bytes
Lines
29
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>

/*
 * One explicit array map and no global variables, so the generated loader
 * has exactly one map to create (no .rodata/.bss). prog_tests/signed_loader.c
 * uses this to check that a signed loader ignores ctx-supplied max_entries:
 * the map must keep its attested size (4), not whatever the host puts in
 * the loader ctx.
 */
struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 4);
	__type(key, __u32);
	__type(value, __u64);
} amap SEC(".maps");

SEC("socket")
int probe(void *ctx)
{
	__u32 key = 0;
	__u64 *val = bpf_map_lookup_elem(&amap, &key);

	return val ? (int)*val : 0;
}

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

Annotation

Implementation Notes