@@ -768,7 +768,9 @@ impl<'a> Default for BpfLoader<'a> {
768
768
#[ derive( Debug ) ]
769
769
pub struct Bpf {
770
770
maps : HashMap < String , Map > ,
771
- programs : HashMap < String , Program > ,
771
+ // TODO(https://github.com/rust-lang/rust/issues/97601): use `HashMap` when `get_many_mut` is
772
+ // stabilized.
773
+ programs : hashbrown:: HashMap < String , Program > ,
772
774
}
773
775
774
776
impl Bpf {
@@ -914,6 +916,31 @@ impl Bpf {
914
916
self . programs . get_mut ( name)
915
917
}
916
918
919
+ /// Attempts to get mutable references to `N` programs in the map at once.
920
+ ///
921
+ /// Returns an array of length `N` with the results of each query. For soundness, at most one
922
+ /// mutable reference will be returned to any value. `None` will be returned if any of the
923
+ /// keys are duplicates or missing.
924
+ ///
925
+ /// # Examples
926
+ ///
927
+ /// ```no_run
928
+ /// # let mut bpf = aya::Bpf::load(&[])?;
929
+ /// use aya::programs::UProbe;
930
+ ///
931
+ /// let [ssl_read, ssl_write ]= bpf.many_programs_mut(["SSL_read", "SSL_write"]).unwrap();
932
+ /// let ssl_read: &mut UProbe = ssl_read.try_into()?;
933
+ /// let ssl_write: &mut UProbe = ssl_write.try_into()?;
934
+ /// ssl_read.load()?;
935
+ /// ssl_read.attach(Some("SSL_read"), 0, "libssl", None)?;
936
+ /// ssl_write.load()?;
937
+ /// ssl_write.attach(Some("SSL_write"), 0, "libssl", None)?;
938
+ /// # Ok::<(), aya::BpfError>(())
939
+ /// ```
940
+ pub fn many_programs_mut < const N : usize > ( & mut self , names : [ & str ; N ] ) -> Option < [ & mut Program ; N ] > {
941
+ self . programs . get_many_mut ( names)
942
+ }
943
+
917
944
/// An iterator over all the programs.
918
945
///
919
946
/// # Examples
0 commit comments