binder_internal.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_BINDER_INTERNAL_H
  3. #define _LINUX_BINDER_INTERNAL_H
  4. #include <linux/export.h>
  5. #include <linux/fs.h>
  6. #include <linux/list.h>
  7. #include <linux/miscdevice.h>
  8. #include <linux/mutex.h>
  9. #include <linux/refcount.h>
  10. #include <linux/stddef.h>
  11. #include <linux/types.h>
  12. #include <linux/uidgid.h>
  13. #ifdef CONFIG_MTK_ENG_BUILD
  14. #define BINDER_WATCHDOG "v0.1"
  15. #endif
  16. #define BINDER_USER_TRACKING 1
  17. #ifdef BINDER_USER_TRACKING
  18. #include <linux/rtc.h>
  19. #include <linux/time.h>
  20. #endif
  21. #ifdef BINDER_WATCHDOG
  22. #include <linux/mm.h>
  23. #include <linux/slab.h>
  24. #include <linux/types.h>
  25. #include <linux/delay.h>
  26. #include <linux/kthread.h>
  27. /*****************************************************************************/
  28. /* Payload layout of addService(): */
  29. /* */
  30. /* Parcel header | IServiceManager.descriptor | Parcel header | Service name */
  31. /* (Please refer ServiceManagerNative.java:addService()) */
  32. /* IServiceManager.descriptor is 'android.os.IServiceManager' interleaved */
  33. /* with character '\0'. */
  34. /* that is, 'a', '\0', 'n', '\0', 'd', '\0', 'r', '\0', 'o', ... */
  35. /* */
  36. /* so the offset of Service name */
  37. /* = Parcel header x2 + strlen(android.os.IServiceManager) x2 */
  38. /* = 8x2 + 26x2 = 68 */
  39. /*****************************************************************************/
  40. #define MAX_SERVICE_NAME_LEN 32
  41. #define MAGIC_SERVICE_NAME_OFFSET 68
  42. #define MAX_ENG_TRANS_LOG_BUFF_LEN 10240
  43. enum wait_on_reason {
  44. WAIT_ON_NONE = 0U,
  45. WAIT_ON_READ = 1U,
  46. WAIT_ON_EXEC = 2U,
  47. WAIT_ON_REPLY_READ = 3U,
  48. };
  49. #endif
  50. struct binder_context {
  51. struct binder_node *binder_context_mgr_node;
  52. struct mutex context_mgr_node_lock;
  53. kuid_t binder_context_mgr_uid;
  54. const char *name;
  55. };
  56. /**
  57. * struct binder_device - information about a binder device node
  58. * @hlist: list of binder devices (only used for devices requested via
  59. * CONFIG_ANDROID_BINDER_DEVICES)
  60. * @miscdev: information about a binder character device node
  61. * @context: binder context information
  62. * @binderfs_inode: This is the inode of the root dentry of the super block
  63. * belonging to a binderfs mount.
  64. */
  65. struct binder_device {
  66. struct hlist_node hlist;
  67. struct miscdevice miscdev;
  68. struct binder_context context;
  69. struct inode *binderfs_inode;
  70. refcount_t ref;
  71. };
  72. /**
  73. * binderfs_mount_opts - mount options for binderfs
  74. * @max: maximum number of allocatable binderfs binder devices
  75. * @stats_mode: enable binder stats in binderfs.
  76. */
  77. struct binderfs_mount_opts {
  78. int max;
  79. int stats_mode;
  80. };
  81. /**
  82. * binderfs_info - information about a binderfs mount
  83. * @ipc_ns: The ipc namespace the binderfs mount belongs to.
  84. * @control_dentry: This records the dentry of this binderfs mount
  85. * binder-control device.
  86. * @root_uid: uid that needs to be used when a new binder device is
  87. * created.
  88. * @root_gid: gid that needs to be used when a new binder device is
  89. * created.
  90. * @mount_opts: The mount options in use.
  91. * @device_count: The current number of allocated binder devices.
  92. * @proc_log_dir: Pointer to the directory dentry containing process-specific
  93. * logs.
  94. */
  95. struct binderfs_info {
  96. struct ipc_namespace *ipc_ns;
  97. struct dentry *control_dentry;
  98. kuid_t root_uid;
  99. kgid_t root_gid;
  100. struct binderfs_mount_opts mount_opts;
  101. int device_count;
  102. struct dentry *proc_log_dir;
  103. };
  104. extern const struct file_operations binder_fops;
  105. extern char *binder_devices_param;
  106. #ifdef CONFIG_ANDROID_BINDERFS
  107. extern bool is_binderfs_device(const struct inode *inode);
  108. extern struct dentry *binderfs_create_file(struct dentry *dir, const char *name,
  109. const struct file_operations *fops,
  110. void *data);
  111. extern void binderfs_remove_file(struct dentry *dentry);
  112. #else
  113. static inline bool is_binderfs_device(const struct inode *inode)
  114. {
  115. return false;
  116. }
  117. static inline struct dentry *binderfs_create_file(struct dentry *dir,
  118. const char *name,
  119. const struct file_operations *fops,
  120. void *data)
  121. {
  122. return NULL;
  123. }
  124. static inline void binderfs_remove_file(struct dentry *dentry) {}
  125. #endif
  126. #ifdef CONFIG_ANDROID_BINDERFS
  127. extern int __init init_binderfs(void);
  128. #else
  129. static inline int __init init_binderfs(void)
  130. {
  131. return 0;
  132. }
  133. #endif
  134. int binder_stats_show(struct seq_file *m, void *unused);
  135. DEFINE_SHOW_ATTRIBUTE(binder_stats);
  136. int binder_state_show(struct seq_file *m, void *unused);
  137. DEFINE_SHOW_ATTRIBUTE(binder_state);
  138. int binder_transactions_show(struct seq_file *m, void *unused);
  139. DEFINE_SHOW_ATTRIBUTE(binder_transactions);
  140. int binder_transaction_log_show(struct seq_file *m, void *unused);
  141. DEFINE_SHOW_ATTRIBUTE(binder_transaction_log);
  142. struct binder_transaction_log_entry {
  143. int debug_id;
  144. int debug_id_done;
  145. int call_type;
  146. int from_proc;
  147. int from_thread;
  148. int target_handle;
  149. int to_proc;
  150. int to_thread;
  151. int to_node;
  152. int data_size;
  153. int offsets_size;
  154. int return_error_line;
  155. uint32_t return_error;
  156. uint32_t return_error_param;
  157. const char *context_name;
  158. #ifdef BINDER_WATCHDOG
  159. unsigned int code;
  160. char service[MAX_SERVICE_NAME_LEN];
  161. int fd;
  162. struct timespec readstamp;
  163. struct timespec endstamp;
  164. unsigned int cur;
  165. #endif
  166. #ifdef BINDER_USER_TRACKING
  167. struct timespec timestamp;
  168. struct timeval tv;
  169. #endif
  170. };
  171. #ifdef BINDER_WATCHDOG
  172. struct binder_timeout_log_entry {
  173. enum wait_on_reason r;
  174. pid_t from_proc;
  175. pid_t from_thrd;
  176. pid_t to_proc;
  177. pid_t to_thrd;
  178. unsigned int over_sec;
  179. struct timespec ts;
  180. struct timeval tv;
  181. unsigned int code;
  182. char service[MAX_SERVICE_NAME_LEN];
  183. int debug_id;
  184. };
  185. #endif
  186. struct binder_transaction_log {
  187. atomic_t cur;
  188. bool full;
  189. #ifdef BINDER_WATCHDOG
  190. unsigned int size;
  191. struct binder_transaction_log_entry *entry;
  192. #else
  193. struct binder_transaction_log_entry entry[32];
  194. #endif
  195. };
  196. extern struct binder_transaction_log binder_transaction_log;
  197. extern struct binder_transaction_log binder_transaction_log_failed;
  198. #endif /* _LINUX_BINDER_INTERNAL_H */