fishinabarrel / linux-kernel-module-rust

Framework for writing Linux kernel modules in safe Rust
GNU General Public License v2.0
1.33k stars 120 forks source link

I know a solution to one of the TODOs #245

Closed Shnatsel closed 4 years ago

Shnatsel commented 4 years ago

https://github.com/fishinabarrel/linux-kernel-module-rust/blob/51688f923de35cd5a40861a45b842374848efa49/src/lib.rs#L76-L86

I have managed to achieve that with a little help from build.rs.

This is the part that goes into the binary and puts the data into the linker section:

https://github.com/Shnatsel/rust-audit/blob/2be53a791c4ae76bda8471401fd46daa48d89a8c/auditable/src/lib.rs#L18

And this is be build script preparing the data: https://github.com/Shnatsel/rust-audit/blob/2be53a791c4ae76bda8471401fd46daa48d89a8c/auditable-build/src/lib.rs#L10

alex commented 4 years ago

I'm not sure we can easily do this, I think in our case it'd require the project invoking us to have a build.rs, which is currently not required. The next optimization would be if rust had a bytes_concat!() macro that produced an [u8; N] array (and not &[u8]). But for now this works well enough, even if it's ugly.

Thanks for the suggestion though!