drivers/misc/ntsync.c
Source file repositories/reference/linux-study-clean/drivers/misc/ntsync.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/ntsync.c- Extension
.c- Size
- 27163 bytes
- Lines
- 1213
- Domain
- Driver Families
- Bucket
- drivers/misc
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/anon_inodes.hlinux/atomic.hlinux/file.hlinux/fs.hlinux/hrtimer.hlinux/ktime.hlinux/miscdevice.hlinux/module.hlinux/mutex.hlinux/overflow.hlinux/sched.hlinux/sched/signal.hlinux/slab.hlinux/spinlock.hlinux/time_namespace.huapi/linux/ntsync.h
Detected Declarations
struct ntsync_objstruct ntsync_q_entrystruct ntsync_qstruct ntsync_deviceenum ntsync_typefunction dev_lock_objfunction dev_unlock_objfunction obj_lockfunction obj_unlockfunction ntsync_lock_objfunction ntsync_unlock_objfunction is_signaledfunction try_wake_allfunction try_wake_all_objfunction try_wake_any_semfunction list_for_each_entryfunction try_wake_any_mutexfunction list_for_each_entryfunction try_wake_any_eventfunction list_for_each_entryfunction release_sem_statefunction ntsync_sem_releasefunction unlock_mutex_statefunction ntsync_mutex_unlockfunction kill_mutex_statefunction ntsync_mutex_killfunction ntsync_event_setfunction ntsync_event_resetfunction ntsync_sem_readfunction ntsync_mutex_readfunction ntsync_event_readfunction ntsync_free_objfunction ntsync_obj_releasefunction ntsync_obj_ioctlfunction ntsync_obj_get_fdfunction ntsync_create_semfunction ntsync_create_mutexfunction ntsync_create_eventfunction put_objfunction ntsync_schedulefunction setup_waitfunction try_wake_any_objfunction ntsync_wait_anyfunction ntsync_wait_allfunction ntsync_char_openfunction ntsync_char_releasefunction ntsync_char_ioctl
Annotated Snippet
static const struct file_operations ntsync_obj_fops = {
.owner = THIS_MODULE,
.release = ntsync_obj_release,
.unlocked_ioctl = ntsync_obj_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev,
enum ntsync_type type)
{
struct ntsync_obj *obj;
obj = kzalloc_obj(*obj);
if (!obj)
return NULL;
obj->type = type;
obj->dev = dev;
get_file(dev->file);
spin_lock_init(&obj->lock);
INIT_LIST_HEAD(&obj->any_waiters);
INIT_LIST_HEAD(&obj->all_waiters);
atomic_set(&obj->all_hint, 0);
return obj;
}
static int ntsync_obj_get_fd(struct ntsync_obj *obj)
{
FD_PREPARE(fdf, O_CLOEXEC,
anon_inode_getfile("ntsync", &ntsync_obj_fops, obj, O_RDWR));
if (fdf.err)
return fdf.err;
obj->file = fd_prepare_file(fdf);
return fd_publish(fdf);
}
static int ntsync_create_sem(struct ntsync_device *dev, void __user *argp)
{
struct ntsync_sem_args args;
struct ntsync_obj *sem;
int fd;
if (copy_from_user(&args, argp, sizeof(args)))
return -EFAULT;
if (args.count > args.max)
return -EINVAL;
sem = ntsync_alloc_obj(dev, NTSYNC_TYPE_SEM);
if (!sem)
return -ENOMEM;
sem->u.sem.count = args.count;
sem->u.sem.max = args.max;
fd = ntsync_obj_get_fd(sem);
if (fd < 0)
ntsync_free_obj(sem);
return fd;
}
static int ntsync_create_mutex(struct ntsync_device *dev, void __user *argp)
{
struct ntsync_mutex_args args;
struct ntsync_obj *mutex;
int fd;
if (copy_from_user(&args, argp, sizeof(args)))
return -EFAULT;
if (!args.owner != !args.count)
return -EINVAL;
mutex = ntsync_alloc_obj(dev, NTSYNC_TYPE_MUTEX);
if (!mutex)
return -ENOMEM;
mutex->u.mutex.count = args.count;
mutex->u.mutex.owner = args.owner;
fd = ntsync_obj_get_fd(mutex);
if (fd < 0)
ntsync_free_obj(mutex);
return fd;
}
static int ntsync_create_event(struct ntsync_device *dev, void __user *argp)
{
struct ntsync_event_args args;
struct ntsync_obj *event;
int fd;
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/atomic.h`, `linux/file.h`, `linux/fs.h`, `linux/hrtimer.h`, `linux/ktime.h`, `linux/miscdevice.h`, `linux/module.h`.
- Detected declarations: `struct ntsync_obj`, `struct ntsync_q_entry`, `struct ntsync_q`, `struct ntsync_device`, `enum ntsync_type`, `function dev_lock_obj`, `function dev_unlock_obj`, `function obj_lock`, `function obj_unlock`, `function ntsync_lock_obj`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: pattern 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.