-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Background
Currently, to develop a driver using the RROS service, developers are required to implement it in Rust under the rros/ directory. However, in real-world usage, most existing drivers are written in C and we usually only need limited access to RROS functionality (e.g., files, thread, memory buffers) to enable out-of-band (OOB) execution.
Rewriting these drivers entirely in Rust is impractical and unnecessary. Instead, a more viable path is to allow existing C drivers to directly call RROS functions and use RROS-defined structs with minimal modifications. This, however, currently lacks proper tooling and support in the build system.
Feature Request
Introduce a mechanism that allows RROS to expose selected functions and data structures via a C-compatible ABI, and generate a corresponding C header file. This will enable C drivers to:
- Include RROS headers (#include <rros.h>)
- Link against RROS-exported symbols
- Use RROS struct definitions in a type-safe manner
In advance, we could have a macro to wrap this things together.
Proposed Design
Rust-side ABI exposure:
- Use #[repr(C)] for structs and #[no_mangle] extern "C" for functions in a dedicated rros_ffi module.
#[repr(C)]
pub struct RrosFoo{
filp: *mut bindings::file,
}
#[no_mangle]
pub extern "C" fn rros_open_file(rf: *mut RrosFoo) ->i32{
// Some rros service functions
0
}- Header file generation:
Use bindgen to generate a rros.h header from the module.
Integrate this into the kernel build process (e.g., as a pre-build step in scripts/Makefile.build). - Add a RROS c glue layer.
Add a c file, sayrros_export.c. Add the exported function automatically:
extern int rros_open_file(struct RrosFoo *rf);
EXPORT_SYMBOL(rros_open_file);- Integration with kernel build system:
Install the generated header into include/generated/ or another suitable path.
Benefits
- Greatly simplifies OOB adaptation of existing C drivers.
- Aligns with existing kernel practices (e.g., EXPORT_SYMBOL, generated headers).
Optional Extensions
- Use versioning macros in rros.h to manage API evolution.
- Use macro and Makefile script to automatically finish the work.