xref: /linux/drivers/android/binder/rust_binder_internal.h (revision 4f38da1f027ea2c9f01bb71daa7a299c191b6940)
1*eafedbc7SAlice Ryhl /* SPDX-License-Identifier: GPL-2.0 */
2*eafedbc7SAlice Ryhl /* rust_binder_internal.h
3*eafedbc7SAlice Ryhl  *
4*eafedbc7SAlice Ryhl  * This file contains internal data structures used by Rust Binder. Mostly,
5*eafedbc7SAlice Ryhl  * these are type definitions used only by binderfs or things that Rust Binder
6*eafedbc7SAlice Ryhl  * define and export to binderfs.
7*eafedbc7SAlice Ryhl  *
8*eafedbc7SAlice Ryhl  * It does not include things exported by binderfs to Rust Binder since this
9*eafedbc7SAlice Ryhl  * file is not included as input to bindgen.
10*eafedbc7SAlice Ryhl  *
11*eafedbc7SAlice Ryhl  * Copyright (C) 2025 Google LLC.
12*eafedbc7SAlice Ryhl  */
13*eafedbc7SAlice Ryhl 
14*eafedbc7SAlice Ryhl #ifndef _LINUX_RUST_BINDER_INTERNAL_H
15*eafedbc7SAlice Ryhl #define _LINUX_RUST_BINDER_INTERNAL_H
16*eafedbc7SAlice Ryhl 
17*eafedbc7SAlice Ryhl #define RUST_BINDERFS_SUPER_MAGIC	0x6c6f6f71
18*eafedbc7SAlice Ryhl 
19*eafedbc7SAlice Ryhl #include <linux/seq_file.h>
20*eafedbc7SAlice Ryhl #include <uapi/linux/android/binder.h>
21*eafedbc7SAlice Ryhl #include <uapi/linux/android/binderfs.h>
22*eafedbc7SAlice Ryhl 
23*eafedbc7SAlice Ryhl /*
24*eafedbc7SAlice Ryhl  * The internal data types in the Rust Binder driver are opaque to C, so we use
25*eafedbc7SAlice Ryhl  * void pointer typedefs for these types.
26*eafedbc7SAlice Ryhl  */
27*eafedbc7SAlice Ryhl typedef void *rust_binder_context;
28*eafedbc7SAlice Ryhl 
29*eafedbc7SAlice Ryhl /**
30*eafedbc7SAlice Ryhl  * struct binder_device - information about a binder device node
31*eafedbc7SAlice Ryhl  * @minor:     the minor number used by this device
32*eafedbc7SAlice Ryhl  * @ctx:       the Rust Context used by this device, or null for binder-control
33*eafedbc7SAlice Ryhl  *
34*eafedbc7SAlice Ryhl  * This is used as the private data for files directly in binderfs, but not
35*eafedbc7SAlice Ryhl  * files in the binder_logs subdirectory. This struct owns a refcount on `ctx`
36*eafedbc7SAlice Ryhl  * and the entry for `minor` in `binderfs_minors`. For binder-control `ctx` is
37*eafedbc7SAlice Ryhl  * null.
38*eafedbc7SAlice Ryhl  */
39*eafedbc7SAlice Ryhl struct binder_device {
40*eafedbc7SAlice Ryhl 	int minor;
41*eafedbc7SAlice Ryhl 	rust_binder_context ctx;
42*eafedbc7SAlice Ryhl };
43*eafedbc7SAlice Ryhl 
44*eafedbc7SAlice Ryhl int rust_binder_stats_show(struct seq_file *m, void *unused);
45*eafedbc7SAlice Ryhl int rust_binder_state_show(struct seq_file *m, void *unused);
46*eafedbc7SAlice Ryhl int rust_binder_transactions_show(struct seq_file *m, void *unused);
47*eafedbc7SAlice Ryhl int rust_binder_proc_show(struct seq_file *m, void *pid);
48*eafedbc7SAlice Ryhl 
49*eafedbc7SAlice Ryhl extern const struct file_operations rust_binder_fops;
50*eafedbc7SAlice Ryhl rust_binder_context rust_binder_new_context(char *name);
51*eafedbc7SAlice Ryhl void rust_binder_remove_context(rust_binder_context device);
52*eafedbc7SAlice Ryhl 
53*eafedbc7SAlice Ryhl /**
54*eafedbc7SAlice Ryhl  * binderfs_mount_opts - mount options for binderfs
55*eafedbc7SAlice Ryhl  * @max: maximum number of allocatable binderfs binder devices
56*eafedbc7SAlice Ryhl  * @stats_mode: enable binder stats in binderfs.
57*eafedbc7SAlice Ryhl  */
58*eafedbc7SAlice Ryhl struct binderfs_mount_opts {
59*eafedbc7SAlice Ryhl 	int max;
60*eafedbc7SAlice Ryhl 	int stats_mode;
61*eafedbc7SAlice Ryhl };
62*eafedbc7SAlice Ryhl 
63*eafedbc7SAlice Ryhl /**
64*eafedbc7SAlice Ryhl  * binderfs_info - information about a binderfs mount
65*eafedbc7SAlice Ryhl  * @ipc_ns:         The ipc namespace the binderfs mount belongs to.
66*eafedbc7SAlice Ryhl  * @control_dentry: This records the dentry of this binderfs mount
67*eafedbc7SAlice Ryhl  *                  binder-control device.
68*eafedbc7SAlice Ryhl  * @root_uid:       uid that needs to be used when a new binder device is
69*eafedbc7SAlice Ryhl  *                  created.
70*eafedbc7SAlice Ryhl  * @root_gid:       gid that needs to be used when a new binder device is
71*eafedbc7SAlice Ryhl  *                  created.
72*eafedbc7SAlice Ryhl  * @mount_opts:     The mount options in use.
73*eafedbc7SAlice Ryhl  * @device_count:   The current number of allocated binder devices.
74*eafedbc7SAlice Ryhl  * @proc_log_dir:   Pointer to the directory dentry containing process-specific
75*eafedbc7SAlice Ryhl  *                  logs.
76*eafedbc7SAlice Ryhl  */
77*eafedbc7SAlice Ryhl struct binderfs_info {
78*eafedbc7SAlice Ryhl 	struct ipc_namespace *ipc_ns;
79*eafedbc7SAlice Ryhl 	struct dentry *control_dentry;
80*eafedbc7SAlice Ryhl 	kuid_t root_uid;
81*eafedbc7SAlice Ryhl 	kgid_t root_gid;
82*eafedbc7SAlice Ryhl 	struct binderfs_mount_opts mount_opts;
83*eafedbc7SAlice Ryhl 	int device_count;
84*eafedbc7SAlice Ryhl 	struct dentry *proc_log_dir;
85*eafedbc7SAlice Ryhl };
86*eafedbc7SAlice Ryhl 
87*eafedbc7SAlice Ryhl #endif /* _LINUX_RUST_BINDER_INTERNAL_H */
88