scripts/gendwarfksyms/kabi.c
Source file repositories/reference/linux-study-clean/scripts/gendwarfksyms/kabi.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/gendwarfksyms/kabi.c- Extension
.c- Size
- 7956 bytes
- Lines
- 374
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstdio.hgendwarfksyms.h
Detected Declarations
struct ruleenum kabi_rule_typefunction rule_values_hashfunction rule_hashfunction kabi_read_rulesfunction hash_for_each_possiblefunction kabi_is_declonlyfunction get_ulong_valuefunction kabi_is_enumerator_ignoredfunction kabi_get_enumerator_valuefunction kabi_get_byte_sizefunction kabi_get_type_stringfunction kabi_freefunction hash_for_each_safe
Annotated Snippet
struct rule {
enum kabi_rule_type type;
const char *target;
const char *value;
struct hlist_node hash;
};
/* { type, target } -> struct rule */
static HASHTABLE_DEFINE(rules, 1 << RULE_HASH_BITS);
static inline unsigned int rule_values_hash(enum kabi_rule_type type,
const char *target)
{
return hash_32(type) ^ hash_str(target);
}
static inline unsigned int rule_hash(const struct rule *rule)
{
return rule_values_hash(rule->type, rule->target);
}
static inline const char *get_rule_field(const char **pos, ssize_t *left)
{
const char *start = *pos;
size_t len;
if (*left <= 0)
error("unexpected end of kABI rules");
len = strnlen(start, *left) + 1;
*pos += len;
*left -= len;
return start;
}
void kabi_read_rules(int fd)
{
GElf_Shdr shdr_mem;
GElf_Shdr *shdr;
Elf_Data *rule_data = NULL;
Elf_Scn *scn;
Elf *elf;
size_t shstrndx;
const char *rule_str;
ssize_t left;
int i;
const struct {
enum kabi_rule_type type;
const char *tag;
} rule_types[] = {
{
.type = KABI_RULE_TYPE_DECLONLY,
.tag = KABI_RULE_TAG_DECLONLY,
},
{
.type = KABI_RULE_TYPE_ENUMERATOR_IGNORE,
.tag = KABI_RULE_TAG_ENUMERATOR_IGNORE,
},
{
.type = KABI_RULE_TYPE_ENUMERATOR_VALUE,
.tag = KABI_RULE_TAG_ENUMERATOR_VALUE,
},
{
.type = KABI_RULE_TYPE_BYTE_SIZE,
.tag = KABI_RULE_TAG_BYTE_SIZE,
},
{
.type = KABI_RULE_TYPE_TYPE_STRING,
.tag = KABI_RULE_TAG_TYPE_STRING,
},
};
if (!stable)
return;
if (elf_version(EV_CURRENT) != EV_CURRENT)
error("elf_version failed: %s", elf_errmsg(-1));
elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
if (!elf)
error("elf_begin failed: %s", elf_errmsg(-1));
if (elf_getshdrstrndx(elf, &shstrndx) < 0)
error("elf_getshdrstrndx failed: %s", elf_errmsg(-1));
scn = elf_nextscn(elf, NULL);
while (scn) {
Annotation
- Immediate include surface: `errno.h`, `stdio.h`, `gendwarfksyms.h`.
- Detected declarations: `struct rule`, `enum kabi_rule_type`, `function rule_values_hash`, `function rule_hash`, `function kabi_read_rules`, `function hash_for_each_possible`, `function kabi_is_declonly`, `function get_ulong_value`, `function kabi_is_enumerator_ignored`, `function kabi_get_enumerator_value`.
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: source implementation candidate.
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.