// SPDX-License-Identifier: BSD-3-Clause use devices::virtio::{wl2, InterruptProxy, InterruptProxyEvent, SingleFd}; use msg_socket::{MsgReceiver, MsgSocket}; use std::collections::BTreeMap; use std::fs::remove_file; use sys_util::{net::UnixSeqpacketListener, GuestMemory}; use vm_control::VmMemoryControlRequestSocket; #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] pub use aarch64::{arch_memory_regions, MemoryParams}; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub use x86_64::{arch_memory_regions, MemoryParams}; type Socket = MsgSocket<(), SingleFd>; fn main() { eprintln!("hello world"); // Create and display the socket. let mut path = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR missing"); path.push_str("/crosvm-wl.sock"); let _ = remove_file(&path); let server = UnixSeqpacketListener::bind(&path).expect("failed to create control socket"); println!("{}", path); // Receive connection from crosvm. let conn = server.accept().expect("accept failed"); let msg_socket: Socket = MsgSocket::new(conn); let mut wl = None; loop { match msg_socket.recv() { Ok(SingleFd { shm, interrupt, interrupt_resample_evt, in_queue, out_queue, vm_socket, use_transition_flags, in_queue_evt, out_queue_evt, kill_evt, }) => { if wl.is_some() { panic!("Received SingleFd twice"); } let shm = shm.owned(); let regions = arch_memory_regions(MemoryParams { size: shm.size(), has_bios: false, }); let mem = GuestMemory::with_memfd(®ions, shm).expect("GuestMemory::with_memfd failed"); let interrupt: MsgSocket = MsgSocket::new(interrupt.owned()); let vm_socket: VmMemoryControlRequestSocket = MsgSocket::new(vm_socket.owned()); let mut wayland_paths = BTreeMap::new(); wayland_paths.insert("".into(), "/run/user/1000/wayland-0".into()); use devices::virtio::VirtioDevice; let mut wl_ = wl2::Wl::new(wayland_paths, vm_socket, None).unwrap(); println!("constructed Wl"); wl_.activate( mem, Box::new(InterruptProxy::new( interrupt, interrupt_resample_evt.owned(), )), vec![in_queue, out_queue], vec![in_queue_evt.owned(), out_queue_evt.owned()], ); println!("activated Wl"); wl = Some(wl_); } Err(e) => panic!("recv failed {:?}", e), } } }