Struct libafl_bolts::llmp::LlmpSender
source · pub struct LlmpSender<SP>where
SP: ShMemProvider,{ /* private fields */ }
Expand description
Sending end on a (unidirectional) sharedmap channel
Implementations§
source§impl<SP> LlmpSender<SP>where
SP: ShMemProvider,
impl<SP> LlmpSender<SP>where
SP: ShMemProvider,
An actor on the sending part of the shared map
sourcepub fn new(
shmem_provider: SP,
id: ClientId,
keep_pages_forever: bool
) -> Result<Self, Error>
pub fn new( shmem_provider: SP, id: ClientId, keep_pages_forever: bool ) -> Result<Self, Error>
Create a new LlmpSender
using a given ShMemProvider
, and id
.
If keep_pages_forever
is true
, ShMem
will never be freed.
If it is false
, the pages will be unmapped once they are full, and have been mapped by at least one LlmpReceiver
.
sourcepub unsafe fn reset(&mut self)
pub unsafe fn reset(&mut self)
Completely reset the current sender map. Afterwards, no receiver should read from it at a different location. This is only useful if all connected llmp parties start over, for example after a crash.
Safety
Only safe if you really really restart the page on everything connected No receiver should read from this page at a different location.
sourcepub fn on_existing_from_env(
shmem_provider: SP,
env_name: &str
) -> Result<Self, Error>
pub fn on_existing_from_env( shmem_provider: SP, env_name: &str ) -> Result<Self, Error>
Reattach to a vacant out_shmem
, to with a previous sender stored the information in an env before.
sourcepub fn to_env(&self, env_name: &str) -> Result<(), Error>
pub fn to_env(&self, env_name: &str) -> Result<(), Error>
Store the info to this sender to env.
A new client can reattach to it using LlmpSender::on_existing_from_env()
.
sourcepub fn await_safe_to_unmap_blocking(&self)
pub fn await_safe_to_unmap_blocking(&self)
Waits for this sender to be save to unmap. If a receiver is involved, this function should always be called.
sourcepub fn safe_to_unmap(&self) -> bool
pub fn safe_to_unmap(&self) -> bool
If we are allowed to unmap this client
sourcepub unsafe fn mark_safe_to_unmap(&mut self)
pub unsafe fn mark_safe_to_unmap(&mut self)
For debug purposes: Mark save to unmap, even though it might not have been read by a receiver yet.
Safety
If this method is called, the page may be unmapped before it is read by any receiver.
sourcepub fn on_existing_shmem(
shmem_provider: SP,
current_out_shmem: SP::ShMem,
last_msg_sent_offset: Option<u64>
) -> Result<Self, Error>
pub fn on_existing_shmem( shmem_provider: SP, current_out_shmem: SP::ShMem, last_msg_sent_offset: Option<u64> ) -> Result<Self, Error>
Reattach to a vacant out_shmem
.
It is essential, that the receiver (or someone else) keeps a pointer to this map
else reattach will get a new, empty page, from the OS, or fail.
sourcepub fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error>
pub fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error>
Allocates the next space on this sender page
sourcepub unsafe fn cancel_send(&mut self, msg: *mut LlmpMsg)
pub unsafe fn cancel_send(&mut self, msg: *mut LlmpMsg)
Cancel send of the next message, this allows us to allocate a new message without sending this one.
Safety
They msg pointer may no longer be used after cancel_send
sourcepub unsafe fn shrink_alloced(
&mut self,
msg: *mut LlmpMsg,
shrinked_len: usize
) -> Result<(), Error>
pub unsafe fn shrink_alloced( &mut self, msg: *mut LlmpMsg, shrinked_len: usize ) -> Result<(), Error>
sourcepub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error>
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error>
Allocates a message of the given size, tags it, and sends it off.
sourcepub fn send_buf_with_flags(
&mut self,
tag: Tag,
flags: Flags,
buf: &[u8]
) -> Result<(), Error>
pub fn send_buf_with_flags( &mut self, tag: Tag, flags: Flags, buf: &[u8] ) -> Result<(), Error>
Send a buf
with the given flags
.
sourcepub fn describe(&self) -> Result<LlmpDescription, Error>
pub fn describe(&self) -> Result<LlmpDescription, Error>
Describe this LlmpClient
in a way that it can be restored later, using Self::on_existing_from_description
.
sourcepub fn on_existing_from_description(
shmem_provider: SP,
description: &LlmpDescription
) -> Result<Self, Error>
pub fn on_existing_from_description( shmem_provider: SP, description: &LlmpDescription ) -> Result<Self, Error>
Create this client on an existing map from the given description.
Acquired with [self.describe
].
sourcepub fn send_exiting(&mut self) -> Result<(), Error>
pub fn send_exiting(&mut self) -> Result<(), Error>
Send information that this client is exiting. The other side may free up all allocated memory. We are no longer allowed to send anything afterwards.
Examples found in repository?
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
fn main() -> Result<(), Box<dyn std::error::Error>> {
/* The main node has a broker, and a few worker threads */
let mode = std::env::args()
.nth(1)
.expect("no mode specified, chose 'broker', 'b2b', 'ctr', 'adder', 'large', or 'exiting'");
let port: u16 = std::env::args()
.nth(2)
.unwrap_or_else(|| "1337".into())
.parse::<u16>()?;
// in the b2b use-case, this is our "own" port, we connect to the "normal" broker node on startup.
let b2b_port: u16 = std::env::args()
.nth(3)
.unwrap_or_else(|| "4242".into())
.parse::<u16>()?;
log::set_logger(&LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Trace);
println!("Launching in mode {mode} on port {port}");
match mode.as_str() {
"broker" => {
let mut broker = llmp::LlmpBroker::new(StdShMemProvider::new()?)?;
broker.launch_tcp_listener_on(port)?;
// Exit when we got at least _n_ nodes, and all of them quit.
broker.set_exit_cleanly_after(NonZeroUsize::new(1_usize).unwrap());
broker.loop_with_timeouts(
&mut broker_message_hook,
BROKER_TIMEOUT,
Some(SLEEP_BETWEEN_FORWARDS),
);
}
"b2b" => {
let mut broker = llmp::LlmpBroker::new(StdShMemProvider::new()?)?;
broker.launch_tcp_listener_on(b2b_port)?;
// connect back to the main broker.
broker.connect_b2b(("127.0.0.1", port))?;
broker.loop_with_timeouts(
&mut broker_message_hook,
BROKER_TIMEOUT,
Some(SLEEP_BETWEEN_FORWARDS),
);
}
"ctr" => {
let mut client =
llmp::LlmpClient::create_attach_to_tcp(StdShMemProvider::new()?, port)?;
let mut counter: u32 = 0;
loop {
counter = counter.wrapping_add(1);
client.send_buf(_TAG_SIMPLE_U32_V1, &counter.to_le_bytes())?;
println!("CTR Client writing {counter}");
thread::sleep(Duration::from_secs(1));
}
}
"adder" => {
adder_loop(port)?;
}
"large" => {
large_msg_loop(port)?;
}
"exiting" => {
let mut client =
llmp::LlmpClient::create_attach_to_tcp(StdShMemProvider::new()?, port)?;
for i in 0..10_u32 {
client.send_buf(_TAG_SIMPLE_U32_V1, &i.to_le_bytes())?;
println!("Exiting Client writing {i}");
thread::sleep(Duration::from_millis(10));
}
log::info!("Exiting Client exits");
client.sender_mut().send_exiting()?;
}
_ => {
println!("No valid mode supplied");
}
}
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl<SP> RefUnwindSafe for LlmpSender<SP>
impl<SP> !Send for LlmpSender<SP>
impl<SP> !Sync for LlmpSender<SP>
impl<SP> Unpin for LlmpSender<SP>
impl<SP> UnwindSafe for LlmpSender<SP>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Tail, T> Prepend<T> for Tail
impl<Tail, T> Prepend<T> for Tail
§type PreprendResult = Tail
type PreprendResult = Tail
TupleList
, of an Prepend::prepend()
call,
including the prepended entry.