arch/mips/kernel/module.c
Source file repositories/reference/linux-study-clean/arch/mips/kernel/module.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/kernel/module.c- Extension
.c- Size
- 10968 bytes
- Lines
- 443
- Domain
- Architecture Layer
- Bucket
- arch/mips
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/extable.hlinux/moduleloader.hlinux/elf.hlinux/mm.hlinux/numa.hlinux/slab.hlinux/fs.hlinux/string.hlinux/kernel.hlinux/spinlock.hlinux/jump_label.hasm/jump_label.h
Detected Declarations
struct mips_hi16function apply_r_mips_32function apply_r_mips_26function apply_r_mips_hi16function free_relocation_chainfunction apply_r_mips_lo16function apply_r_mips_pcfunction apply_r_mips_pc16function apply_r_mips_pc21function apply_r_mips_pc26function apply_r_mips_64function apply_r_mips_higherfunction apply_r_mips_highestfunction reloc_handlerfunction __apply_relocatefunction apply_relocatefunction apply_relocate_addfunction module_finalizefunction module_arch_cleanup
Annotated Snippet
struct mips_hi16 {
struct mips_hi16 *next;
Elf_Addr *addr;
Elf_Addr value;
};
static LIST_HEAD(dbe_list);
static DEFINE_SPINLOCK(dbe_lock);
static void apply_r_mips_32(u32 *location, u32 base, Elf_Addr v)
{
*location = base + v;
}
static int apply_r_mips_26(struct module *me, u32 *location, u32 base,
Elf_Addr v)
{
if (v % 4) {
pr_err("module %s: dangerous R_MIPS_26 relocation\n",
me->name);
return -ENOEXEC;
}
if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
pr_err("module %s: relocation overflow\n",
me->name);
return -ENOEXEC;
}
*location = (*location & ~0x03ffffff) |
((base + (v >> 2)) & 0x03ffffff);
return 0;
}
static int apply_r_mips_hi16(struct module *me, u32 *location, Elf_Addr v,
bool rela)
{
struct mips_hi16 *n;
if (rela) {
*location = (*location & 0xffff0000) |
((((long long) v + 0x8000LL) >> 16) & 0xffff);
return 0;
}
/*
* We cannot relocate this one now because we don't know the value of
* the carry we need to add. Save the information, and let LO16 do the
* actual relocation.
*/
n = kmalloc_obj(*n);
if (!n)
return -ENOMEM;
n->addr = (Elf_Addr *)location;
n->value = v;
n->next = me->arch.r_mips_hi16_list;
me->arch.r_mips_hi16_list = n;
return 0;
}
static void free_relocation_chain(struct mips_hi16 *l)
{
struct mips_hi16 *next;
while (l) {
next = l->next;
kfree(l);
l = next;
}
}
static int apply_r_mips_lo16(struct module *me, u32 *location,
u32 base, Elf_Addr v, bool rela)
{
unsigned long insnlo = base;
struct mips_hi16 *l;
Elf_Addr val, vallo;
if (rela) {
*location = (*location & 0xffff0000) | (v & 0xffff);
return 0;
}
/* Sign extend the addend we extract from the lo insn. */
vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000;
if (me->arch.r_mips_hi16_list != NULL) {
Annotation
- Immediate include surface: `linux/extable.h`, `linux/moduleloader.h`, `linux/elf.h`, `linux/mm.h`, `linux/numa.h`, `linux/slab.h`, `linux/fs.h`, `linux/string.h`.
- Detected declarations: `struct mips_hi16`, `function apply_r_mips_32`, `function apply_r_mips_26`, `function apply_r_mips_hi16`, `function free_relocation_chain`, `function apply_r_mips_lo16`, `function apply_r_mips_pc`, `function apply_r_mips_pc16`, `function apply_r_mips_pc21`, `function apply_r_mips_pc26`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.