• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_RUST_BINDER_H
3 #define _LINUX_RUST_BINDER_H
4 
5 #include <uapi/linux/android/binder.h>
6 #include <uapi/linux/android/binderfs.h>
7 
8 /*
9  * These symbols are exposed by `rust_binderfs.c` and exist here so that Rust
10  * Binder can call them.
11  */
12 int init_rust_binderfs(void);
13 
14 struct dentry;
15 struct inode;
16 struct dentry *rust_binderfs_create_proc_file(struct inode *nodp, int pid);
17 void rust_binderfs_remove_file(struct dentry *dentry);
18 
19 /*
20  * The internal data types in the Rust Binder driver are opaque to C, so we use
21  * void pointer typedefs for these types.
22  */
23 typedef void *rust_binder_transaction;
24 typedef void *rust_binder_thread;
25 typedef void *rust_binder_process;
26 typedef void *rust_binder_node;
27 typedef void *rust_binder_ref_data;
28 
29 struct rb_transaction_layout {
30 	size_t debug_id;
31 	size_t code;
32 	size_t flags;
33 	size_t from_thread;
34 	size_t to_proc;
35 	size_t target_node;
36 };
37 
38 struct rb_thread_layout {
39 	size_t arc_offset;
40 	size_t process;
41 	size_t id;
42 };
43 
44 struct rb_process_layout {
45 	size_t arc_offset;
46 	size_t task;
47 };
48 
49 struct rb_node_layout {
50 	size_t arc_offset;
51 	size_t debug_id;
52 	size_t ptr;
53 };
54 
55 struct rust_binder_layout {
56 	struct rb_transaction_layout t;
57 	struct rb_thread_layout th;
58 	struct rb_process_layout p;
59 	struct rb_node_layout n;
60 };
61 
62 extern const struct rust_binder_layout RUST_BINDER_LAYOUT;
63 
rust_binder_transaction_debug_id(rust_binder_transaction t)64 static inline size_t rust_binder_transaction_debug_id(rust_binder_transaction t)
65 {
66 	return * (size_t *) (t + RUST_BINDER_LAYOUT.t.debug_id);
67 }
68 
rust_binder_transaction_code(rust_binder_transaction t)69 static inline u32 rust_binder_transaction_code(rust_binder_transaction t)
70 {
71 	return * (u32 *) (t + RUST_BINDER_LAYOUT.t.code);
72 }
73 
rust_binder_transaction_flags(rust_binder_transaction t)74 static inline u32 rust_binder_transaction_flags(rust_binder_transaction t)
75 {
76 	return * (u32 *) (t + RUST_BINDER_LAYOUT.t.flags);
77 }
78 
79 // Nullable!
rust_binder_transaction_target_node(rust_binder_transaction t)80 static inline rust_binder_node rust_binder_transaction_target_node(rust_binder_transaction t)
81 {
82 	void *p = * (void **) (t + RUST_BINDER_LAYOUT.t.target_node);
83 	if (p)
84 		p = p + RUST_BINDER_LAYOUT.n.arc_offset;
85 	return p;
86 }
87 
rust_binder_transaction_from_thread(rust_binder_transaction t)88 static inline rust_binder_thread rust_binder_transaction_from_thread(rust_binder_transaction t)
89 {
90 	void *p = * (void **) (t + RUST_BINDER_LAYOUT.t.from_thread);
91 	return p + RUST_BINDER_LAYOUT.th.arc_offset;
92 }
93 
rust_binder_transaction_to_proc(rust_binder_transaction t)94 static inline rust_binder_process rust_binder_transaction_to_proc(rust_binder_transaction t)
95 {
96 	void *p = * (void **) (t + RUST_BINDER_LAYOUT.t.to_proc);
97 	return p + RUST_BINDER_LAYOUT.p.arc_offset;
98 }
99 
rust_binder_thread_proc(rust_binder_thread t)100 static inline rust_binder_process rust_binder_thread_proc(rust_binder_thread t)
101 {
102 	void *p = * (void **) (t + RUST_BINDER_LAYOUT.th.process);
103 	return p + RUST_BINDER_LAYOUT.p.arc_offset;
104 }
105 
rust_binder_thread_id(rust_binder_thread t)106 static inline s32 rust_binder_thread_id(rust_binder_thread t)
107 {
108 	return * (s32 *) (t + RUST_BINDER_LAYOUT.th.id);
109 }
110 
rust_binder_process_task(rust_binder_process t)111 static inline struct task_struct *rust_binder_process_task(rust_binder_process t)
112 {
113 	return * (struct task_struct **) (t + RUST_BINDER_LAYOUT.p.task);
114 }
115 
rust_binder_node_debug_id(rust_binder_node t)116 static inline size_t rust_binder_node_debug_id(rust_binder_node t)
117 {
118 	return * (size_t *) (t + RUST_BINDER_LAYOUT.n.debug_id);
119 }
120 
rust_binder_node_ptr(rust_binder_node t)121 static inline binder_uintptr_t rust_binder_node_ptr(rust_binder_node t)
122 {
123 	return * (binder_uintptr_t *) (t + RUST_BINDER_LAYOUT.n.ptr);
124 }
125 
126 #endif
127