diff --git a/programs/bpf_loader/src/syscalls/mem_ops.rs b/programs/bpf_loader/src/syscalls/mem_ops.rs index 3255c7d07a..f02f1935d9 100644 --- a/programs/bpf_loader/src/syscalls/mem_ops.rs +++ b/programs/bpf_loader/src/syscalls/mem_ops.rs @@ -216,6 +216,21 @@ fn memcmp_non_contiguous( n: u64, memory_mapping: &MemoryMapping, ) -> Result { + let memcmp_chunk = |s1_addr, s2_addr, chunk_len| { + let res = unsafe { + let s1 = slice::from_raw_parts(s1_addr, chunk_len); + let s2 = slice::from_raw_parts(s2_addr, chunk_len); + // Safety: + // memcmp is marked unsafe since it assumes that s1 and s2 are exactly chunk_len + // long. The whole point of iter_memory_pair_chunks is to find same length chunks + // across two memory regions. + memcmp(s1, s2, chunk_len) + }; + if res != 0 { + return Err(MemcmpError::Diff(res).into()); + } + Ok(0) + }; match iter_memory_pair_chunks( AccessType::Load, src_addr, @@ -224,21 +239,7 @@ fn memcmp_non_contiguous( n, memory_mapping, false, - |s1_addr, s2_addr, chunk_len| { - let res = unsafe { - let s1 = slice::from_raw_parts(s1_addr, chunk_len); - let s2 = slice::from_raw_parts(s2_addr, chunk_len); - // Safety: - // memcmp is marked unsafe since it assumes that s1 and s2 are exactly chunk_len - // long. The whole point of iter_memory_pair_chunks is to find same length chunks - // across two memory regions. - memcmp(s1, s2, chunk_len) - }; - if res != 0 { - return Err(MemcmpError::Diff(res).into()); - } - Ok(0) - }, + memcmp_chunk, ) { Ok(res) => Ok(res), Err(error) => match error.downcast_ref() {