Skip to content

Commit 4358ab8

Browse files
committed
Remove redundant ret
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
1 parent c6bdefc commit 4358ab8

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

profiling/src/wall_time.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,22 @@ mod frameless {
154154
use crate::zend;
155155

156156
pub unsafe fn generate_wrapper(original: *mut c_void) -> *mut c_void {
157+
// Calls original function, then calls interrupt function.
157158
let mut assembler = Assembler::new().unwrap();
158159
let interrupt_addr = ddog_php_prof_icall_trampoline_target as *const ();
159160
#[cfg(target_arch = "aarch64")]
160161
dynasm!(assembler
161162
; mov x16, original as u64
162163
; blr x16
163164
; mov x16, interrupt_addr as u64
164-
; blr x16
165-
; ret
165+
; br x16 // tail call
166166
);
167167
#[cfg(target_arch = "x86_64")]
168168
dynasm!(assembler
169169
; mov rax, QWORD original as i64
170170
; call rax
171171
; mov rax, QWORD interrupt_addr as i64
172-
; call rax
173-
; ret
172+
; jmp rax // tail call
174173
);
175174
let buffer = assembler.finalize().unwrap();
176175
let ptr = buffer.as_ptr() as *mut c_void;
@@ -181,6 +180,7 @@ mod frameless {
181180
#[no_mangle]
182181
#[inline(never)]
183182
pub unsafe extern "C" fn ddog_php_prof_icall_trampoline_target() {
183+
// TODO: First check for REQUEST_LOCALS.interrupt_count before fetching execute data to make this less expensive
184184
ddog_php_prof_interrupt_function(zend::ddog_php_prof_get_current_execute_data());
185185
}
186186
}
@@ -198,6 +198,8 @@ mod frameless {
198198
let wrapper = trampoline::generate_wrapper(original);
199199
*zend_flf_handlers.add(i) = wrapper;
200200
let func = &mut **zend_flf_functions.add(i);
201+
202+
// We need to do copies of frameless_function_infos as they may be readonly memory
201203
let original_info = func.internal_function.frameless_function_infos;
202204
let mut infos = Vec::new();
203205
let mut ptr = original_info;
@@ -214,7 +216,6 @@ mod frameless {
214216
info.handler = wrapper;
215217
}
216218
}
217-
infos.push(crate::bindings::zend_frameless_function_info { handler: std::ptr::null_mut(), num_args: 0 });
218219
let new_infos = infos.into_boxed_slice();
219220
func.internal_function.frameless_function_infos = new_infos.as_ptr() as *mut _;
220221
std::mem::forget(new_infos); // TODO: leaks memory

0 commit comments

Comments
 (0)