kernel/trace/trace_selftest.c

Source file repositories/reference/linux-study-clean/kernel/trace/trace_selftest.c

File Facts

System
Linux kernel
Corpus path
kernel/trace/trace_selftest.c
Extension
.c
Size
35089 bytes
Lines
1568
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct fgraph_fixture {
	struct fgraph_ops gops;
	int store_size;
	const char *store_type_name;
	char error_str_buf[ERRSTR_BUFLEN];
	char *error_str;
};

static __init int store_entry(struct ftrace_graph_ent *trace,
			      struct fgraph_ops *gops,
			      struct ftrace_regs *fregs)
{
	struct fgraph_fixture *fixture = container_of(gops, struct fgraph_fixture, gops);
	const char *type = fixture->store_type_name;
	int size = fixture->store_size;
	void *p;

	p = fgraph_reserve_data(gops->idx, size);
	if (!p) {
		snprintf(fixture->error_str_buf, ERRSTR_BUFLEN,
			 "Failed to reserve %s\n", type);
		return 0;
	}

	switch (size) {
	case 1:
		*(char *)p = CHAR_NUMBER;
		break;
	case 2:
		*(short *)p = SHORT_NUMBER;
		break;
	case 4:
		*(int *)p = WORD_NUMBER;
		break;
	case 8:
		*(long long *)p = LONG_NUMBER;
		break;
	}

	return 1;
}

static __init void store_return(struct ftrace_graph_ret *trace,
				struct fgraph_ops *gops,
				struct ftrace_regs *fregs)
{
	struct fgraph_fixture *fixture = container_of(gops, struct fgraph_fixture, gops);
	const char *type = fixture->store_type_name;
	long long expect = 0;
	long long found = -1;
	int size;
	char *p;

	p = fgraph_retrieve_data(gops->idx, &size);
	if (!p) {
		snprintf(fixture->error_str_buf, ERRSTR_BUFLEN,
			 "Failed to retrieve %s\n", type);
		return;
	}
	if (fixture->store_size > size) {
		snprintf(fixture->error_str_buf, ERRSTR_BUFLEN,
			 "Retrieved size %d is smaller than expected %d\n",
			 size, (int)fixture->store_size);
		return;
	}

	switch (fixture->store_size) {
	case 1:
		expect = CHAR_NUMBER;
		found = *(char *)p;
		break;
	case 2:
		expect = SHORT_NUMBER;
		found = *(short *)p;
		break;
	case 4:
		expect = WORD_NUMBER;
		found = *(int *)p;
		break;
	case 8:
		expect = LONG_NUMBER;
		found = *(long long *)p;
		break;
	}

	if (found != expect) {
		snprintf(fixture->error_str_buf, ERRSTR_BUFLEN,
			 "%s returned not %lld but %lld\n", type, expect, found);
		return;
	}

Annotation

Implementation Notes