mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-12-24 11:58:41 +00:00
usb_util: add sandboxed-libusb feature
make open_fd patch optional. if sandboxed-libusb feature is not selected, open_fd is not required. In this case, the code must have access to /dev/bus/usb, and not external fd is needed. BUG=chromium:831850 TEST=cargo test Change-Id: I21fa87dd15d08a03c2fe2b190559abbe6f63dcd5 Reviewed-on: https://chromium-review.googlesource.com/1375019 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Jingkui Wang <jkwang@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
parent
f8a6bdddb7
commit
7df5a0ef1a
3 changed files with 8 additions and 4 deletions
|
@ -17,6 +17,7 @@ default-no-sandbox = []
|
|||
wl-dmabuf = ["devices/wl-dmabuf", "gpu_buffer", "resources/wl-dmabuf"]
|
||||
gpu = ["devices/gpu"]
|
||||
usb-emulation = ["usb_util"]
|
||||
sandboxed-libusb = ["usb_util/sandboxed-libusb"]
|
||||
|
||||
[dependencies]
|
||||
arch = { path = "arch" }
|
||||
|
|
|
@ -4,6 +4,9 @@ version = "0.1.0"
|
|||
authors = ["The Chromium OS Authors"]
|
||||
build = "build.rs"
|
||||
|
||||
[features]
|
||||
sandboxed-libusb = []
|
||||
|
||||
[dependencies]
|
||||
assertions = { path = "../assertions" }
|
||||
data_model = { path = "../data_model" }
|
||||
|
|
|
@ -110,11 +110,11 @@ impl LibUsbDevice {
|
|||
|
||||
/// Get device handle of this device. Take an external fd. This function is only safe when fd
|
||||
/// is an fd of this usb device.
|
||||
#[cfg(feature = "sandboxed-libusb")]
|
||||
pub unsafe fn open_fd(&self, fd: RawFd) -> Result<DeviceHandle> {
|
||||
let mut handle: *mut bindings::libusb_device_handle = std::ptr::null_mut();
|
||||
// Safe because 'self.device' is constructed from libusb device list and handle is on stack.
|
||||
try_libusb!(unsafe { bindings::libusb_open_fd(self.device, fd, &mut handle) });
|
||||
// Safe because handle is successfully initialized with libusb_open_fd.
|
||||
Ok(unsafe { DeviceHandle::new(self._context.clone(), handle) })
|
||||
// Safe when 'self.device' is constructed from libusb device list and handle is on stack.
|
||||
try_libusb!(bindings::libusb_open_fd(self.device, fd, &mut handle));
|
||||
Ok(DeviceHandle::new(self._context.clone(), handle))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue