drivers/android/binder.c
Source file repositories/reference/linux-study-clean/drivers/android/binder.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/android/binder.c- Extension
.c- Size
- 206867 bytes
- Lines
- 7172
- Domain
- Driver Families
- Bucket
- drivers/android
- 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/fdtable.hlinux/file.hlinux/freezer.hlinux/fs.hlinux/list.hlinux/miscdevice.hlinux/module.hlinux/mutex.hlinux/nsproxy.hlinux/poll.hlinux/debugfs.hlinux/rbtree.hlinux/sched/signal.hlinux/sched/mm.hlinux/seq_file.hlinux/string.hlinux/uaccess.hlinux/pid_namespace.hlinux/security.hlinux/spinlock.hlinux/ratelimit.hlinux/syscalls.hlinux/task_work.hlinux/sizes.hlinux/ktime.hkunit/visibility.huapi/linux/android/binder.hlinux/cacheflush.hbinder_netlink.hbinder_internal.hbinder_trace.h
Detected Declarations
struct binder_transaction_log_entrystruct binder_transaction_logstruct binder_task_work_cbstruct binder_ptr_fixupstruct binder_sg_copyenum binder_deferred_statefunction binder_set_stop_on_user_errorfunction __printffunction __printffunction binder_stats_deletedfunction binder_stats_createdfunction binder_proc_lockfunction binder_proc_unlockfunction binder_inner_proc_lockfunction binder_inner_proc_unlockfunction binder_node_lockfunction binder_node_unlockfunction binder_node_inner_lockfunction binder_node_inner_unlockfunction binder_worklist_empty_ilockedfunction binder_worklist_emptyfunction binder_enqueue_work_ilockedfunction binder_enqueue_deferred_thread_work_ilockedfunction binder_enqueue_thread_work_ilockedfunction binder_enqueue_thread_workfunction binder_dequeue_work_ilockedfunction binder_dequeue_workfunction binder_has_work_ilockedfunction binder_has_workfunction binder_available_for_proc_work_ilockedfunction binder_wakeup_poll_threads_ilockedfunction binder_select_thread_ilockedfunction binder_wakeup_thread_ilockedfunction binder_wakeup_proc_ilockedfunction binder_set_nicefunction binder_free_nodefunction binder_inc_node_nilockedfunction binder_inc_nodefunction binder_dec_node_nilockedfunction binder_dec_nodefunction binder_inc_node_tmpref_ilockedfunction binder_inc_node_tmpreffunction binder_dec_node_tmpreffunction binder_put_nodefunction slow_desc_lookup_olockedfunction get_ref_desc_olockedfunction binder_get_ref_for_node_olockedfunction binder_cleanup_ref_olocked
Annotated Snippet
const struct file_operations binder_fops = {
.owner = THIS_MODULE,
.poll = binder_poll,
.unlocked_ioctl = binder_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.mmap = binder_mmap,
.open = binder_open,
.flush = binder_flush,
.release = binder_release,
};
DEFINE_SHOW_ATTRIBUTE(state);
DEFINE_SHOW_ATTRIBUTE(state_hashed);
DEFINE_SHOW_ATTRIBUTE(stats);
DEFINE_SHOW_ATTRIBUTE(transactions);
DEFINE_SHOW_ATTRIBUTE(transactions_hashed);
DEFINE_SHOW_ATTRIBUTE(transaction_log);
const struct binder_debugfs_entry binder_debugfs_entries[] = {
{
.name = "state",
.mode = 0444,
.fops = &state_fops,
.data = NULL,
},
{
.name = "state_hashed",
.mode = 0444,
.fops = &state_hashed_fops,
.data = NULL,
},
{
.name = "stats",
.mode = 0444,
.fops = &stats_fops,
.data = NULL,
},
{
.name = "transactions",
.mode = 0444,
.fops = &transactions_fops,
.data = NULL,
},
{
.name = "transactions_hashed",
.mode = 0444,
.fops = &transactions_hashed_fops,
.data = NULL,
},
{
.name = "transaction_log",
.mode = 0444,
.fops = &transaction_log_fops,
.data = &binder_transaction_log,
},
{
.name = "failed_transaction_log",
.mode = 0444,
.fops = &transaction_log_fops,
.data = &binder_transaction_log_failed,
},
{} /* terminator */
};
void binder_add_device(struct binder_device *device)
{
guard(spinlock)(&binder_devices_lock);
hlist_add_head(&device->hlist, &binder_devices);
}
void binder_remove_device(struct binder_device *device)
{
guard(spinlock)(&binder_devices_lock);
hlist_del_init(&device->hlist);
}
static int __init init_binder_device(const char *name)
{
int ret;
struct binder_device *binder_device;
binder_device = kzalloc_obj(*binder_device);
if (!binder_device)
return -ENOMEM;
binder_device->miscdev.fops = &binder_fops;
binder_device->miscdev.minor = MISC_DYNAMIC_MINOR;
binder_device->miscdev.name = name;
refcount_set(&binder_device->ref, 1);
Annotation
- Immediate include surface: `linux/fdtable.h`, `linux/file.h`, `linux/freezer.h`, `linux/fs.h`, `linux/list.h`, `linux/miscdevice.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct binder_transaction_log_entry`, `struct binder_transaction_log`, `struct binder_task_work_cb`, `struct binder_ptr_fixup`, `struct binder_sg_copy`, `enum binder_deferred_state`, `function binder_set_stop_on_user_error`, `function __printf`, `function __printf`, `function binder_stats_deleted`.
- Atlas domain: Driver Families / drivers/android.
- 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.