2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
regex::Regex,
|
|
|
|
std::{
|
|
|
|
fs::File,
|
|
|
|
io::{prelude::*, BufWriter, Read},
|
|
|
|
path::PathBuf,
|
|
|
|
process::exit,
|
|
|
|
str,
|
|
|
|
},
|
2021-06-12 19:54:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 path = PathBuf::from("src/syscalls.rs");
|
|
|
|
let mut file = match File::open(&path) {
|
|
|
|
Ok(x) => x,
|
|
|
|
_ => exit(1),
|
|
|
|
};
|
|
|
|
let mut text = vec![];
|
|
|
|
file.read_to_end(&mut text).unwrap();
|
|
|
|
let text = str::from_utf8(&text).unwrap();
|
|
|
|
let path = PathBuf::from("../../sdk/bpf/syscalls.txt");
|
|
|
|
let file = match File::create(&path) {
|
|
|
|
Ok(x) => x,
|
|
|
|
_ => exit(1),
|
|
|
|
};
|
|
|
|
let mut out = BufWriter::new(file);
|
|
|
|
let sysc_re = Regex::new(r#"register_syscall_by_name\([[:space:]]*b"([^"]+)","#).unwrap();
|
2021-06-18 15:34:46 +02:00
|
|
|
for caps in sysc_re.captures_iter(text) {
|
2021-10-22 21:25:54 -07:00
|
|
|
let name = caps[1].to_string();
|
|
|
|
writeln!(out, "{}", name).unwrap();
|
2021-06-12 19:54:44 -07:00
|
|
|
}
|
|
|
|
}
|