mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 15:26:47 +00:00
feat(debug)[WIP]: add static-keys support (#1025)
* feat: add static-keys support
This commit is contained in:
parent
e232830c18
commit
750b3b5d91
@ -15,7 +15,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["backtrace", "kvm", "fatfs", "fatfs-secure"]
|
default = ["backtrace", "kvm", "fatfs", "fatfs-secure", "static_keys_test"]
|
||||||
# 内核栈回溯
|
# 内核栈回溯
|
||||||
backtrace = []
|
backtrace = []
|
||||||
# kvm
|
# kvm
|
||||||
@ -27,6 +27,7 @@ driver_ps2_mouse = []
|
|||||||
|
|
||||||
# kprobe
|
# kprobe
|
||||||
kprobe_test = []
|
kprobe_test = []
|
||||||
|
static_keys_test = []
|
||||||
|
|
||||||
# 运行时依赖项
|
# 运行时依赖项
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -67,6 +68,8 @@ lru = "0.12.3"
|
|||||||
|
|
||||||
rbpf = { path = "crates/rbpf" }
|
rbpf = { path = "crates/rbpf" }
|
||||||
printf-compat = { version = "0.1.1", default-features = false }
|
printf-compat = { version = "0.1.1", default-features = false }
|
||||||
|
static-keys = "=0.6.1"
|
||||||
|
|
||||||
# target为x86_64时,使用下面的依赖
|
# target为x86_64时,使用下面的依赖
|
||||||
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
||||||
mini-backtrace = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/mini-backtrace.git", rev = "e0b1d90940" }
|
mini-backtrace = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/mini-backtrace.git", rev = "e0b1d90940" }
|
||||||
|
28
kernel/src/debug/jump_label.rs
Normal file
28
kernel/src/debug/jump_label.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#[cfg(feature = "static_keys_test")]
|
||||||
|
mod tests {
|
||||||
|
use static_keys::{define_static_key_false, static_branch_unlikely};
|
||||||
|
define_static_key_false!(MY_STATIC_KEY);
|
||||||
|
#[inline(always)]
|
||||||
|
fn foo() {
|
||||||
|
println!("Entering foo function");
|
||||||
|
if static_branch_unlikely!(MY_STATIC_KEY) {
|
||||||
|
println!("A branch");
|
||||||
|
} else {
|
||||||
|
println!("B branch");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn static_keys_test() {
|
||||||
|
foo();
|
||||||
|
unsafe {
|
||||||
|
MY_STATIC_KEY.enable();
|
||||||
|
}
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn static_keys_init() {
|
||||||
|
static_keys::global_init();
|
||||||
|
#[cfg(feature = "static_keys_test")]
|
||||||
|
tests::static_keys_test();
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
|
pub mod jump_label;
|
||||||
pub mod klog;
|
pub mod klog;
|
||||||
pub mod kprobe;
|
pub mod kprobe;
|
||||||
|
@ -57,6 +57,7 @@ fn do_start_kernel() {
|
|||||||
|
|
||||||
unsafe { mm_init() };
|
unsafe { mm_init() };
|
||||||
|
|
||||||
|
// crate::debug::jump_label::static_keys_init();
|
||||||
if scm_reinit().is_ok() {
|
if scm_reinit().is_ok() {
|
||||||
if let Err(e) = textui_init() {
|
if let Err(e) = textui_init() {
|
||||||
warn!("Failed to init textui: {:?}", e);
|
warn!("Failed to init textui: {:?}", e);
|
||||||
@ -90,6 +91,7 @@ fn do_start_kernel() {
|
|||||||
clocksource_boot_finish();
|
clocksource_boot_finish();
|
||||||
Futex::init();
|
Futex::init();
|
||||||
crate::bpf::init_bpf_system();
|
crate::bpf::init_bpf_system();
|
||||||
|
crate::debug::jump_label::static_keys_init();
|
||||||
#[cfg(all(target_arch = "x86_64", feature = "kvm"))]
|
#[cfg(all(target_arch = "x86_64", feature = "kvm"))]
|
||||||
crate::virt::kvm::kvm_init();
|
crate::virt::kvm::kvm_init();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#![feature(sync_unsafe_cell)]
|
#![feature(sync_unsafe_cell)]
|
||||||
#![feature(vec_into_raw_parts)]
|
#![feature(vec_into_raw_parts)]
|
||||||
#![feature(c_variadic)]
|
#![feature(c_variadic)]
|
||||||
|
#![feature(asm_goto)]
|
||||||
#![cfg_attr(target_os = "none", no_std)]
|
#![cfg_attr(target_os = "none", no_std)]
|
||||||
#![allow(static_mut_refs, non_local_definitions, internal_features)]
|
#![allow(static_mut_refs, non_local_definitions, internal_features)]
|
||||||
// clippy的配置
|
// clippy的配置
|
||||||
|
Loading…
x
Reference in New Issue
Block a user