1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _LINUX_BINDER_INTERNAL_H
4 #define _LINUX_BINDER_INTERNAL_H
5 
6 #include <linux/export.h>
7 #include <linux/fs.h>
8 #include <linux/list.h>
9 #include <linux/miscdevice.h>
10 #include <linux/mutex.h>
11 #include <linux/stddef.h>
12 #include <linux/types.h>
13 #include <linux/uidgid.h>
14 
15 struct binder_context {
16 	struct binder_node *binder_context_mgr_node;
17 	struct mutex context_mgr_node_lock;
18 	kuid_t binder_context_mgr_uid;
19 	const char *name;
20 };
21 
22 /**
23  * struct binder_device - information about a binder device node
24  * @hlist:          list of binder devices (only used for devices requested via
25  *                  CONFIG_ANDROID_BINDER_DEVICES)
26  * @miscdev:        information about a binder character device node
27  * @context:        binder context information
28  * @binderfs_inode: This is the inode of the root dentry of the super block
29  *                  belonging to a binderfs mount.
30  */
31 struct binder_device {
32 	struct hlist_node hlist;
33 	struct miscdevice miscdev;
34 	struct binder_context context;
35 	struct inode *binderfs_inode;
36 };
37 
38 /**
39  * binderfs_mount_opts - mount options for binderfs
40  * @max: maximum number of allocatable binderfs binder devices
41  * @stats_mode: enable binder stats in binderfs.
42  */
43 struct binderfs_mount_opts {
44 	int max;
45 	int stats_mode;
46 };
47 
48 /**
49  * binderfs_info - information about a binderfs mount
50  * @ipc_ns:         The ipc namespace the binderfs mount belongs to.
51  * @control_dentry: This records the dentry of this binderfs mount
52  *                  binder-control device.
53  * @root_uid:       uid that needs to be used when a new binder device is
54  *                  created.
55  * @root_gid:       gid that needs to be used when a new binder device is
56  *                  created.
57  * @mount_opts:     The mount options in use.
58  * @device_count:   The current number of allocated binder devices.
59  * @proc_log_dir:   Pointer to the directory dentry containing process-specific
60  *                  logs.
61  */
62 struct binderfs_info {
63 	struct ipc_namespace *ipc_ns;
64 	struct dentry *control_dentry;
65 	kuid_t root_uid;
66 	kgid_t root_gid;
67 	struct binderfs_mount_opts mount_opts;
68 	int device_count;
69 	struct dentry *proc_log_dir;
70 };
71 
72 extern const struct file_operations binder_fops;
73 
74 extern char *binder_devices_param;
75 
76 #ifdef CONFIG_ANDROID_BINDERFS
77 extern bool is_binderfs_device(const struct inode *inode);
78 extern struct dentry *binderfs_create_file(struct dentry *dir, const char *name,
79 					   const struct file_operations *fops,
80 					   void *data);
81 extern void binderfs_remove_file(struct dentry *dentry);
82 #else
83 static inline bool is_binderfs_device(const struct inode *inode)
84 {
85 	return false;
86 }
87 static inline struct dentry *binderfs_create_file(struct dentry *dir,
88 					   const char *name,
89 					   const struct file_operations *fops,
90 					   void *data)
91 {
92 	return NULL;
93 }
94 static inline void binderfs_remove_file(struct dentry *dentry) {}
95 #endif
96 
97 #ifdef CONFIG_ANDROID_BINDERFS
98 extern int __init init_binderfs(void);
99 #else
100 static inline int __init init_binderfs(void)
101 {
102 	return 0;
103 }
104 #endif
105 
106 int binder_stats_show(struct seq_file *m, void *unused);
107 DEFINE_SHOW_ATTRIBUTE(binder_stats);
108 
109 int binder_state_show(struct seq_file *m, void *unused);
110 DEFINE_SHOW_ATTRIBUTE(binder_state);
111 
112 int binder_transactions_show(struct seq_file *m, void *unused);
113 DEFINE_SHOW_ATTRIBUTE(binder_transactions);
114 
115 int binder_transaction_log_show(struct seq_file *m, void *unused);
116 DEFINE_SHOW_ATTRIBUTE(binder_transaction_log);
117 
118 struct binder_transaction_log_entry {
119 	int debug_id;
120 	int debug_id_done;
121 	int call_type;
122 	int from_proc;
123 	int from_thread;
124 	int target_handle;
125 	int to_proc;
126 	int to_thread;
127 	int to_node;
128 	int data_size;
129 	int offsets_size;
130 	int return_error_line;
131 	uint32_t return_error;
132 	uint32_t return_error_param;
133 	const char *context_name;
134 };
135 
136 struct binder_transaction_log {
137 	atomic_t cur;
138 	bool full;
139 	struct binder_transaction_log_entry entry[32];
140 };
141 
142 extern struct binder_transaction_log binder_transaction_log;
143 extern struct binder_transaction_log binder_transaction_log_failed;
144 #endif /* _LINUX_BINDER_INTERNAL_H */
145