Add build script to extract a list of registered syscalls

The list is used in cargo-build-bpf to check generated .so modules for
undefined symbols that are not known run-time syscalls.
This commit is contained in:
Dmitri Makarov
2021-06-12 19:54:44 -07:00
committed by Dmitri Makarov
parent 76bb403318
commit 32742df1b4
6 changed files with 51 additions and 26 deletions

View File

@ -9,6 +9,9 @@ homepage = "https://solana.com/"
documentation = "https://docs.rs/solana-bpf-loader-program"
edition = "2018"
[build-dependencies]
regex = "1.5.4"
[dependencies]
bincode = "1.3.1"
byteorder = "1.3.4"

View File

@ -0,0 +1,34 @@
use regex::Regex;
use std::{
fs::File,
io::{prelude::*, BufWriter, Read},
path::PathBuf,
process::exit,
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 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();
for caps in sysc_re.captures_iter(&text) {
writeln!(out, "{}", caps[1].to_string()).unwrap();
}
}