struct binder_node {
int debug_id; // 幫助調試用的
// 當Binder實體對象的引用計數由0變爲1或由1變爲0時,Binder驅動程序就會請求相應的
// Service組件增加或減少其引用計數。Binder驅動程序就會將“該引用計數修改”封裝成一個類
// 型爲一個類型爲binder_node的工作項,即將成員work的值置爲BINDER_WORK_NODE,並將
// 它添加到相應進程的todo隊列中等待處理
struct binder_work work;
union {
struct rb_node rb_node;
struct hlist_node dead_node;
};
// 指向宿主進程,宿主進程使用一個紅黑樹來維護它內部所有Binder實體對象,而每一個
// Binder實體對象的成員變量rb_node就正好是這個紅黑樹的一個節點。如果Binder實體對象
// 的宿主進程已經死亡,那麼該Binder實體對象就會通過它的成員變量dead_node保存在一個全
// 局的hash列表中。
struct binder_proc *proc;
// 一個Binder實體對象可能會同時被多個Client組件引用,因此Binder驅動使用結構體
// binder_ref來描述這些引用關係,並且將引用了同一個Binder實體對象的所有引用都保存在
// 一個hash列表中。這個hash列表通過Binder實體對象的refs成員來描述,而Binder驅動通
// 過refs就可以知道有哪些Client組件引用了同一個Binder實體對象
struct hlist_head refs;
int internal_strong_refs; // 描述Bidner實體對象的強引用計數
int local_weak_refs; // 描述Binder實體對象的弱引用計數
int local_strong_refs; // 描述Bidner實體對象的強引用計數
void __user *ptr; // 描述用戶空間中的Service組件,指向Service的影子對象
void __user *cookie; // 描述用戶空間中的Service組件的地址,指向Service的地址
// 當Binder實體對象請求Service執行某個操作時,會增加該Service的強/弱引用計數,
// has_strong_ref和has_weak_ref被置1;
// 當Service完成Binder所請求的操作後,會遞減該Service的強/弱引用計數,has_strong_ref和has_weak_ref被置0;
// Binder實體在請求Service增/減強/弱引用計數的過程中,會將
// pending_strong_ref或pending_weak_ref置1;
// 當Service完成增/減強/弱引用計數之後,會將這兩個成員變量置爲0。
unsigned has_strong_ref:1;
unsigned pending_strong_ref:1;
unsigned has_weak_ref:1;
unsigned pending_weak_ref:1;
// 描述Binder對象是否正在處理一個異步事務。Binder驅動程序將一個事務保存在todo隊列中
// 表示將由該線程來處理該事務。每個事務都關聯着一個Binder實體對象,要求與該Binder實
// 體對象對應的Service組件在指定線程中處理該事務。然而,當Binder驅動發現一個事務是異
// 步事務時,就會將它保存在目標Binder實體對象的一個異步事務隊列中,這個異步事務隊列就
// 是由成員變量async_todo來描述的。異步事務的定義是那些單向的進程間通信請求,即不需
// 要等待應答的進程間通信請求,與此相對的是同步事務。因爲不需要等待應答,Binder驅動就
// 認爲異步事務優先級低於同步事務,具體表現爲在同一時刻,一個Binder實體對象的所有異步
// 事務最多隻有一個會得到處理,其餘的都等待在異步事務隊列中,而同步事務無此限制。
unsigned has_async_transaction:1;
// 描述Binder實體對象是否可以接收包含有文件描述符的進程間通信數據。1表示可以接收,0表
// 示禁止接收。當一個進程向另一個進程發送的數據中包含有文件描述符時,Binder驅動程序就
// 會自動在目標進程中打開一個相同的文件。基於安全性考慮,Binder程序就要通過該變量防止
// 源進程在目標進程中打開文件。
unsigned accept_fds:1;
// 表示Binder實體對象在處理來自Client進程的請求時,他所要求的處理線程(即Server進程
// 中的一個線程)應具備的最小線程優先級。
unsigned min_priority:8;
struct list_head async_todo;
};