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 static inline struct binder_device *binderfs_device_get(struct binder_device *dev) 39 { 40 if (dev->binderfs_inode) 41 ihold(dev->binderfs_inode); 42 return dev; 43 } 44 45 static inline void binderfs_device_put(struct binder_device *dev) 46 { 47 if (dev->binderfs_inode) 48 iput(dev->binderfs_inode); 49 } 50 51 /** 52 * binderfs_mount_opts - mount options for binderfs 53 * @max: maximum number of allocatable binderfs binder devices 54 * @stats_mode: enable binder stats in binderfs. 55 */ 56 struct binderfs_mount_opts { 57 int max; 58 int stats_mode; 59 }; 60 61 /** 62 * binderfs_info - information about a binderfs mount 63 * @ipc_ns: The ipc namespace the binderfs mount belongs to. 64 * @control_dentry: This records the dentry of this binderfs mount 65 * binder-control device. 66 * @root_uid: uid that needs to be used when a new binder device is 67 * created. 68 * @root_gid: gid that needs to be used when a new binder device is 69 * created. 70 * @mount_opts: The mount options in use. 71 * @device_count: The current number of allocated binder devices. 72 * @proc_log_dir: Pointer to the directory dentry containing process-specific 73 * logs. 74 */ 75 struct binderfs_info { 76 struct ipc_namespace *ipc_ns; 77 struct dentry *control_dentry; 78 kuid_t root_uid; 79 kgid_t root_gid; 80 struct binderfs_mount_opts mount_opts; 81 int device_count; 82 struct dentry *proc_log_dir; 83 }; 84 85 extern const struct file_operations binder_fops; 86 87 extern char *binder_devices_param; 88 89 #ifdef CONFIG_ANDROID_BINDERFS 90 extern bool is_binderfs_device(const struct inode *inode); 91 extern struct dentry *binderfs_create_file(struct dentry *dir, const char *name, 92 const struct file_operations *fops, 93 void *data); 94 extern void binderfs_remove_file(struct dentry *dentry); 95 #else 96 static inline bool is_binderfs_device(const struct inode *inode) 97 { 98 return false; 99 } 100 static inline struct dentry *binderfs_create_file(struct dentry *dir, 101 const char *name, 102 const struct file_operations *fops, 103 void *data) 104 { 105 return NULL; 106 } 107 static inline void binderfs_remove_file(struct dentry *dentry) {} 108 #endif 109 110 #ifdef CONFIG_ANDROID_BINDERFS 111 extern int __init init_binderfs(void); 112 #else 113 static inline int __init init_binderfs(void) 114 { 115 return 0; 116 } 117 #endif 118 119 int binder_stats_show(struct seq_file *m, void *unused); 120 DEFINE_SHOW_ATTRIBUTE(binder_stats); 121 122 int binder_state_show(struct seq_file *m, void *unused); 123 DEFINE_SHOW_ATTRIBUTE(binder_state); 124 125 int binder_transactions_show(struct seq_file *m, void *unused); 126 DEFINE_SHOW_ATTRIBUTE(binder_transactions); 127 128 int binder_transaction_log_show(struct seq_file *m, void *unused); 129 DEFINE_SHOW_ATTRIBUTE(binder_transaction_log); 130 131 struct binder_transaction_log_entry { 132 int debug_id; 133 int debug_id_done; 134 int call_type; 135 int from_proc; 136 int from_thread; 137 int target_handle; 138 int to_proc; 139 int to_thread; 140 int to_node; 141 int data_size; 142 int offsets_size; 143 int return_error_line; 144 uint32_t return_error; 145 uint32_t return_error_param; 146 char context_name[BINDERFS_MAX_NAME + 1]; 147 }; 148 149 struct binder_transaction_log { 150 atomic_t cur; 151 bool full; 152 struct binder_transaction_log_entry entry[32]; 153 }; 154 155 extern struct binder_transaction_log binder_transaction_log; 156 extern struct binder_transaction_log binder_transaction_log_failed; 157 #endif /* _LINUX_BINDER_INTERNAL_H */ 158