Add helper crate to generate syscalls.txt
This commit is contained in:
9
programs/bpf_loader/gen-syscall-list/Cargo.toml
Normal file
9
programs/bpf_loader/gen-syscall-list/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "gen-syscall-list"
|
||||
version = "1.10.0"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
publish = false
|
||||
|
||||
[build-dependencies]
|
||||
regex = "1.5.4"
|
42
programs/bpf_loader/gen-syscall-list/build.rs
Normal file
42
programs/bpf_loader/gen-syscall-list/build.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use {
|
||||
regex::Regex,
|
||||
std::{
|
||||
fs::File,
|
||||
io::{prelude::*, BufWriter, Read},
|
||||
path::PathBuf,
|
||||
str,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract a list of registered syscall names and save it in a file
|
||||
* for distribution with the SDK. This file is read by cargo-build-bpf
|
||||
* to verify undefined symbols in a .so module that cargo-build-bpf has built.
|
||||
*/
|
||||
fn main() {
|
||||
let syscalls_rs_path = PathBuf::from("../src/syscalls.rs");
|
||||
let syscalls_txt_path = PathBuf::from("../../../sdk/bpf/syscalls.txt");
|
||||
println!(
|
||||
"cargo:warning=(not a warning) Generating {1} from {0}",
|
||||
syscalls_rs_path.display(),
|
||||
syscalls_txt_path.display()
|
||||
);
|
||||
|
||||
let mut file = match File::open(&syscalls_rs_path) {
|
||||
Ok(x) => x,
|
||||
Err(err) => panic!("Failed to open {}: {}", syscalls_rs_path.display(), err),
|
||||
};
|
||||
let mut text = vec![];
|
||||
file.read_to_end(&mut text).unwrap();
|
||||
let text = str::from_utf8(&text).unwrap();
|
||||
let file = match File::create(&syscalls_txt_path) {
|
||||
Ok(x) => x,
|
||||
Err(err) => panic!("Failed to create {}: {}", syscalls_txt_path.display(), err),
|
||||
};
|
||||
let mut out = BufWriter::new(file);
|
||||
let sysc_re = Regex::new(r#"register_syscall_by_name\([[:space:]]*b"([^"]+)","#).unwrap();
|
||||
for caps in sysc_re.captures_iter(text) {
|
||||
let name = caps[1].to_string();
|
||||
writeln!(out, "{}", name).unwrap();
|
||||
}
|
||||
}
|
3
programs/bpf_loader/gen-syscall-list/src/main.rs
Normal file
3
programs/bpf_loader/gen-syscall-list/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
/* I do all my work in `../build.rs` */
|
||||
}
|
Reference in New Issue
Block a user