#![no_std]#![no_main]#[allow(non_upper_case_globals)]#[allow(non_snake_case)]#[allow(non_camel_case_types)]#[allow(dead_code)]modvmlinux;useaya_ebpf::{cty::{c_int,c_ulong},macros::{lsm,map},maps::HashMap,programs::LsmContext,};usevmlinux::task_struct;#[map]staticPROCESSES: HashMap<i32,i32>=HashMap::with_max_entries(32768,0);#[lsm(hook = "task_alloc")]pubfntask_alloc(ctx: LsmContext)-> i32{matchunsafe{try_task_alloc(ctx)}{Ok(ret)=>ret,Err(ret)=>ret,}}unsafefntry_task_alloc(ctx: LsmContext)-> Result<i32,i32>{lettask: *consttask_struct=ctx.arg(0);let_clone_flags: c_ulong=ctx.arg(1);letretval: c_int=ctx.arg(2);// Save the PID of a new process in map.letpid=(*task).pid;PROCESSES.insert(&pid,&pid,0).map_err(|e|easi32)?;// Handle results of previous LSM programs.ifretval!=0{returnOk(retval);}Ok(0)}#[panic_handler]fnpanic(_info: &core::panic::PanicInfo)-> !{unsafe{core::hint::unreachable_unchecked()}}