1 // Copyright (C) 2019 Alibaba Cloud Computing. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause 3 // 4 // Portions Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 // 6 // Portions Copyright 2017 The Chromium OS Authors. All rights reserved. 7 // Use of this source code is governed by a BSD-style license that can be 8 // found in the LICENSE-BSD-Google file. 9 10 /* Auto-generated by bindgen then manually edited for simplicity */ 11 12 #![allow(non_upper_case_globals)] 13 #![allow(non_camel_case_types)] 14 #![allow(non_snake_case)] 15 #![allow(missing_docs)] 16 #![allow(clippy::missing_safety_doc)] 17 18 use crate::{Error, Result}; 19 use std::os::raw; 20 21 pub const VHOST: raw::c_uint = 0xaf; 22 pub const VHOST_VRING_F_LOG: raw::c_uint = 0; 23 pub const VHOST_ACCESS_RO: raw::c_uchar = 1; 24 pub const VHOST_ACCESS_WO: raw::c_uchar = 2; 25 pub const VHOST_ACCESS_RW: raw::c_uchar = 3; 26 pub const VHOST_IOTLB_MISS: raw::c_uchar = 1; 27 pub const VHOST_IOTLB_UPDATE: raw::c_uchar = 2; 28 pub const VHOST_IOTLB_INVALIDATE: raw::c_uchar = 3; 29 pub const VHOST_IOTLB_ACCESS_FAIL: raw::c_uchar = 4; 30 pub const VHOST_IOTLB_BATCH_BEGIN: raw::c_uchar = 5; 31 pub const VHOST_IOTLB_BATCH_END: raw::c_uchar = 6; 32 pub const VHOST_IOTLB_MSG: raw::c_int = 1; 33 pub const VHOST_IOTLB_MSG_V2: raw::c_uint = 2; 34 pub const VHOST_PAGE_SIZE: raw::c_uint = 4096; 35 pub const VHOST_VIRTIO: raw::c_uint = 175; 36 pub const VHOST_VRING_LITTLE_ENDIAN: raw::c_uint = 0; 37 pub const VHOST_VRING_BIG_ENDIAN: raw::c_uint = 1; 38 pub const VHOST_F_LOG_ALL: raw::c_uint = 26; 39 pub const VHOST_NET_F_VIRTIO_NET_HDR: raw::c_uint = 27; 40 pub const VHOST_SCSI_ABI_VERSION: raw::c_uint = 1; 41 pub const VHOST_BACKEND_F_IOTLB_MSG_V2: raw::c_ulonglong = 0x1; 42 pub const VHOST_BACKEND_F_IOTLB_BATCH: raw::c_ulonglong = 0x2; 43 pub const VHOST_BACKEND_F_IOTLB_ASID: raw::c_ulonglong = 0x3; 44 pub const VHOST_BACKEND_F_SUSPEND: raw::c_ulonglong = 0x4; 45 46 ioctl_ior_nr!(VHOST_GET_FEATURES, VHOST, 0x00, raw::c_ulonglong); 47 ioctl_iow_nr!(VHOST_SET_FEATURES, VHOST, 0x00, raw::c_ulonglong); 48 ioctl_io_nr!(VHOST_SET_OWNER, VHOST, 0x01); 49 ioctl_io_nr!(VHOST_RESET_OWNER, VHOST, 0x02); 50 ioctl_iow_nr!(VHOST_SET_MEM_TABLE, VHOST, 0x03, vhost_memory); 51 ioctl_iow_nr!(VHOST_SET_LOG_BASE, VHOST, 0x04, raw::c_ulonglong); 52 ioctl_iow_nr!(VHOST_SET_LOG_FD, VHOST, 0x07, raw::c_int); 53 ioctl_iow_nr!(VHOST_SET_VRING_NUM, VHOST, 0x10, vhost_vring_state); 54 ioctl_iow_nr!(VHOST_SET_VRING_ADDR, VHOST, 0x11, vhost_vring_addr); 55 ioctl_iow_nr!(VHOST_SET_VRING_BASE, VHOST, 0x12, vhost_vring_state); 56 ioctl_iowr_nr!(VHOST_GET_VRING_BASE, VHOST, 0x12, vhost_vring_state); 57 ioctl_iow_nr!(VHOST_SET_VRING_KICK, VHOST, 0x20, vhost_vring_file); 58 ioctl_iow_nr!(VHOST_SET_VRING_CALL, VHOST, 0x21, vhost_vring_file); 59 ioctl_iow_nr!(VHOST_SET_VRING_ERR, VHOST, 0x22, vhost_vring_file); 60 ioctl_iow_nr!(VHOST_SET_BACKEND_FEATURES, VHOST, 0x25, raw::c_ulonglong); 61 ioctl_ior_nr!(VHOST_GET_BACKEND_FEATURES, VHOST, 0x26, raw::c_ulonglong); 62 ioctl_iow_nr!(VHOST_NET_SET_BACKEND, VHOST, 0x30, vhost_vring_file); 63 ioctl_iow_nr!(VHOST_SCSI_SET_ENDPOINT, VHOST, 0x40, vhost_scsi_target); 64 ioctl_iow_nr!(VHOST_SCSI_CLEAR_ENDPOINT, VHOST, 0x41, vhost_scsi_target); 65 ioctl_iow_nr!(VHOST_SCSI_GET_ABI_VERSION, VHOST, 0x42, raw::c_int); 66 ioctl_iow_nr!(VHOST_SCSI_SET_EVENTS_MISSED, VHOST, 0x43, raw::c_uint); 67 ioctl_iow_nr!(VHOST_SCSI_GET_EVENTS_MISSED, VHOST, 0x44, raw::c_uint); 68 ioctl_iow_nr!(VHOST_VSOCK_SET_GUEST_CID, VHOST, 0x60, raw::c_ulonglong); 69 ioctl_iow_nr!(VHOST_VSOCK_SET_RUNNING, VHOST, 0x61, raw::c_int); 70 ioctl_ior_nr!(VHOST_VDPA_GET_DEVICE_ID, VHOST, 0x70, raw::c_uint); 71 ioctl_ior_nr!(VHOST_VDPA_GET_STATUS, VHOST, 0x71, raw::c_uchar); 72 ioctl_iow_nr!(VHOST_VDPA_SET_STATUS, VHOST, 0x72, raw::c_uchar); 73 ioctl_ior_nr!(VHOST_VDPA_GET_CONFIG, VHOST, 0x73, vhost_vdpa_config); 74 ioctl_iow_nr!(VHOST_VDPA_SET_CONFIG, VHOST, 0x74, vhost_vdpa_config); 75 ioctl_iow_nr!(VHOST_VDPA_SET_VRING_ENABLE, VHOST, 0x75, vhost_vring_state); 76 ioctl_ior_nr!(VHOST_VDPA_GET_VRING_NUM, VHOST, 0x76, raw::c_ushort); 77 ioctl_iow_nr!(VHOST_VDPA_SET_CONFIG_CALL, VHOST, 0x77, raw::c_int); 78 ioctl_ior_nr!( 79 VHOST_VDPA_GET_IOVA_RANGE, 80 VHOST, 81 0x78, 82 vhost_vdpa_iova_range 83 ); 84 ioctl_ior_nr!(VHOST_VDPA_GET_CONFIG_SIZE, VHOST, 0x79, raw::c_uint); 85 ioctl_ior_nr!(VHOST_VDPA_GET_VQS_COUNT, VHOST, 0x80, raw::c_uint); 86 ioctl_ior_nr!(VHOST_VDPA_GET_GROUP_NUM, VHOST, 0x81, raw::c_uint); 87 ioctl_ior_nr!(VHOST_VDPA_GET_AS_NUM, VHOST, 0x7a, raw::c_uint); 88 ioctl_iowr_nr!(VHOST_VDPA_GET_VRING_GROUP, VHOST, 0x7b, vhost_vring_state); 89 ioctl_iow_nr!(VHOST_VDPA_SET_GROUP_ASID, VHOST, 0x7c, vhost_vring_state); 90 ioctl_io_nr!(VHOST_VDPA_SUSPEND, VHOST, 0x7d); 91 92 #[repr(C)] 93 #[derive(Default)] 94 pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); 95 96 impl<T> __IncompleteArrayField<T> { 97 #[inline] new() -> Self98 pub fn new() -> Self { 99 __IncompleteArrayField(::std::marker::PhantomData) 100 } 101 102 #[inline] 103 #[allow(clippy::trivially_copy_pass_by_ref)] 104 #[allow(clippy::useless_transmute)] as_ptr(&self) -> *const T105 pub unsafe fn as_ptr(&self) -> *const T { 106 ::std::mem::transmute(self) 107 } 108 109 #[inline] 110 #[allow(clippy::useless_transmute)] as_mut_ptr(&mut self) -> *mut T111 pub unsafe fn as_mut_ptr(&mut self) -> *mut T { 112 ::std::mem::transmute(self) 113 } 114 115 #[inline] as_slice(&self, len: usize) -> &[T]116 pub unsafe fn as_slice(&self, len: usize) -> &[T] { 117 ::std::slice::from_raw_parts(self.as_ptr(), len) 118 } 119 120 #[inline] as_mut_slice(&mut self, len: usize) -> &mut [T]121 pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { 122 ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) 123 } 124 } 125 126 impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result127 fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { 128 fmt.write_str("__IncompleteArrayField") 129 } 130 } 131 132 impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { 133 #[inline] clone(&self) -> Self134 fn clone(&self) -> Self { 135 *self 136 } 137 } 138 139 impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {} 140 141 #[repr(C)] 142 #[derive(Debug, Default, Copy, Clone)] 143 pub struct vhost_vring_state { 144 pub index: raw::c_uint, 145 pub num: raw::c_uint, 146 } 147 148 #[repr(C)] 149 #[derive(Debug, Default, Copy, Clone)] 150 pub struct vhost_vring_file { 151 pub index: raw::c_uint, 152 pub fd: raw::c_int, 153 } 154 155 #[repr(C)] 156 #[derive(Debug, Default, Copy, Clone)] 157 pub struct vhost_vring_addr { 158 pub index: raw::c_uint, 159 pub flags: raw::c_uint, 160 pub desc_user_addr: raw::c_ulonglong, 161 pub used_user_addr: raw::c_ulonglong, 162 pub avail_user_addr: raw::c_ulonglong, 163 pub log_guest_addr: raw::c_ulonglong, 164 } 165 166 #[repr(C)] 167 #[derive(Debug, Default, Copy, Clone)] 168 pub struct vhost_iotlb_msg { 169 pub iova: raw::c_ulonglong, 170 pub size: raw::c_ulonglong, 171 pub uaddr: raw::c_ulonglong, 172 pub perm: raw::c_uchar, 173 pub type_: raw::c_uchar, 174 } 175 176 #[repr(C)] 177 #[derive(Copy, Clone)] 178 pub struct vhost_msg { 179 pub type_: raw::c_int, 180 pub __bindgen_anon_1: vhost_msg__bindgen_ty_1, 181 } 182 183 impl Default for vhost_msg { default() -> Self184 fn default() -> Self { 185 // SAFETY: Zeroing all bytes is fine because they represent a valid 186 // value for all members of the structure 187 unsafe { ::std::mem::zeroed() } 188 } 189 } 190 191 #[repr(C)] 192 #[derive(Copy, Clone)] 193 pub union vhost_msg__bindgen_ty_1 { 194 pub iotlb: vhost_iotlb_msg, 195 pub padding: [raw::c_uchar; 64usize], 196 _bindgen_union_align: [u64; 8usize], 197 } 198 199 impl Default for vhost_msg__bindgen_ty_1 { default() -> Self200 fn default() -> Self { 201 // SAFETY: Zeroing all bytes is fine because they represent a valid 202 // value for all members of the structure 203 unsafe { ::std::mem::zeroed() } 204 } 205 } 206 207 #[repr(C)] 208 #[derive(Copy, Clone)] 209 pub struct vhost_msg_v2 { 210 pub type_: raw::c_uint, 211 pub reserved: raw::c_uint, 212 pub __bindgen_anon_1: vhost_msg_v2__bindgen_ty_1, 213 } 214 215 impl Default for vhost_msg_v2 { default() -> Self216 fn default() -> Self { 217 // SAFETY: Zeroing all bytes is fine because they represent a valid 218 // value for all members of the structure 219 unsafe { ::std::mem::zeroed() } 220 } 221 } 222 223 #[repr(C)] 224 #[derive(Copy, Clone)] 225 pub union vhost_msg_v2__bindgen_ty_1 { 226 pub iotlb: vhost_iotlb_msg, 227 pub padding: [raw::c_uchar; 64usize], 228 _bindgen_union_align: [u64; 8usize], 229 } 230 231 impl Default for vhost_msg_v2__bindgen_ty_1 { default() -> Self232 fn default() -> Self { 233 // SAFETY: Zeroing all bytes is fine because they represent a valid 234 // value for all members of the structure 235 unsafe { ::std::mem::zeroed() } 236 } 237 } 238 239 #[repr(C)] 240 #[derive(Debug, Default, Copy, Clone)] 241 pub struct vhost_memory_region { 242 pub guest_phys_addr: raw::c_ulonglong, 243 pub memory_size: raw::c_ulonglong, 244 pub userspace_addr: raw::c_ulonglong, 245 pub flags_padding: raw::c_ulonglong, 246 } 247 248 #[repr(C)] 249 #[derive(Debug, Default, Clone)] 250 pub struct vhost_memory { 251 pub nregions: raw::c_uint, 252 pub padding: raw::c_uint, 253 pub regions: __IncompleteArrayField<vhost_memory_region>, 254 __force_alignment: [u64; 0], 255 } 256 257 #[repr(C)] 258 #[derive(Copy, Clone)] 259 pub struct vhost_scsi_target { 260 pub abi_version: raw::c_int, 261 pub vhost_wwpn: [raw::c_char; 224usize], 262 pub vhost_tpgt: raw::c_ushort, 263 pub reserved: raw::c_ushort, 264 } 265 266 impl Default for vhost_scsi_target { default() -> Self267 fn default() -> Self { 268 // SAFETY: Zeroing all bytes is fine because they represent a valid 269 // value for all members of the structure 270 unsafe { ::std::mem::zeroed() } 271 } 272 } 273 274 #[repr(C)] 275 #[derive(Debug, Default)] 276 pub struct vhost_vdpa_config { 277 pub off: raw::c_uint, 278 pub len: raw::c_uint, 279 pub buf: __IncompleteArrayField<raw::c_uchar>, 280 } 281 282 #[repr(C)] 283 #[derive(Debug, Copy, Clone)] 284 pub struct vhost_vdpa_iova_range { 285 pub first: raw::c_ulonglong, 286 pub last: raw::c_ulonglong, 287 } 288 289 /// Helper to support vhost::set_mem_table() 290 pub struct VhostMemory { 291 buf: Vec<vhost_memory>, 292 } 293 294 impl VhostMemory { 295 // Limit number of regions to u16 to simplify error handling new(entries: u16) -> Self296 pub fn new(entries: u16) -> Self { 297 let size = std::mem::size_of::<vhost_memory_region>() * entries as usize; 298 let count = (size + 2 * std::mem::size_of::<vhost_memory>() - 1) 299 / std::mem::size_of::<vhost_memory>(); 300 let mut buf: Vec<vhost_memory> = vec![Default::default(); count]; 301 buf[0].nregions = u32::from(entries); 302 VhostMemory { buf } 303 } 304 as_ptr(&self) -> *const char305 pub fn as_ptr(&self) -> *const char { 306 &self.buf[0] as *const vhost_memory as *const char 307 } 308 get_header(&self) -> &vhost_memory309 pub fn get_header(&self) -> &vhost_memory { 310 &self.buf[0] 311 } 312 get_region(&self, index: u32) -> Option<&vhost_memory_region>313 pub fn get_region(&self, index: u32) -> Option<&vhost_memory_region> { 314 if index >= self.buf[0].nregions { 315 return None; 316 } 317 // SAFETY: Safe because we have allocated enough space nregions 318 let regions = unsafe { self.buf[0].regions.as_slice(self.buf[0].nregions as usize) }; 319 Some(®ions[index as usize]) 320 } 321 set_region(&mut self, index: u32, region: &vhost_memory_region) -> Result<()>322 pub fn set_region(&mut self, index: u32, region: &vhost_memory_region) -> Result<()> { 323 if index >= self.buf[0].nregions { 324 return Err(Error::InvalidGuestMemory); 325 } 326 // SAFETY: Safe because we have allocated enough space nregions and checked the index. 327 let regions = unsafe { self.buf[0].regions.as_mut_slice(index as usize + 1) }; 328 regions[index as usize] = *region; 329 Ok(()) 330 } 331 } 332 333 #[cfg(test)] 334 mod tests { 335 use super::*; 336 337 #[test] bindgen_test_layout_vhost_vring_state()338 fn bindgen_test_layout_vhost_vring_state() { 339 assert_eq!( 340 ::std::mem::size_of::<vhost_vring_state>(), 341 8usize, 342 concat!("Size of: ", stringify!(vhost_vring_state)) 343 ); 344 assert_eq!( 345 ::std::mem::align_of::<vhost_vring_state>(), 346 4usize, 347 concat!("Alignment of ", stringify!(vhost_vring_state)) 348 ); 349 } 350 351 #[test] bindgen_test_layout_vhost_vring_file()352 fn bindgen_test_layout_vhost_vring_file() { 353 assert_eq!( 354 ::std::mem::size_of::<vhost_vring_file>(), 355 8usize, 356 concat!("Size of: ", stringify!(vhost_vring_file)) 357 ); 358 assert_eq!( 359 ::std::mem::align_of::<vhost_vring_file>(), 360 4usize, 361 concat!("Alignment of ", stringify!(vhost_vring_file)) 362 ); 363 } 364 365 #[test] bindgen_test_layout_vhost_vring_addr()366 fn bindgen_test_layout_vhost_vring_addr() { 367 assert_eq!( 368 ::std::mem::size_of::<vhost_vring_addr>(), 369 40usize, 370 concat!("Size of: ", stringify!(vhost_vring_addr)) 371 ); 372 assert_eq!( 373 ::std::mem::align_of::<vhost_vring_addr>(), 374 8usize, 375 concat!("Alignment of ", stringify!(vhost_vring_addr)) 376 ); 377 } 378 379 #[test] bindgen_test_layout_vhost_msg__bindgen_ty_1()380 fn bindgen_test_layout_vhost_msg__bindgen_ty_1() { 381 assert_eq!( 382 ::std::mem::size_of::<vhost_msg__bindgen_ty_1>(), 383 64usize, 384 concat!("Size of: ", stringify!(vhost_msg__bindgen_ty_1)) 385 ); 386 assert_eq!( 387 ::std::mem::align_of::<vhost_msg__bindgen_ty_1>(), 388 8usize, 389 concat!("Alignment of ", stringify!(vhost_msg__bindgen_ty_1)) 390 ); 391 } 392 393 #[test] bindgen_test_layout_vhost_msg()394 fn bindgen_test_layout_vhost_msg() { 395 assert_eq!( 396 ::std::mem::size_of::<vhost_msg>(), 397 72usize, 398 concat!("Size of: ", stringify!(vhost_msg)) 399 ); 400 assert_eq!( 401 ::std::mem::align_of::<vhost_msg>(), 402 8usize, 403 concat!("Alignment of ", stringify!(vhost_msg)) 404 ); 405 } 406 407 #[test] bindgen_test_layout_vhost_msg_v2__bindgen_ty_1()408 fn bindgen_test_layout_vhost_msg_v2__bindgen_ty_1() { 409 assert_eq!( 410 ::std::mem::size_of::<vhost_msg_v2__bindgen_ty_1>(), 411 64usize, 412 concat!("Size of: ", stringify!(vhost_msg_v2__bindgen_ty_1)) 413 ); 414 assert_eq!( 415 ::std::mem::align_of::<vhost_msg_v2__bindgen_ty_1>(), 416 8usize, 417 concat!("Alignment of ", stringify!(vhost_msg_v2__bindgen_ty_1)) 418 ); 419 } 420 421 #[test] bindgen_test_layout_vhost_msg_v2()422 fn bindgen_test_layout_vhost_msg_v2() { 423 assert_eq!( 424 ::std::mem::size_of::<vhost_msg_v2>(), 425 72usize, 426 concat!("Size of: ", stringify!(vhost_msg_v2)) 427 ); 428 assert_eq!( 429 ::std::mem::align_of::<vhost_msg_v2>(), 430 8usize, 431 concat!("Alignment of ", stringify!(vhost_msg_v2)) 432 ); 433 } 434 435 #[test] bindgen_test_layout_vhost_memory_region()436 fn bindgen_test_layout_vhost_memory_region() { 437 assert_eq!( 438 ::std::mem::size_of::<vhost_memory_region>(), 439 32usize, 440 concat!("Size of: ", stringify!(vhost_memory_region)) 441 ); 442 assert_eq!( 443 ::std::mem::align_of::<vhost_memory_region>(), 444 8usize, 445 concat!("Alignment of ", stringify!(vhost_memory_region)) 446 ); 447 } 448 449 #[test] bindgen_test_layout_vhost_memory()450 fn bindgen_test_layout_vhost_memory() { 451 assert_eq!( 452 ::std::mem::size_of::<vhost_memory>(), 453 8usize, 454 concat!("Size of: ", stringify!(vhost_memory)) 455 ); 456 assert_eq!( 457 ::std::mem::align_of::<vhost_memory>(), 458 8usize, 459 concat!("Alignment of ", stringify!(vhost_memory)) 460 ); 461 } 462 463 #[test] bindgen_test_layout_vhost_iotlb_msg()464 fn bindgen_test_layout_vhost_iotlb_msg() { 465 assert_eq!( 466 ::std::mem::size_of::<vhost_iotlb_msg>(), 467 32usize, 468 concat!("Size of: ", stringify!(vhost_iotlb_msg)) 469 ); 470 assert_eq!( 471 ::std::mem::align_of::<vhost_iotlb_msg>(), 472 8usize, 473 concat!("Alignment of ", stringify!(vhost_iotlb_msg)) 474 ); 475 } 476 477 #[test] bindgen_test_layout_vhost_scsi_target()478 fn bindgen_test_layout_vhost_scsi_target() { 479 assert_eq!( 480 ::std::mem::size_of::<vhost_scsi_target>(), 481 232usize, 482 concat!("Size of: ", stringify!(vhost_scsi_target)) 483 ); 484 assert_eq!( 485 ::std::mem::align_of::<vhost_scsi_target>(), 486 4usize, 487 concat!("Alignment of ", stringify!(vhost_scsi_target)) 488 ); 489 } 490 491 #[test] bindgen_test_layout_vhost_vdpa_config()492 fn bindgen_test_layout_vhost_vdpa_config() { 493 assert_eq!( 494 ::std::mem::size_of::<vhost_vdpa_config>(), 495 8usize, 496 concat!("Size of: ", stringify!(vhost_vdpa_config)) 497 ); 498 assert_eq!( 499 ::std::mem::align_of::<vhost_vdpa_config>(), 500 4usize, 501 concat!("Alignment of ", stringify!(vhost_vdpa_config)) 502 ); 503 } 504 505 #[test] bindgen_test_layout_vhost_vdpa_iova_range()506 fn bindgen_test_layout_vhost_vdpa_iova_range() { 507 assert_eq!( 508 ::std::mem::size_of::<vhost_vdpa_iova_range>(), 509 16usize, 510 concat!("Size of: ", stringify!(vhost_vdpa_iova_range)) 511 ); 512 assert_eq!( 513 ::std::mem::align_of::<vhost_vdpa_iova_range>(), 514 8usize, 515 concat!("Alignment of ", stringify!(vhost_vdpa_iova_range)) 516 ); 517 } 518 519 #[test] test_vhostmemory()520 fn test_vhostmemory() { 521 let mut obj = VhostMemory::new(2); 522 let region = vhost_memory_region { 523 guest_phys_addr: 0x1000u64, 524 memory_size: 0x2000u64, 525 userspace_addr: 0x300000u64, 526 flags_padding: 0u64, 527 }; 528 assert!(obj.get_region(2).is_none()); 529 530 { 531 let header = obj.get_header(); 532 assert_eq!(header.nregions, 2u32); 533 } 534 { 535 assert!(obj.set_region(0, ®ion).is_ok()); 536 assert!(obj.set_region(1, ®ion).is_ok()); 537 assert!(obj.set_region(2, ®ion).is_err()); 538 } 539 540 let region1 = obj.get_region(1).unwrap(); 541 assert_eq!(region1.guest_phys_addr, 0x1000u64); 542 assert_eq!(region1.memory_size, 0x2000u64); 543 assert_eq!(region1.userspace_addr, 0x300000u64); 544 } 545 } 546