tools/perf/util/syscalltbl.c

Source file repositories/reference/linux-study-clean/tools/perf/util/syscalltbl.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/syscalltbl.c
Extension
.c
Size
3070 bytes
Lines
134
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: syscall or user/kernel boundary
Status
core 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

struct syscall_cmp_key {
	const char *name;
	const char *const *tbl;
};

static int syscallcmpname(const void *vkey, const void *ventry)
{
	const struct syscall_cmp_key *key = vkey;
	const uint16_t *entry = ventry;

	return strcmp(key->name, key->tbl[*entry]);
}

int syscalltbl__id(int e_machine, const char *name)
{
	const struct syscalltbl *table = find_table(e_machine);
	struct syscall_cmp_key key;
	const uint16_t *id;

	if (!table)
		return -1;

	key.name = name;
	key.tbl = table->num_to_name;
	id = bsearch(&key, table->sorted_names, table->sorted_names_len,
		     sizeof(table->sorted_names[0]), syscallcmpname);

	return id ? *id : -1;
}

int syscalltbl__num_idx(int e_machine)
{
	const struct syscalltbl *table = find_table(e_machine);

	if (!table)
		return 0;

	return table->sorted_names_len;
}

int syscalltbl__id_at_idx(int e_machine, int idx)
{
	const struct syscalltbl *table = find_table(e_machine);

	if (!table)
		return -1;

	assert(idx >= 0 && idx < table->sorted_names_len);
	return table->sorted_names[idx];
}

int syscalltbl__strglobmatch_next(int e_machine, const char *syscall_glob, int *idx)
{
	const struct syscalltbl *table = find_table(e_machine);

	for (int i = *idx + 1; table && i < table->sorted_names_len; ++i) {
		const char *name = table->num_to_name[table->sorted_names[i]];

		if (strglobmatch(name, syscall_glob)) {
			*idx = i;
			return table->sorted_names[i];
		}
	}

	return -1;
}

int syscalltbl__strglobmatch_first(int e_machine, const char *syscall_glob, int *idx)
{
	*idx = -1;
	return syscalltbl__strglobmatch_next(e_machine, syscall_glob, idx);
}

Annotation

Implementation Notes