MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / capget

Function capget

src/thread/libcap.rs:142–167  ·  view source on GitHub ↗
(pid: Option<Pid>)

Source from the content-addressed store, hash-verified

140#[inline]
141#[allow(unsafe_code)]
142fn capget(pid: Option<Pid>) -> io::Result<CapabilitySets> {
143 let mut data = [MaybeUninit::<linux_raw_sys::general::__user_cap_data_struct>::uninit(); 2];
144
145 let data = {
146 let mut header = linux_raw_sys::general::__user_cap_header_struct {
147 version: linux_raw_sys::general::_LINUX_CAPABILITY_VERSION_3,
148 pid: Pid::as_raw(pid) as backend::c::c_int,
149 };
150
151 backend::thread::syscalls::capget(&mut header, &mut data)?;
152 // SAFETY: v3 is a 64-bit implementation, so the kernel filled in both
153 // data structs.
154 unsafe { (data[0].assume_init(), data[1].assume_init()) }
155 };
156
157 let effective = u64::from(data.0.effective) | (u64::from(data.1.effective) << u32::BITS);
158 let permitted = u64::from(data.0.permitted) | (u64::from(data.1.permitted) << u32::BITS);
159 let inheritable = u64::from(data.0.inheritable) | (u64::from(data.1.inheritable) << u32::BITS);
160
161 // The kernel returns a partitioned bitset that we just combined above.
162 Ok(CapabilitySets {
163 effective: CapabilitySet::from_bits_retain(effective),
164 permitted: CapabilitySet::from_bits_retain(permitted),
165 inheritable: CapabilitySet::from_bits_retain(inheritable),
166 })
167}
168
169#[inline]
170fn capset(pid: Option<Pid>, sets: CapabilitySets) -> io::Result<()> {

Callers 1

capabilitiesFunction · 0.70

Calls 1

assume_initMethod · 0.80

Tested by

no test coverage detected