fn open_opts_impl()

in src/bpf/pid_iter.skel.rs [192:233]


        fn open_opts_impl(
            self,
            open_opts: *const libbpf_sys::bpf_object_open_opts,
            object: &'obj mut std::mem::MaybeUninit<libbpf_rs::OpenObject>,
        ) -> libbpf_rs::Result<OpenPidIterSkel<'obj>> {
            let skel_config = build_skel_config()?;
            let skel_ptr = skel_config.as_libbpf_object();

            let ret =
                unsafe { libbpf_sys::bpf_object__open_skeleton(skel_ptr.as_ptr(), open_opts) };
            if ret != 0 {
                return Err(libbpf_rs::Error::from_raw_os_error(-ret));
            }

            // SAFETY: `skel_ptr` points to a valid object after the
            //         open call.
            let obj_ptr = unsafe { *skel_ptr.as_ref().obj };
            // SANITY: `bpf_object__open_skeleton` should have
            //         allocated the object.
            let obj_ptr = std::ptr::NonNull::new(obj_ptr).unwrap();
            // SAFETY: `obj_ptr` points to an opened object after
            //         skeleton open.
            let obj = unsafe { libbpf_rs::OpenObject::from_ptr(obj_ptr) };
            let _obj = object.write(obj);
            // SAFETY: We just wrote initialized data to `object`.
            let mut obj_ref = unsafe { OwnedRef::new(object) };

            #[allow(unused_mut)]
            let mut skel = OpenPidIterSkel {
                maps: unsafe { OpenPidIterMaps::new(&skel_config, obj_ref.as_mut())? },
                progs: unsafe { OpenPidIterProgs::new(obj_ref.as_mut())? },
                obj: obj_ref,
                // SAFETY: Our `struct_ops` type contains only pointers,
                //         which are allowed to be NULL.
                // TODO: Generate and use a `Default` representation
                //       instead, to cut down on unsafe code.
                struct_ops: unsafe { std::mem::zeroed() },
                skel_config,
            };

            Ok(skel)
        }