lib/codetag.c
Source file repositories/reference/linux-study-clean/lib/codetag.c
File Facts
- System
- Linux kernel
- Corpus path
lib/codetag.c- Extension
.c- Size
- 9050 bytes
- Lines
- 406
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/codetag.hlinux/idr.hlinux/kallsyms.hlinux/module.hlinux/seq_buf.hlinux/slab.hlinux/vmalloc.h
Detected Declarations
struct codetag_typestruct codetag_rangestruct codetag_modulefunction codetag_lock_module_listfunction codetag_trylock_module_listfunction codetag_get_ct_iterfunction codetag_to_textfunction range_sizefunction get_section_rangefunction codetag_module_initfunction codetag_needs_module_sectionfunction codetag_free_module_sectionsfunction codetag_module_replacedfunction codetag_load_modulefunction codetag_unload_modulefunction idr_for_each_entry_ulfunction codetag_register_type
Annotated Snippet
struct codetag_type {
struct list_head link;
unsigned int count;
struct idr mod_idr;
/*
* protects mod_idr, next_mod_seq,
* iter->mod_seq and cmod->mod_seq
*/
struct rw_semaphore mod_lock;
struct codetag_type_desc desc;
/* generates unique sequence number for module load */
unsigned long next_mod_seq;
};
struct codetag_range {
struct codetag *start;
struct codetag *stop;
};
struct codetag_module {
struct module *mod;
struct codetag_range range;
unsigned long mod_seq;
};
static DEFINE_MUTEX(codetag_lock);
static LIST_HEAD(codetag_types);
void codetag_lock_module_list(struct codetag_type *cttype, bool lock)
{
if (lock)
down_read(&cttype->mod_lock);
else
up_read(&cttype->mod_lock);
}
bool codetag_trylock_module_list(struct codetag_type *cttype)
{
return down_read_trylock(&cttype->mod_lock) != 0;
}
struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttype)
{
struct codetag_iterator iter = {
.cttype = cttype,
.cmod = NULL,
.mod_id = 0,
.ct = NULL,
.mod_seq = 0,
};
return iter;
}
static inline struct codetag *get_first_module_ct(struct codetag_module *cmod)
{
return cmod->range.start < cmod->range.stop ? cmod->range.start : NULL;
}
static inline
struct codetag *get_next_module_ct(struct codetag_iterator *iter)
{
struct codetag *res = (struct codetag *)
((char *)iter->ct + iter->cttype->desc.tag_size);
return res < iter->cmod->range.stop ? res : NULL;
}
struct codetag *codetag_next_ct(struct codetag_iterator *iter)
{
struct codetag_type *cttype = iter->cttype;
struct codetag_module *cmod;
struct codetag *ct;
lockdep_assert_held(&cttype->mod_lock);
if (unlikely(idr_is_empty(&cttype->mod_idr)))
return NULL;
ct = NULL;
while (true) {
cmod = idr_find(&cttype->mod_idr, iter->mod_id);
/* If module was removed move to the next one */
if (!cmod)
cmod = idr_get_next_ul(&cttype->mod_idr,
&iter->mod_id);
/* Exit if no more modules */
if (!cmod)
Annotation
- Immediate include surface: `linux/codetag.h`, `linux/idr.h`, `linux/kallsyms.h`, `linux/module.h`, `linux/seq_buf.h`, `linux/slab.h`, `linux/vmalloc.h`.
- Detected declarations: `struct codetag_type`, `struct codetag_range`, `struct codetag_module`, `function codetag_lock_module_list`, `function codetag_trylock_module_list`, `function codetag_get_ct_iter`, `function codetag_to_text`, `function range_size`, `function get_section_range`, `function codetag_module_init`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration 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.