From b23e338263ca979c60d7a2c48b9bab67e2af7e8a Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 13 Mar 2025 09:34:27 +0000 Subject: [PATCH] ANDROID: rust_binder: add Rust Binder to Makefile For now, we only provide the option to only enable C Binder, or to enable both drivers. When both drivers are enabled, C Binder is always the default. We define a separate rust_binder-objs with all of the compilation units rather than just listing them under obj-$(ANDROID_BINDER_IPC_RUST) because otherwise five different GKI modules are built when choosing =m for the config option. With this commit, Rust Binder works as a built-in module. However it is not actually enough to use it as a GKI module because GKI modules are loaded too late in the boot process. That issue is tracked by b/402049944 and will be fixed in a follow-up. Bug: 388786466 Change-Id: I04a0b604a756717fff730e6e3eb4496da016a8e5 Signed-off-by: Alice Ryhl --- drivers/android/Kconfig | 12 ++++++++++++ drivers/android/Makefile | 4 ++++ drivers/android/binder/rust_binder.rs | 2 ++ 3 files changed, 18 insertions(+) diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig index c5e063b723dd..f87475aebeed 100644 --- a/drivers/android/Kconfig +++ b/drivers/android/Kconfig @@ -37,6 +37,18 @@ config ANDROID_BINDER_DEVICES created. Each binder device has its own context manager, and is therefore logically separated from the other devices. +config ANDROID_BINDER_IPC_RUST + tristate "Rust version of Android Binder IPC Driver" + depends on RUST && ANDROID_BINDER_IPC && ANDROID_BINDERFS + help + This enables the Rust implementation of the Binder driver. At this + time, the Rust implementation can only be built as an alternative to + the C implementation. By default, the C implementation is used, but + if the binder.impl=rust kernel command-line parameter is provided, + then the Rust implementation is used instead. + + To build this as a GKI module, choose m. + config ANDROID_BINDER_IPC_SELFTEST bool "Android Binder IPC Driver Selftest" depends on ANDROID_BINDER_IPC diff --git a/drivers/android/Makefile b/drivers/android/Makefile index 9b89e4ba00a1..0b876f863e02 100644 --- a/drivers/android/Makefile +++ b/drivers/android/Makefile @@ -6,3 +6,7 @@ obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o binder_alloc.o obj-$(CONFIG_ANDROID_BINDER_IPC_SELFTEST) += binder_alloc_selftest.o obj-$(CONFIG_ANDROID_VENDOR_HOOKS) += vendor_hooks.o obj-$(CONFIG_ANDROID_DEBUG_KINFO) += debug_kinfo.o + +obj-$(CONFIG_ANDROID_BINDER_IPC_RUST) += rust_binder.o +rust_binder-objs := binder/rust_binder.o binder/rust_binderfs.o binder/rust_binder_events.o +rust_binder-objs += binder/rust_binder_hooks.o binder/page_range_helper.o diff --git a/drivers/android/binder/rust_binder.rs b/drivers/android/binder/rust_binder.rs index 67c401a67551..2a8aa474fea7 100644 --- a/drivers/android/binder/rust_binder.rs +++ b/drivers/android/binder/rust_binder.rs @@ -314,6 +314,8 @@ impl kernel::Module for BinderModule { } } + pr_warn!("Loaded Rust Binder."); + BINDER_SHRINKER.register(kernel::c_str!("android-binder"))?; // SAFETY: The module is being loaded, so we can initialize binderfs.