aya-gen: rename probe_read_getter to read_getter

The same code can be used to wrap with preserve_access_index()
pull/1/head
Alessandro Decina 4 years ago
parent 9cd04a79e7
commit d9c3489165

@ -4,7 +4,7 @@ use thiserror::Error;
use crate::{
bindgen,
getters::{generate_getters_for_items, probe_read_getter},
getters::{generate_getters_for_items, read_getter},
rustfmt,
};
@ -44,9 +44,8 @@ pub fn generate<T: AsRef<str>>(
let tree = syn::parse_str::<syn::File>(&bindings).unwrap();
let bpf_probe_read = syn::parse_str::<syn::Path>("::aya_bpf::helpers::bpf_probe_read").unwrap();
let getters = generate_getters_for_items(&tree.items, |getter| {
probe_read_getter(getter, &bpf_probe_read)
});
let getters =
generate_getters_for_items(&tree.items, |getter| read_getter(getter, &bpf_probe_read));
let getters =
rustfmt::format(&getters.to_string()).map_err(|io_error| Error::Rustfmt(io_error))?;

@ -99,7 +99,7 @@ pub fn generate_getters_for_items(
tokens
}
pub fn probe_read_getter(getter: &Getter<'_>, bpf_probe_read: &Path) -> TokenStream {
pub fn read_getter(getter: &Getter<'_>, read_fn: &Path) -> TokenStream {
let ident = getter.ident;
let ty = getter.ty;
let prefix = &getter.prefix;
@ -107,7 +107,7 @@ pub fn probe_read_getter(getter: &Getter<'_>, bpf_probe_read: &Path) -> TokenStr
Type::Ptr(_) => {
quote! {
pub fn #ident(&self) -> Option<#ty> {
let v = unsafe { #bpf_probe_read(&#(#prefix).*.#ident) }.ok()?;
let v = unsafe { #read_fn(&#(#prefix).*.#ident) }.ok()?;
if v.is_null() {
None
} else {
@ -119,7 +119,7 @@ pub fn probe_read_getter(getter: &Getter<'_>, bpf_probe_read: &Path) -> TokenStr
_ => {
quote! {
pub fn #ident(&self) -> Option<#ty> {
unsafe { #bpf_probe_read(&#(#prefix).*.#ident) }.ok()
unsafe { #read_fn(&#(#prefix).*.#ident) }.ok()
}
}
}

@ -6,7 +6,7 @@ use structopt::StructOpt;
use aya_gen::{
bindgen,
getters::{generate_getters_for_items, probe_read_getter},
getters::{generate_getters_for_items, read_getter},
write_to_file, write_to_file_fmt,
};
use syn::{parse_str, Item};
@ -75,7 +75,7 @@ pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> {
&format!(
"use super::bindings::*; {}",
&generate_getters_for_items(&tree.items, |getter| {
probe_read_getter(getter, &bpf_probe_read)
read_getter(getter, &bpf_probe_read)
})
.to_string()
),

Loading…
Cancel
Save