|
11 | 11 |
|
12 | 12 | use std::fmt::Debug;
|
13 | 13 | use std::marker::PhantomData;
|
| 14 | +use std::ops::Deref; |
14 | 15 |
|
15 | 16 | use vm_memory::ByteValued;
|
16 | 17 |
|
@@ -528,44 +529,36 @@ pub type VhostUserMemoryPayload = Vec<VhostUserMemoryRegion>;
|
528 | 529 | pub struct VhostUserSingleMemoryRegion {
|
529 | 530 | /// Padding for correct alignment
|
530 | 531 | padding: u64,
|
531 |
| - /// Guest physical address of the memory region. |
532 |
| - pub guest_phys_addr: u64, |
533 |
| - /// Size of the memory region. |
534 |
| - pub memory_size: u64, |
535 |
| - /// Virtual address in the current process. |
536 |
| - pub user_addr: u64, |
537 |
| - /// Offset where region starts in the mapped memory. |
538 |
| - pub mmap_offset: u64, |
| 532 | + /// General memory region |
| 533 | + region: VhostUserMemoryRegion, |
| 534 | +} |
| 535 | + |
| 536 | +impl Deref for VhostUserSingleMemoryRegion { |
| 537 | + type Target = VhostUserMemoryRegion; |
| 538 | + |
| 539 | + fn deref(&self) -> &VhostUserMemoryRegion { |
| 540 | + &self.region |
| 541 | + } |
539 | 542 | }
|
540 | 543 |
|
541 | 544 | impl VhostUserSingleMemoryRegion {
|
542 | 545 | /// Create a new instance.
|
543 | 546 | pub fn new(guest_phys_addr: u64, memory_size: u64, user_addr: u64, mmap_offset: u64) -> Self {
|
544 | 547 | VhostUserSingleMemoryRegion {
|
545 | 548 | padding: 0,
|
546 |
| - guest_phys_addr, |
547 |
| - memory_size, |
548 |
| - user_addr, |
549 |
| - mmap_offset, |
| 549 | + region: VhostUserMemoryRegion::new( |
| 550 | + guest_phys_addr, |
| 551 | + memory_size, |
| 552 | + user_addr, |
| 553 | + mmap_offset, |
| 554 | + ), |
550 | 555 | }
|
551 | 556 | }
|
552 | 557 | }
|
553 | 558 |
|
554 | 559 | // SAFETY: Safe because all fields of VhostUserSingleMemoryRegion are POD.
|
555 | 560 | unsafe impl ByteValued for VhostUserSingleMemoryRegion {}
|
556 |
| - |
557 |
| -impl VhostUserMsgValidator for VhostUserSingleMemoryRegion { |
558 |
| - fn is_valid(&self) -> bool { |
559 |
| - if self.memory_size == 0 |
560 |
| - || self.guest_phys_addr.checked_add(self.memory_size).is_none() |
561 |
| - || self.user_addr.checked_add(self.memory_size).is_none() |
562 |
| - || self.mmap_offset.checked_add(self.memory_size).is_none() |
563 |
| - { |
564 |
| - return false; |
565 |
| - } |
566 |
| - true |
567 |
| - } |
568 |
| -} |
| 561 | +impl VhostUserMsgValidator for VhostUserSingleMemoryRegion {} |
569 | 562 |
|
570 | 563 | /// Vring state descriptor.
|
571 | 564 | #[repr(packed)]
|
|
0 commit comments