/* binder.c
*
* Android IPC Subsystem
*
* Copyright (C) 2007-2008 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <asm/cacheflush.h>
#include <linux/fdtable.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/miscdevice.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/nsproxy.h>
#include <linux/poll.h>
#include <linux/debugfs.h>
#include <linux/rbtree.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include "binder.h"
static DEFINE_MUTEX(binder_lock);
static DEFINE_MUTEX(binder_deferred_lock);
static HLIST_HEAD(binder_procs);
static HLIST_HEAD(binder_deferred_list);
static HLIST_HEAD(binder_dead_nodes);
static struct dentry *binder_debugfs_dir_entry_root;
static struct dentry *binder_debugfs_dir_entry_proc;
static struct binder_node *binder_context_mgr_node;
static uid_t binder_context_mgr_uid = -1;
static int binder_last_id;
static struct workqueue_struct *binder_deferred_workqueue;
#define BINDER_DEBUG_ENTRY(name) \
static int binder_##name##_open(struct inode *inode, struct file *file) \
{ \
return single_open(file, binder_##name##_show, inode->i_private); \
} \
\
static const struct file_operations binder_##name##_fops = { \
.owner = THIS_MODULE, \
.open = binder_##name##_open, \
.read = seq_read, \
.llseek = seq_lseek, \
.release = single_release, \
}
static int binder_proc_show(struct seq_file *m, void *unused);
BINDER_DEBUG_ENTRY(proc);
/* This is only defined in include/asm-arm/sizes.h */
#ifndef SZ_1K
#define SZ_1K 0x400
#endif
#ifndef SZ_4M
#define SZ_4M 0x400000
#endif
#define FORBIDDEN_MMAP_FLAGS (VM_WRITE)
#define BINDER_SMALL_BUF_SIZE (PAGE_SIZE * 64)
enum {
BINDER_DEBUG_USER_ERROR = 1U << 0,
BINDER_DEBUG_FAILED_TRANSACTION = 1U << 1,
BINDER_DEBUG_DEAD_TRANSACTION = 1U << 2,
BINDER_DEBUG_OPEN_CLOSE = 1U << 3,
BINDER_DEBUG_DEAD_BINDER = 1U << 4,
BINDER_DEBUG_DEATH_NOTIFICATION = 1U << 5,
BINDER_DEBUG_READ_WRITE = 1U << 6,
BINDER_DEBUG_USER_REFS = 1U << 7,
BINDER_DEBUG_THREADS = 1U << 8,
BINDER_DEBUG_TRANSACTION = 1U << 9,
BINDER_DEBUG_TRANSACTION_COMPLETE = 1U << 10,
BINDER_DEBUG_FREE_BUFFER = 1U << 11,
BINDER_DEBUG_INTERNAL_REFS = 1U << 12,
BINDER_DEBUG_BUFFER_ALLOC = 1U << 13,
BINDER_DEBUG_PRIORITY_CAP = 1U << 14,
BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 15,
};
static uint32_t binder_debug_mask = BINDER_DEBUG_USER_ERROR |
BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
module_param_named(debug_mask, binder_debug_mask, uint, S_IWUSR | S_IRUGO);
static int binder_debug_no_lock;
module_param_named(proc_no_lock, binder_debug_no_lock, bool, S_IWUSR | S_IRUGO);
static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
static int binder_stop_on_user_error;
static int binder_set_stop_on_user_error(const char *val,
struct kernel_param *kp)
{
int ret;
ret = param_set_int(val, kp);
if (binder_stop_on_user_error < 2)
wake_up(&binder_user_error_wait);
return ret;
}
module_param_call(stop_on_user_error, binder_set_stop_on_user_error,
param_get_int, &binder_stop_on_user_error, S_IWUSR | S_IRUGO);
#define binder_debug(mask, x...) \
do { \
if (binder_debug_mask & mask) \
printk(KERN_INFO x); \
} while (0)
#define binder_user_error(x...) \
do { \
if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \
printk(KERN_INFO x); \
if (binder_stop_on_user_error) \
binder_stop_on_user_error = 2; \
} while (0)
enum binder_stat_types {
BINDER_STAT_PROC,
BINDER_STAT_THREAD,
BINDER_STAT_NODE,
BINDER_STAT_REF,
BINDER_STAT_DEATH,
BINDER_STAT_TRANSACTION,
BINDER_STAT_TRANSACTION_COMPLETE,
BINDER_STAT_COUNT
};
struct binder_stats {
int br[_IOC_NR(BR_FAILED_REPLY) + 1];
int bc[_IOC_NR(BC_DEAD_BINDER_DONE) + 1];
int obj_created[BINDER_STAT_COUNT];
int obj_deleted[BINDER_STAT_COUNT];
};
static struct binder_stats binder_stats;
static inline void binder_stats_deleted(enum binder_stat_types type)
{
binder_stats.obj_deleted[type]++;
}
static inline void binder_stats_created(enum binder_stat_types type)
{
binder_stats.obj_created[type]++;
}
struct binder_transaction_log_entry {
int debug_id;
int call_type;
int from_proc;
int from_thread;
int target_handle;
int to_proc;
int to_thread;
int to_node;
int data_size;
int offsets_size;
};
struct binder_transaction_log {
int next;
int full;
struct binder_transaction_log_entry entry[32];
};
static struct binder_transaction_log binder_transaction_log;
static struct binder_transaction_log binder_transaction_log_failed;
static struct binder_transaction_log_entry *binder_transaction_log_add(
struct binder_transaction_log *log)
{
struct binder_transaction_log_entry *e;
e = &log->entry[log->next];
memset(e, 0, sizeof(*e));
log->next++;
if (log->next == ARRAY_SIZE(log->entry)) {
log->next = 0;
log->full = 1;
}
return e;
}
struct binder_work {
struct list_head entry;
enum {
BINDER_WORK_TRANSACTION = 1,
BINDER_WORK_TRANSACTION_COMPLETE,
BINDER_WORK_NODE,
BINDER_WORK_DEAD_BINDER,
BINDER_WORK_DEAD_BINDER_AND_CLEAR,
BINDER_WORK_CLEAR_DEATH_NOTIFICATION,
} type;
};
struct binder_node {
int debug_id;
struct binder_work work;
union {
struct rb_node rb_node;
struct hlist_node dead_node;
};
struct binder_proc *proc;
struct hlist_head refs;
int internal_strong_refs;
int local_weak_refs;
int local_strong_refs;
void __user *ptr;
void __user *cookie;
unsigned has_strong_ref:1;
unsigned pending_strong_ref:1;
unsigned has_weak_ref:1;
unsigned pending_weak_ref:1;
unsigned has_async_transaction:1;
unsigned accept_fds:1;
unsigned min_priority:8;
struct list_head async_todo;
};
struct binder_ref_death {
struct binder_work work;
void __user *cookie;
};
struct binder_ref {
/* Lookups needed: */
/* node + proc => ref (transaction) */
/* desc + proc => ref (transaction, inc/dec ref) */
/* node => refs + procs (proc exit) */
int debug_id;
struct rb_node rb_node_desc;
struct rb_node rb_node_node;
struct hlist_node node_entry;
struct binder_proc *proc;
struct binder_node *node;
uint32_t desc;
int strong;
int weak;
struct binder_ref_death *death;
};
struct binder_buffer {
struct list_head entry; /* free and allocated entries by addesss */
struct rb_node rb_node; /* free entry by size or allocated entry */
/* by address */
unsigned free:1;
unsigned allow_user_free:1;
unsigned async_transaction:1;
unsigned debug_id:29;
struct binder_transaction *transaction;
struct binder_node *target_node;
size_t data_size;
size_t offsets_size;
uint8_t data[0];
};
enum binder_deferred_state {
BINDER_DEFERRED_PUT_FILES = 0x01,
BINDER_DEFERRED_FLUSH = 0x02,
BINDER_DEFERRED_RELEASE = 0x04,
};
struct binder_proc {
struct hlist_node proc_node;
struct rb_root threads;
struct rb_root nodes;
struct rb_root refs_by_desc;
struct rb_root refs_by_node;
int pid;
struct vm_area_struct *vma;
struct task_struct *tsk;
struct files_struct *files;
struct hlist_node deferred_work_node;
int deferred_work;
void *buffer;
ptrdiff_t user_buffer_offset;
struct list_head buffers;
struct rb_root free_buffers;
struct rb_root allocated_buffers;
size_t free_async_space;
struct page **pages;
size_t buffer_size;
uint32_t buffer_free;
struct list_head todo;
没有合适的资源?快使用搜索试试~ 我知道了~
android binder package
5星 · 超过95%的资源 需积分: 9 15 下载量 43 浏览量
2013-07-15
20:33:34
上传
评论
收藏 2.28MB GZ 举报
温馨提示
共705个文件
h:124个
cpp:33个
makefile:11个
android binder的驱动和应用层库,以及一个sample程序展示binder库的用法。代码在i386架构上编译执行通过。可用于binder机制学习或porting到实际项目中做为IPC.
资源推荐
资源详情
资源评论
收起资源包目录
android binder package (705个子文件)
0018fcc7a52b1cd2ec74e1104bad318cbd20d8 650B
0028f1828ff54968a62bc58ee0dfd13ddcf233 145B
02c8f112d140c80f279904b59c8ce4311fa1ee 55B
034c5935457b6a677bb96ebfae1afc2058d95d 18KB
03dc54bd69cc2c66e72548cbb40a9b79d85a09 192B
060c05aa6bc59d9054a229a953b70387fc5ed5 3KB
07b5666b6735975cdea0572d9b4c91de1b5563 3KB
07d97a94028ae910b5e6c7cb5c067bfadd6781 140B
08488adde68743883aa6e81d7f86b514178811 882B
08e2ab2e2cb5dab880e9ebf3470b5d947cc64f 3KB
091e53874740b43b88a15db54bd515284f2329 120B
09b79aa6b645f9d63cc28219c326b6eebc5b0f 2KB
0a0ebfb2dfb6d95849f9705035f3ac6946638d 1005B
0a523c66c6d8ae45e53a85128d01650941ca98 173B
0b90b7cf719f4a1b4377937252629cec2e028f 893B
0c2472024a32cbbf33f0871116fca3bd71fee3 553B
0cd324b8dcafa5faaddf191c6ab9b0f7567abd 18KB
0d0f1316e0f4415c95ea205825e50ec374e685 759B
0da8c362779e9558675f847c0db1df132f004c 2KB
0db001c654c5f4ae6a29e6af355cd7151f83c0 1KB
0e54f4517e718f2589d3eaebbcd33b0e7d2832 583B
0e7fb56c16eb630ea1c5bcf3875b0a088aa6cf 1KB
0e85bec7a225bf3efca6f31854a3ab3cd1560a 4KB
0efbcd79a5a14051ecffe3e87f2d8beb058776 452B
0f20d67a023404ae9e9ee3f3cdae9001f915be 761B
0f407c36b5461f27b2f7f819a1794d35328e2a 2KB
0f7ad59a1229ddbee96f45e8d60c4584a67c77 688B
0f9fc652690f18d3c1921664eb10fa252e98cc 632B
0fa766e551b966d7746a80c84f6265f78b9ccb 161B
0ff5673f94765f815003fcc007720d6cda20b7 308B
100002f24e2f3fd9cb917bd615fa6d418719c3 86B
10147ab13d7a815b4485b585127a56f7314995 49KB
102800b2a7e15986b951b29141676bd6653bb8 220B
103cae5eccf82738b08e62b2bb333c143f5747 769B
115c1a53709d42fa0b83564064c32812590014 120B
1195bec57106b21b22d39efad8fb959b94fa86 1KB
12e96c04a5ffc3b9ae28cc6a8f4555b8987c2f 703B
12e9fbb47b70534a116f88a3316c5a3eba87e2 39KB
14af65c55f59449e60f042b537b1df09571bd8 2KB
14d24e8a1aa8d67b79bc8563610ff0a8d323fd 15KB
1514869f2f4fb7a073a994f82f4904224f17e4 1KB
1552cd839d3861bd08ab955d25878179da91cb 7KB
155bde63399d81db0b21c4a59e4739c30801ef 162B
16fef788d34ea590a50cf820d459913954f90d 787B
17120effad1c267160dd76fd248eb6bb4d5547 905B
17a7ac6fc4e39eae4a77f80ac2b1bd3039cd4c 2KB
18967254260175605282ebdc00505292a7fd87 88B
18b8037603ee1efdfcb76165f10d395cff1545 120B
18c9cc2f5970b9d020cd2c872afedc9045b5c3 4KB
18deabf026b5afe3546936d7338ddce2bea59b 53B
18e8c4f11eadbafd175a175213b6b0055e3c4c 196B
192661cb78d9fa376283e3c95254a083c800ae 727B
1a2b6d84fa029e8c57cde5bb7456bc0c439aca 330B
1a382f2ad5d74eeeec058675159e95239c87ec 748B
1ac3902bc9fdcaf5c1d4302d71989672a26c9f 2KB
1bc1ad6a2cf8d02bd9c07c304f617c35a99b9b 94B
1d31729e84be0249df0314721cfd27c4c3c165 50B
1d9e37890cd713f30c871d3cc51bd599fbdd5a 1KB
1de956feca243af9f5177c3bce3d98df8cd8b0 3KB
1e55dcade4afba235094a62afc6fe228a958b2 4KB
1ec2c95d45a40e3038f670122aeace7340f94e 2KB
1f60ca311ff6cb66ea51070a6defba37e315ec 2KB
203c1a7e716dad62bce5bb08da4f190006a09e 206B
20a9016f79987e842e10eb61e1826d5a13cbc0 2KB
20c2d9d60204aefec618d40327152d0e2c8e3a 1KB
20fedabe6982612ae6444044e0bfcd9e638d52 250B
21a5dc5f1f6432d4bffd530e1bc1efd27b42d7 14KB
222ba46a701278a3d67a8ed5dc0a8ee721e24a 145B
224bb643b1cb51681c040e18ab605831f95d61 158B
22b929941fb4ad1b085d84713753e5b325a5c5 567B
2395e93f3697ab6087c347367f54dc19565e31 204B
23d212f5cedceab32e7a7415030f856dbae781 17KB
24c234b9c2d23b7936ef2a37831b1f4fe628cc 564B
25822eaff9837aa0b3e6cdb22ce4c5dbb860f2 1KB
25cdd032229125227e235d057069b5425d8595 691B
284ded0cb29131436fb2a2237cd6aaa1e7d495 2KB
288c8c3ead82045196eb097bea44ed7c7fce82 4KB
2905d597ba68afac608cae342874543070d2cb 5KB
2baea8ac5ea386f0f58f8fcfc888b907aaed0a 948B
2be3b6a36aa014baa1598a5f909f34333f3932 948B
2c7f012ad898fd1bc2fb1f8fd1fb92e8698ae1 2KB
2ce210dd48c6ea201a95145f0b690c6111d200 1KB
2cf5f5c8d9899b08e8ad35be603bc981d49815 29KB
2d02114fb2dcc10df1729c243d62dae923b70c 334B
2e6d76bfb882c6f12c9411c18ff08b0e8eda9a 1KB
2f5a632bd2c944f4a2fbaa395b049efa09bbeb 563B
2fbbee1f2f9a73efd846930dd564db8bbf18d7 2KB
2ff93463a785d73325261c298af1422a3eaa0c 21KB
2ffaa281b3a645f8082ca21d58518ddac989aa 466B
3036ff428aa6dbcbb680c16940d2bb5e89d728 1KB
3066bea3d9f6f6ff014487e5b94315ca7a25ed 622B
30777cb269743ddcce17491e3ae8da159fcb31 249B
307ff6c58558a1407b67ac7490f49f6e3ca9b4 120B
319be131799b1750ea62a43b7c49f38b77c5f0 550B
31b936c94020919f2227d050fb580533b4a9f1 548B
322ea5d9c4c2952b266099344eb7e5c81be5aa 2KB
333787cbb0ed76a52c24cdea3dfec465cee6fb 3KB
3349023336ce10c5ebdaf1863830ca4ae87d13 2KB
33f6879498ff84769cfbdb5657977c4531cf15 91B
3416946ba38c7581c111da0cd0c3bb4cef7727 22KB
共 705 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
- Neil_baby2013-08-06不错的学习资料,可以了解binder的通信机制
wenbo_z
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功