change synchronization with agent

This commit is contained in:
2025-04-04 12:18:07 +02:00
parent 2b23baa3af
commit a97adf188b

View File

@@ -5,7 +5,7 @@ use libc::{
MFD_ALLOW_SEALING, PROT_READ, PROT_WRITE,
};
use shared_memory_heap::get_shared_mem_fd;
use std::{ffi::CString, path::Path, ptr, usize};
use std::{arch::x86_64::_mm_mfence, ffi::CString, path::Path, ptr, usize};
pub struct Agent {
sync_mem: *mut usize,
@@ -66,7 +66,7 @@ impl Agent {
execve(path.as_ptr() as *const c_char, args.as_ptr(), ptr::null());
perror("execve:\x00".as_ptr() as *const c_char);
perror(r#"execve:\0"#.as_ptr() as *const c_char);
panic!("execve failed");
}
@@ -83,29 +83,12 @@ impl Agent {
*self.sync_mem.add(i + 2) = *ptr;
}
// wake agent
let mut woken_up = 0;
while woken_up == 0 {
woken_up = syscall(
SYS_futex,
self.sync_mem,
FUTEX_WAKE,
1,
ptr::null::<u8>(),
ptr::null::<u8>(),
0,
);
}
*self.sync_mem = 1;
// wait for agent to be finished
syscall(
SYS_futex,
self.sync_mem,
FUTEX_WAIT,
0,
ptr::null::<u8>(),
ptr::null::<u8>(),
0,
);
_mm_mfence();
#[allow(clippy::while_immutable_condition)]
while *self.sync_mem == 1 {
_mm_mfence();
}
}
}