tools/testing/selftests/bpf/prog_tests/test_struct_ops_no_cfi.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_struct_ops_no_cfi.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/test_struct_ops_no_cfi.c
Extension
.c
Size
850 bytes
Lines
36
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
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
#include <testing_helpers.h>

static void load_bpf_test_no_cfi(void)
{
	int fd;
	int err;

	fd = open("bpf_test_no_cfi.ko", O_RDONLY);
	if (!ASSERT_GE(fd, 0, "open"))
		return;

	/* The module will try to register a struct_ops type without
	 * cfi_stubs and with cfi_stubs.
	 *
	 * The one without cfi_stub should fail. The module will be loaded
	 * successfully only if the result of the registration is as
	 * expected, or it fails.
	 */
	err = finit_module(fd, "", 0);
	close(fd);
	if (!ASSERT_OK(err, "finit_module"))
		return;

	err = delete_module("bpf_test_no_cfi", 0);
	ASSERT_OK(err, "delete_module");
}

void test_struct_ops_no_cfi(void)
{
	if (test__start_subtest("load_bpf_test_no_cfi"))
		load_bpf_test_no_cfi();
}

Annotation

Implementation Notes