rust_binder.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2025 Google, Inc.
  4. */
  5. #ifndef _LINUX_RUST_BINDER_H
  6. #define _LINUX_RUST_BINDER_H
  7. #include <uapi/linux/android/binder.h>
  8. #include <uapi/linux/android/binderfs.h>
  9. /*
  10. * These symbols are exposed by `rust_binderfs.c` and exist here so that Rust
  11. * Binder can call them.
  12. */
  13. int init_rust_binderfs(void);
  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. * The internal data types in the Rust Binder driver are opaque to C, so we use
  20. * void pointer typedefs for these types.
  21. */
  22. typedef void *rust_binder_transaction;
  23. typedef void *rust_binder_process;
  24. typedef void *rust_binder_node;
  25. struct rb_process_layout {
  26. size_t arc_offset;
  27. size_t task;
  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. struct rb_node_layout {
  38. size_t arc_offset;
  39. size_t debug_id;
  40. size_t ptr;
  41. };
  42. struct rust_binder_layout {
  43. struct rb_transaction_layout t;
  44. struct rb_process_layout p;
  45. struct rb_node_layout n;
  46. };
  47. extern const struct rust_binder_layout RUST_BINDER_LAYOUT;
  48. static inline size_t rust_binder_transaction_debug_id(rust_binder_transaction t)
  49. {
  50. return *(size_t *) (t + RUST_BINDER_LAYOUT.t.debug_id);
  51. }
  52. static inline u32 rust_binder_transaction_code(rust_binder_transaction t)
  53. {
  54. return *(u32 *) (t + RUST_BINDER_LAYOUT.t.code);
  55. }
  56. static inline u32 rust_binder_transaction_flags(rust_binder_transaction t)
  57. {
  58. return *(u32 *) (t + RUST_BINDER_LAYOUT.t.flags);
  59. }
  60. // Nullable!
  61. static inline rust_binder_node rust_binder_transaction_target_node(rust_binder_transaction t)
  62. {
  63. void *p = *(void **) (t + RUST_BINDER_LAYOUT.t.target_node);
  64. if (p)
  65. p = p + RUST_BINDER_LAYOUT.n.arc_offset;
  66. return p;
  67. }
  68. static inline rust_binder_process rust_binder_transaction_to_proc(rust_binder_transaction t)
  69. {
  70. void *p = *(void **) (t + RUST_BINDER_LAYOUT.t.to_proc);
  71. return p + RUST_BINDER_LAYOUT.p.arc_offset;
  72. }
  73. static inline struct task_struct *rust_binder_process_task(rust_binder_process t)
  74. {
  75. return *(struct task_struct **) (t + RUST_BINDER_LAYOUT.p.task);
  76. }
  77. static inline size_t rust_binder_node_debug_id(rust_binder_node t)
  78. {
  79. return *(size_t *) (t + RUST_BINDER_LAYOUT.n.debug_id);
  80. }
  81. #endif