tools/testing/selftests/bpf/libarena/include/libarena/userspace.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/libarena/include/libarena/userspace.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/libarena/include/libarena/userspace.h
Extension
.h
Size
2791 bytes
Lines
139
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: LGPL-2.1 OR BSD-2-Clause
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
#pragma once

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#include <bpf/libbpf.h>
#include <bpf/bpf.h>

static inline int libarena_run_prog(int prog_fd)
{
	LIBBPF_OPTS(bpf_test_run_opts, opts);
	int ret;

	ret = bpf_prog_test_run_opts(prog_fd, &opts);
	if (ret)
		return ret;

	return opts.retval;
}

static inline bool libarena_is_test_prog(const char *name)
{
	return strstr(name, "test_") == name;
}

static inline bool libarena_is_asan_test_prog(const char *name)
{
	return strstr(name, "asan_test") == name;
}

static inline bool libarena_is_parallel_test_prog(const char *name)
{
	return strstr(name, "parallel_test") == name;
}


static inline int libarena_run_prog_args(int prog_fd, void *args, size_t argsize)
{
	LIBBPF_OPTS(bpf_test_run_opts, opts);
	int ret;

	opts.ctx_in = args;
	opts.ctx_size_in = argsize;

	ret = bpf_prog_test_run_opts(prog_fd, &opts);

	return ret ?: opts.retval;
}

static inline int libarena_get_arena_base(int arena_get_info_fd,
					  void **arena_base)
{
	LIBBPF_OPTS(bpf_test_run_opts, opts);
	struct arena_get_info_args args = { .arena_base = NULL };
	int ret;

	opts.ctx_in = &args;
	opts.ctx_size_in = sizeof(args);

	ret = bpf_prog_test_run_opts(arena_get_info_fd, &opts);
	if (ret)
		return ret;
	if (opts.retval)
		return opts.retval;

	*arena_base = args.arena_base;
	return 0;
}

static inline int libarena_get_globals_pages(int arena_get_globals_fd,
					     size_t arena_all_pages,
					     u64 *globals_pages)
{
	size_t pgsize = sysconf(_SC_PAGESIZE);
	void *arena_base;
	ssize_t i;
	u8 *vec;
	int ret;

	ret = libarena_get_arena_base(arena_get_globals_fd, &arena_base);
	if (ret)
		return ret;

	if (!arena_base)
		return -EINVAL;

Annotation

Implementation Notes