ipc/namespace.c
Source file repositories/reference/linux-study-clean/ipc/namespace.c
File Facts
- System
- Linux kernel
- Corpus path
ipc/namespace.c- Extension
.c- Size
- 5911 bytes
- Lines
- 258
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/ipc.hlinux/msg.hlinux/ipc_namespace.hlinux/rcupdate.hlinux/nsproxy.hlinux/slab.hlinux/cred.hlinux/fs.hlinux/mount.hlinux/user_namespace.hlinux/proc_ns.hlinux/nstree.hlinux/sched/task.hutil.h
Detected Declarations
function dec_ipc_namespacesfunction free_ipcsfunction free_ipc_nsfunction free_ipcfunction put_ipc_nsfunction ipcns_putfunction ipcns_install
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* linux/ipc/namespace.c
* Copyright (C) 2006 Pavel Emelyanov <xemul@openvz.org> OpenVZ, SWsoft Inc.
*/
#include <linux/ipc.h>
#include <linux/msg.h>
#include <linux/ipc_namespace.h>
#include <linux/rcupdate.h>
#include <linux/nsproxy.h>
#include <linux/slab.h>
#include <linux/cred.h>
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/user_namespace.h>
#include <linux/proc_ns.h>
#include <linux/nstree.h>
#include <linux/sched/task.h>
#include "util.h"
/*
* The work queue is used to avoid the cost of synchronize_rcu in kern_unmount.
*/
static void free_ipc(struct work_struct *unused);
static DECLARE_WORK(free_ipc_work, free_ipc);
static struct ucounts *inc_ipc_namespaces(struct user_namespace *ns)
{
return inc_ucount(ns, current_euid(), UCOUNT_IPC_NAMESPACES);
}
static void dec_ipc_namespaces(struct ucounts *ucounts)
{
dec_ucount(ucounts, UCOUNT_IPC_NAMESPACES);
}
static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
struct ipc_namespace *old_ns)
{
struct ipc_namespace *ns;
struct ucounts *ucounts;
int err;
err = -ENOSPC;
again:
ucounts = inc_ipc_namespaces(user_ns);
if (!ucounts) {
/*
* IPC namespaces are freed asynchronously, by free_ipc_work.
* If frees were pending, flush_work will wait, and
* return true. Fail the allocation if no frees are pending.
*/
if (flush_work(&free_ipc_work))
goto again;
goto fail;
}
err = -ENOMEM;
ns = kzalloc_obj(struct ipc_namespace, GFP_KERNEL_ACCOUNT);
if (ns == NULL)
goto fail_dec;
err = ns_common_init(ns);
if (err)
goto fail_free;
ns_tree_gen_id(ns);
ns->user_ns = get_user_ns(user_ns);
ns->ucounts = ucounts;
err = mq_init_ns(ns);
if (err)
goto fail_put;
err = -ENOMEM;
if (!setup_mq_sysctls(ns))
goto fail_mq_mount;
if (!setup_ipc_sysctls(ns))
goto fail_mq_sysctls;
err = msg_init_ns(ns);
if (err)
goto fail_ipc;
sem_init_ns(ns);
shm_init_ns(ns);
ns_tree_add_raw(ns);
Annotation
- Immediate include surface: `linux/ipc.h`, `linux/msg.h`, `linux/ipc_namespace.h`, `linux/rcupdate.h`, `linux/nsproxy.h`, `linux/slab.h`, `linux/cred.h`, `linux/fs.h`.
- Detected declarations: `function dec_ipc_namespaces`, `function free_ipcs`, `function free_ipc_ns`, `function free_ipc`, `function put_ipc_ns`, `function ipcns_put`, `function ipcns_install`.
- Atlas domain: Core OS / IPC.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.