mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
ecaa6ddff2
The `build_error` crate provides a function `build_error` which will panic at compile-time if executed in const context and, by default, will cause a build error if not executed at compile time and the optimizer does not optimise away the call. The `CONFIG_RUST_BUILD_ASSERT_ALLOW` kernel option allows to relax the default build failure and convert it to a runtime check. If the runtime check fails, `panic!` will be called. Its functionality will be exposed to users as a couple macros in the `kernel` crate in the following patch, thus some documentation here refers to them for simplicity. Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Wei Liu <wei.liu@kernel.org> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
27 lines
862 B
C
27 lines
862 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* A hack to export Rust symbols for loadable modules without having to redo
|
|
* the entire `include/linux/export.h` logic in Rust.
|
|
*
|
|
* This requires the Rust's new/future `v0` mangling scheme because the default
|
|
* one ("legacy") uses invalid characters for C identifiers (thus we cannot use
|
|
* the `EXPORT_SYMBOL_*` macros).
|
|
*
|
|
* All symbols are exported as GPL-only to guarantee no GPL-only feature is
|
|
* accidentally exposed.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
|
|
|
|
#include "exports_core_generated.h"
|
|
#include "exports_alloc_generated.h"
|
|
#include "exports_bindings_generated.h"
|
|
#include "exports_kernel_generated.h"
|
|
|
|
// For modules using `rust/build_error.rs`.
|
|
#ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
|
|
EXPORT_SYMBOL_RUST_GPL(rust_build_error);
|
|
#endif
|