Skip to content

Commit 7e3654b

Browse files
aero_proc::syslog: fix scopes
Previously something like the following was generated: ```rs fn foo(bar: u64) -> u64 { fn inner(bar: u64) -> u64 { let body = { // if return is used here then the syscall magic // will not be called. This made the generated // code skip some of the syscalls in the syslog // because the return returned from the function // not the scope it self. So to solve this // problem the body is inserted into an // even_inner function and to be nice, its // annotated with #[inline(always)] // // return 69; }; // syslog magic body } inner(bar); } ``` Sometimes it just happens. Stay safe with scopes guys! Stay Giga :^) Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 7983214 commit 7e3654b

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/aero_proc/src/syscall.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ pub fn parse(attr: TokenStream, item: TokenStream) -> TokenStream {
105105
let orig_args = &signature.inputs;
106106
let processed_args = process_args(orig_args);
107107
let call_args = process_call_args(orig_args);
108+
let args = orig_args
109+
.iter()
110+
.map(|e| match e {
111+
FnArg::Typed(arg) => match arg.pat.as_ref() {
112+
Pat::Ident(pat) => pat.ident.clone(),
113+
_ => unimplemented!(),
114+
},
115+
_ => unimplemented!(),
116+
})
117+
.collect::<Vec<_>>();
108118
let ret = &signature.output;
109119
let body = &parsed_fn.block;
110120

@@ -150,22 +160,29 @@ pub fn parse(attr: TokenStream, item: TokenStream) -> TokenStream {
150160
};
151161

152162
let compiled_body = if config.no_return {
153-
quote::quote! { #body }
163+
quote::quote! {
164+
fn even_inner(#orig_args) #ret #body
165+
even_inner(#(#call_args),*)
166+
}
154167
} else {
155168
quote::quote! {
156-
let result = #body;
157-
#syslog
158-
result
169+
#[inline(always)]
170+
fn even_inner(#orig_args) #ret #body
171+
172+
#[inline(always)]
173+
fn syscall_inner(#orig_args) #ret {
174+
let result = even_inner(#(#args),*);
175+
#syslog
176+
result
177+
}
178+
179+
syscall_inner(#(#call_args),*)
159180
}
160181
};
161182

162183
let result = quote! {
163184
#(#attrs)* #vis fn #name(#(#processed_args),*) #ret {
164-
#(#attrs)* fn inner_syscall(#orig_args) #ret {
165-
#compiled_body
166-
}
167-
168-
inner_syscall(#(#call_args),*)
185+
#compiled_body
169186
}
170187
};
171188

0 commit comments

Comments
 (0)