Lines Matching full:bitmap
5 //! Rust API for bitmap.
7 //! C headers: [`include/linux/bitmap.h`](srctree/include/linux/bitmap.h).
17 /// Represents a C bitmap. Wraps underlying C bitmap API.
24 pub struct Bitmap { struct
28 impl Bitmap { impl
29 /// Borrows a C bitmap.
35 /// * the array must not be freed for the lifetime of this [`Bitmap`]
37 pub unsafe fn from_raw<'a>(ptr: *const usize, nbits: usize) -> &'a Bitmap { in from_raw() argument
44 // We are casting `*const [()]` to `*const Bitmap`. The `Bitmap` in from_raw()
50 // pointer as `&Bitmap` is safe given the caller's guarantees. in from_raw()
51 unsafe { &*(data as *const Bitmap) } in from_raw() constant
54 /// Borrows a C bitmap exclusively.
60 /// * the array must not be freed for the lifetime of this [`Bitmap`]
62 pub unsafe fn from_raw_mut<'a>(ptr: *mut usize, nbits: usize) -> &'a mut Bitmap { in from_raw_mut() argument
71 // Similar to `from_raw`, casting `*mut [()]` to `*mut Bitmap` is in from_raw_mut()
72 // safe because `Bitmap` is a ZST with a `data: [()]` field, in from_raw_mut()
74 unsafe { &mut *(data as *mut Bitmap) } in from_raw_mut()
77 /// Returns a raw pointer to the backing [`Bitmap`].
79 core::ptr::from_ref::<Bitmap>(self).cast::<usize>() in as_ptr()
82 /// Returns a mutable raw pointer to the backing [`Bitmap`].
84 core::ptr::from_mut::<Bitmap>(self).cast::<usize>() in as_mut_ptr()
87 /// Returns length of this [`Bitmap`].
94 /// Holds either a pointer to array of `unsigned long` or a small bitmap.
97 bitmap: usize,
121 /// Represents an owned bitmap.
123 /// Wraps underlying C bitmap API. See [`Bitmap`] for available
132 /// use kernel::bitmap::BitmapVec;
157 /// Representation of bitmap.
159 /// Length of this bitmap. Must be `<= i32::MAX`.
164 type Target = Bitmap;
166 fn deref(&self) -> &Bitmap { in deref() argument
168 // SAFETY: Bitmap is represented inline. in deref()
171 core::ptr::addr_of!(self.repr.bitmap) in deref()
174 // SAFETY: Bitmap is represented as array of `unsigned long`. in deref()
178 // SAFETY: We got the right pointer and invariants of [`Bitmap`] hold. in deref()
179 // An inline bitmap is treated like an array with single element. in deref()
180 unsafe { Bitmap::from_raw(ptr, self.nbits) } in deref()
185 fn deref_mut(&mut self) -> &mut Bitmap { in deref_mut() argument
187 // SAFETY: Bitmap is represented inline. in deref_mut()
190 core::ptr::addr_of_mut!(self.repr.bitmap) in deref_mut()
193 // SAFETY: Bitmap is represented as array of `unsigned long`. in deref_mut()
198 // An inline bitmap is treated like an array with single element. in deref_mut()
199 unsafe { Bitmap::from_raw_mut(ptr, self.nbits) } in deref_mut()
205 /// SAFETY: We own the underlying bitmap representation.
210 /// SAFETY: `deref()` will return a reference to a [`Bitmap`]. Its methods
237 repr: BitmapRepr { bitmap: 0 }, in new()
255 /// Returns length of this [`Bitmap`].
262 /// Fills this `Bitmap` with random bits.
278 impl Bitmap { implementation
381 /// Copy `src` into this [`Bitmap`] and set any remaining bits to zero.
387 /// use kernel::bitmap::BitmapVec;
402 pub fn copy_and_extend(&mut self, src: &Bitmap) { in copy_and_extend() argument
421 /// use kernel::bitmap::BitmapVec;
423 /// let bitmap = BitmapVec::new(64, GFP_KERNEL)?;
425 /// match bitmap.last_bit() {
430 /// pr_info!("All bits in this bitmap are 0.\n");
499 let b = unsafe { Bitmap::from_raw(fake_bitmap.as_ptr(), 2 * BITS_PER_LONG) }; in bitmap_borrow()
508 let b = unsafe { Bitmap::from_raw(core::ptr::addr_of!(fake_bitmap), 8) }; in bitmap_copy()