security/selinux/ss/ebitmap.c
Source file repositories/reference/linux-study-clean/security/selinux/ss/ebitmap.c
File Facts
- System
- Linux kernel
- Corpus path
security/selinux/ss/ebitmap.c- Extension
.c- Size
- 12643 bytes
- Lines
- 604
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/slab.hlinux/errno.hlinux/jhash.hnet/netlabel.hebitmap.hpolicydb.h
Detected Declarations
function ebitmap_equalfunction ebitmap_cpyfunction ebitmap_andfunction ebitmap_for_each_positive_bitfunction ebitmap_netlbl_exportfunction ebitmap_netlbl_importfunction ebitmap_containsfunction ebitmap_get_highest_set_bitfunction ebitmap_get_bitfunction ebitmap_set_bitfunction ebitmap_destroyfunction ebitmap_readfunction ebitmap_writefunction ebitmap_hashfunction ebitmap_cache_init
Annotated Snippet
if (!new) {
ebitmap_destroy(dst);
return -ENOMEM;
}
new->startbit = n->startbit;
memcpy(new->maps, n->maps, EBITMAP_SIZE / 8);
new->next = NULL;
if (prev)
prev->next = new;
else
dst->node = new;
prev = new;
n = n->next;
}
dst->highbit = src->highbit;
return 0;
}
int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1,
const struct ebitmap *e2)
{
struct ebitmap_node *n;
u32 bit;
int rc;
ebitmap_init(dst);
ebitmap_for_each_positive_bit(e1, n, bit)
{
if (ebitmap_get_bit(e2, bit)) {
rc = ebitmap_set_bit(dst, bit, 1);
if (rc < 0)
return rc;
}
}
return 0;
}
#ifdef CONFIG_NETLABEL
/**
* ebitmap_netlbl_export - Export an ebitmap into a NetLabel category bitmap
* @ebmap: the ebitmap to export
* @catmap: the NetLabel category bitmap
*
* Description:
* Export a SELinux extensibile bitmap into a NetLabel category bitmap.
* Returns zero on success, negative values on error.
*
*/
int ebitmap_netlbl_export(struct ebitmap *ebmap,
struct netlbl_lsm_catmap **catmap)
{
struct ebitmap_node *e_iter = ebmap->node;
unsigned long e_map;
u32 offset;
unsigned int iter;
int rc;
if (e_iter == NULL) {
*catmap = NULL;
return 0;
}
if (*catmap != NULL)
netlbl_catmap_free(*catmap);
*catmap = NULL;
while (e_iter) {
offset = e_iter->startbit;
for (iter = 0; iter < EBITMAP_UNIT_NUMS; iter++) {
e_map = e_iter->maps[iter];
if (e_map != 0) {
rc = netlbl_catmap_setlong(catmap, offset,
e_map, GFP_ATOMIC);
if (rc != 0)
goto netlbl_export_failure;
}
offset += EBITMAP_UNIT_SIZE;
}
e_iter = e_iter->next;
}
return 0;
netlbl_export_failure:
netlbl_catmap_free(*catmap);
return -ENOMEM;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/errno.h`, `linux/jhash.h`, `net/netlabel.h`, `ebitmap.h`, `policydb.h`.
- Detected declarations: `function ebitmap_equal`, `function ebitmap_cpy`, `function ebitmap_and`, `function ebitmap_for_each_positive_bit`, `function ebitmap_netlbl_export`, `function ebitmap_netlbl_import`, `function ebitmap_contains`, `function ebitmap_get_highest_set_bit`, `function ebitmap_get_bit`, `function ebitmap_set_bit`.
- Atlas domain: Core OS / Security And Isolation.
- 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.