ipc/util.h
Source file repositories/reference/linux-study-clean/ipc/util.h
File Facts
- System
- Linux kernel
- Corpus path
ipc/util.h- Extension
.h- Size
- 8996 bytes
- Lines
- 293
- Domain
- Core OS
- Bucket
- IPC
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/unistd.hlinux/err.hlinux/ipc_namespace.hlinux/pid.hlinux/compat.h
Detected Declarations
struct ipc_namespacestruct pid_namespacestruct ipc_paramsstruct ipc_opsstruct seq_filestruct ipc_idsstruct compat_ipc_permfunction mq_clear_sbinfofunction sem_init_nsfunction shm_init_nsfunction ipc_get_maxidxfunction ipc_update_pidfunction ipc_checkidfunction ipc_lock_objectfunction ipc_unlock_objectfunction ipc_assert_locked_objectfunction ipc_unlockfunction ipc_valid_objectfunction sem_check_semmnifunction compat_ipc_parse_version
Annotated Snippet
struct ipc_params {
key_t key;
int flg;
union {
size_t size; /* for shared memories */
int nsems; /* for semaphores */
} u; /* holds the getnew() specific param */
};
/*
* Structure that holds some ipc operations. This structure is used to unify
* the calls to sys_msgget(), sys_semget(), sys_shmget()
* . routine to call to create a new ipc object. Can be one of newque,
* newary, newseg
* . routine to call to check permissions for a new ipc object.
* Can be one of security_msg_associate, security_sem_associate,
* security_shm_associate
* . routine to call for an extra check if needed
*/
struct ipc_ops {
int (*getnew)(struct ipc_namespace *, struct ipc_params *);
int (*associate)(struct kern_ipc_perm *, int);
int (*more_checks)(struct kern_ipc_perm *, struct ipc_params *);
};
struct seq_file;
struct ipc_ids;
void ipc_init_ids(struct ipc_ids *ids);
#ifdef CONFIG_PROC_FS
void __init ipc_init_proc_interface(const char *path, const char *header,
int ids, int (*show)(struct seq_file *, void *));
struct pid_namespace *ipc_seq_pid_ns(struct seq_file *);
#else
#define ipc_init_proc_interface(path, header, ids, show) do {} while (0)
#endif
#define IPC_SEM_IDS 0
#define IPC_MSG_IDS 1
#define IPC_SHM_IDS 2
#define ipcid_to_idx(id) ((id) & IPCMNI_IDX_MASK)
#define ipcid_to_seqx(id) ((id) >> ipcmni_seq_shift())
#define ipcid_seq_max() (INT_MAX >> ipcmni_seq_shift())
/* must be called with ids->rwsem acquired for writing */
int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int);
/* must be called with both locks acquired. */
void ipc_rmid(struct ipc_ids *, struct kern_ipc_perm *);
/* must be called with both locks acquired. */
void ipc_set_key_private(struct ipc_ids *, struct kern_ipc_perm *);
/* must be called with ipcp locked */
int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg);
/**
* ipc_get_maxidx - get the highest assigned index
* @ids: ipc identifier set
*
* The function returns the highest assigned index for @ids. The function
* doesn't scan the idr tree, it uses a cached value.
*
* Called with ipc_ids.rwsem held for reading.
*/
static inline int ipc_get_maxidx(struct ipc_ids *ids)
{
if (ids->in_use == 0)
return -1;
if (ids->in_use == ipc_mni)
return ipc_mni - 1;
return ids->max_idx;
}
/*
* For allocation that need to be freed by RCU.
* Objects are reference counted, they start with reference count 1.
* getref increases the refcount, the putref call that reduces the recount
* to 0 schedules the rcu destruction. Caller must guarantee locking.
*
* refcount is initialized by ipc_addid(), before that point call_rcu()
* must be used.
*/
bool ipc_rcu_getref(struct kern_ipc_perm *ptr);
void ipc_rcu_putref(struct kern_ipc_perm *ptr,
void (*func)(struct rcu_head *head));
Annotation
- Immediate include surface: `linux/unistd.h`, `linux/err.h`, `linux/ipc_namespace.h`, `linux/pid.h`, `linux/compat.h`.
- Detected declarations: `struct ipc_namespace`, `struct pid_namespace`, `struct ipc_params`, `struct ipc_ops`, `struct seq_file`, `struct ipc_ids`, `struct compat_ipc_perm`, `function mq_clear_sbinfo`, `function sem_init_ns`, `function shm_init_ns`.
- Atlas domain: Core OS / IPC.
- 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.