From d9c34891652ce73f51567bd193c1417069dda901 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Wed, 24 Feb 2021 01:30:38 +0000 Subject: [PATCH] aya-gen: rename probe_read_getter to read_getter The same code can be used to wrap with preserve_access_index() --- aya-gen/src/btf_types.rs | 7 +++---- aya-gen/src/getters.rs | 6 +++--- xtask/src/codegen/aya_bpf_bindings.rs | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/aya-gen/src/btf_types.rs b/aya-gen/src/btf_types.rs index dc6b09e1..5ef8c4da 100644 --- a/aya-gen/src/btf_types.rs +++ b/aya-gen/src/btf_types.rs @@ -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>( let tree = syn::parse_str::(&bindings).unwrap(); let bpf_probe_read = syn::parse_str::("::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))?; diff --git a/aya-gen/src/getters.rs b/aya-gen/src/getters.rs index bf855531..4436e25a 100644 --- a/aya-gen/src/getters.rs +++ b/aya-gen/src/getters.rs @@ -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() } } } diff --git a/xtask/src/codegen/aya_bpf_bindings.rs b/xtask/src/codegen/aya_bpf_bindings.rs index d120d056..d78026bd 100644 --- a/xtask/src/codegen/aya_bpf_bindings.rs +++ b/xtask/src/codegen/aya_bpf_bindings.rs @@ -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() ),