kernel/module/kallsyms.c

Source file repositories/reference/linux-study-clean/kernel/module/kallsyms.c

File Facts

System
Linux kernel
Corpus path
kernel/module/kallsyms.c
Extension
.c
Size
13433 bytes
Lines
497
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: exported/initcall integration point
Status
integration 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

if (thisval <= addr && thisval > bestval) {
			best = i;
			bestval = thisval;
		}
		if (thisval > addr && thisval < nextval)
			nextval = thisval;
	}

	if (!best)
		return NULL;

	if (size)
		*size = nextval - bestval;
	if (offset)
		*offset = addr - bestval;

	return kallsyms_symbol_name(kallsyms, best);
}

void * __weak dereference_module_function_descriptor(struct module *mod,
						     void *ptr)
{
	return ptr;
}

/*
 * For kallsyms to ask for address resolution.  NULL means not found.  Careful
 * not to lock to avoid deadlock on oopses, RCU is enough.
 */
int module_address_lookup(unsigned long addr,
			  unsigned long *size,
			  unsigned long *offset,
			  char **modname,
			  const unsigned char **modbuildid,
			  char *namebuf)
{
	const char *sym;
	int ret = 0;
	struct module *mod;

	guard(rcu)();
	mod = __module_address(addr);
	if (mod) {
		if (modname)
			*modname = mod->name;
		if (modbuildid)
			*modbuildid = module_buildid(mod);

		sym = find_kallsyms_symbol(mod, addr, size, offset);

		if (sym)
			ret = strscpy(namebuf, sym, KSYM_NAME_LEN);
	}
	return ret;
}

int lookup_module_symbol_name(unsigned long addr, char *symname)
{
	struct module *mod;

	guard(rcu)();
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (within_module(addr, mod)) {
			const char *sym;

			sym = find_kallsyms_symbol(mod, addr, NULL, NULL);
			if (!sym)
				goto out;

			strscpy(symname, sym, KSYM_NAME_LEN);
			return 0;
		}
	}
out:
	return -ERANGE;
}

int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
		       char *name, char *module_name, int *exported)
{
	struct module *mod;

	guard(rcu)();
	list_for_each_entry_rcu(mod, &modules, list) {
		struct mod_kallsyms *kallsyms;

		if (mod->state == MODULE_STATE_UNFORMED)
			continue;

Annotation

Implementation Notes