Bläddra i källkod

bpf: add memset impl that doesn't trip the verifier

Add a verifier proof memset implementation. This is a quick hack until
we fix compiler-builtins for the bpf target.
Alessandro Decina 3 år sedan
förälder
incheckning
32350f81b7
1 ändrade filer med 9 tillägg och 1 borttagningar
  1. 9 1
      bpf/aya-bpf/src/lib.rs

+ 9 - 1
bpf/aya-bpf/src/lib.rs

@@ -10,7 +10,7 @@ pub mod programs;
 pub use aya_bpf_cty as cty;
 
 use core::ffi::c_void;
-use cty::{c_char, c_long};
+use cty::{c_char, c_int, c_long};
 use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid};
 
 pub use aya_bpf_macros as macros;
@@ -33,3 +33,11 @@ pub trait BpfContext {
         (bpf_get_current_pid_tgid() >> 32) as u32
     }
 }
+
+#[no_mangle]
+pub unsafe extern "C" fn memset(s: *mut u8, c: c_int, n: usize) {
+    let base = s as usize;
+    for i in 0..n {
+        *((base + i) as *mut u8) = c as u8;
+    }
+}