ipc/util.c
Source file repositories/reference/linux-study-clean/ipc/util.c
File Facts
- System
- Linux kernel
- Corpus path
ipc/util.c- Extension
.c- Size
- 24726 bytes
- Lines
- 929
- Domain
- Core OS
- Bucket
- IPC
- 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.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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/mm.hlinux/shm.hlinux/init.hlinux/msg.hlinux/vmalloc.hlinux/slab.hlinux/notifier.hlinux/capability.hlinux/highuid.hlinux/security.hlinux/rcupdate.hlinux/workqueue.hlinux/seq_file.hlinux/proc_fs.hlinux/audit.hlinux/nsproxy.hlinux/rwsem.hlinux/memory.hlinux/ipc_namespace.hlinux/rhashtable.hlinux/log2.hasm/unistd.hutil.h
Detected Declarations
struct ipc_proc_ifacestruct ipc_proc_iterfunction resourcesfunction rangefunction ipc_init_proc_interfacefunction ipc_idr_allocfunction ipc_obtain_object_idrfunction ipc_rcu_putreffunction ipcget_newfunction sys_msggetfunction ipcget_publicfunction ipc_kht_removefunction ipc_search_maxidxfunction ipc_rmidfunction ipc_set_key_privatefunction ipc_rcu_getreffunction ipc_rcu_putreffunction ipcpermsfunction userspacefunction ipc64_perm_to_ipc_permfunction sys_msggetfunction ipc_update_permfunction ipc_parse_versionfunction ipc_lock_objectfunction sysvipc_proc_stopfunction sysvipc_proc_showfunction sysvipc_proc_openfunction sysvipc_proc_releasemodule init ipc_init
Annotated Snippet
device_initcall(ipc_init);
static const struct rhashtable_params ipc_kht_params = {
.head_offset = offsetof(struct kern_ipc_perm, khtnode),
.key_offset = offsetof(struct kern_ipc_perm, key),
.key_len = sizeof_field(struct kern_ipc_perm, key),
.automatic_shrinking = true,
};
/**
* ipc_init_ids - initialise ipc identifiers
* @ids: ipc identifier set
*
* Set up the sequence range to use for the ipc identifier range (limited
* below ipc_mni) then initialise the keys hashtable and ids idr.
*/
void ipc_init_ids(struct ipc_ids *ids)
{
ids->in_use = 0;
ids->seq = 0;
init_rwsem(&ids->rwsem);
rhashtable_init(&ids->key_ht, &ipc_kht_params);
idr_init(&ids->ipcs_idr);
ids->max_idx = -1;
ids->last_idx = -1;
#ifdef CONFIG_CHECKPOINT_RESTORE
ids->next_id = -1;
#endif
}
#ifdef CONFIG_PROC_FS
static const struct proc_ops sysvipc_proc_ops;
/**
* ipc_init_proc_interface - create a proc interface for sysipc types using a seq_file interface.
* @path: Path in procfs
* @header: Banner to be printed at the beginning of the file.
* @ids: ipc id table to iterate.
* @show: show routine.
*/
void __init ipc_init_proc_interface(const char *path, const char *header,
int ids, int (*show)(struct seq_file *, void *))
{
struct proc_dir_entry *pde;
struct ipc_proc_iface *iface;
iface = kmalloc_obj(*iface);
if (!iface)
return;
iface->path = path;
iface->header = header;
iface->ids = ids;
iface->show = show;
pde = proc_create_data(path,
S_IRUGO, /* world readable */
NULL, /* parent dir */
&sysvipc_proc_ops,
iface);
if (!pde)
kfree(iface);
}
#endif
/**
* ipc_findkey - find a key in an ipc identifier set
* @ids: ipc identifier set
* @key: key to find
*
* Returns the locked pointer to the ipc structure if found or NULL
* otherwise. If key is found ipc points to the owning ipc structure
*
* Called with writer ipc_ids.rwsem held.
*/
static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key)
{
struct kern_ipc_perm *ipcp;
ipcp = rhashtable_lookup_fast(&ids->key_ht, &key,
ipc_kht_params);
if (!ipcp)
return NULL;
rcu_read_lock();
ipc_lock_object(ipcp);
return ipcp;
}
/*
* Insert new IPC object into idr tree, and set sequence number and id
* in the correct order.
Annotation
- Immediate include surface: `linux/mm.h`, `linux/shm.h`, `linux/init.h`, `linux/msg.h`, `linux/vmalloc.h`, `linux/slab.h`, `linux/notifier.h`, `linux/capability.h`.
- Detected declarations: `struct ipc_proc_iface`, `struct ipc_proc_iter`, `function resources`, `function range`, `function ipc_init_proc_interface`, `function ipc_idr_alloc`, `function ipc_obtain_object_idr`, `function ipc_rcu_putref`, `function ipcget_new`, `function sys_msgget`.
- Atlas domain: Core OS / IPC.
- 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.