MCPcopy Create free account
hub / github.com/RustCV/RustCV / mmap_buffer

Function mmap_buffer

rustcv-camera/src/backend/linux/sys.rs:405–421  ·  view source on GitHub ↗

Memory-map a V4L2 buffer into user space. 将 V4L2 缓冲区内存映射到用户空间。 Uses `MAP_SHARED` so user space and kernel see the same physical memory (zero-copy). Uses `PROT_READ | PROT_WRITE` — read for frame data access, write for kernel DMA. 使用 `MAP_SHARED` 使用户空间和内核看到同一块物理内存(零拷贝)。 使用 `PROT_READ | PROT_WRITE` —— 读用于帧数据访问,写用于内核 DMA。

(fd: RawFd, length: usize, offset: u32)

Source from the content-addressed store, hash-verified

403/// 使用 `MAP_SHARED` 使用户空间和内核看到同一块物理内存(零拷贝)。
404/// 使用 `PROT_READ | PROT_WRITE` —— 读用于帧数据访问,写用于内核 DMA。
405pub fn mmap_buffer(fd: RawFd, length: usize, offset: u32) -> io::Result<*mut u8> {
406 let ptr = unsafe {
407 libc::mmap(
408 std::ptr::null_mut(),
409 length,
410 libc::PROT_READ | libc::PROT_WRITE,
411 libc::MAP_SHARED,
412 fd,
413 offset as libc::off_t,
414 )
415 };
416 if ptr == libc::MAP_FAILED {
417 Err(io::Error::last_os_error())
418 } else {
419 Ok(ptr as *mut u8)
420 }
421}
422
423/// Unmap a previously mapped buffer.
424/// 解除先前映射的缓冲区。

Callers 1

allocate_buffersMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected