1 use alloc::sync::Arc; 2 use system_error::SystemError; 3 4 use crate::{arch::MMArch, include::bindings::bindings::PAGE_OFFSET}; 5 6 use core::{ 7 cmp, 8 fmt::Debug, 9 intrinsics::unlikely, 10 ops::{Add, AddAssign, Sub, SubAssign}, 11 ptr, 12 sync::atomic::{AtomicBool, Ordering}, 13 }; 14 15 use self::{ 16 allocator::page_frame::{VirtPageFrame, VirtPageFrameIter}, 17 page::round_up_to_page_size, 18 ucontext::{AddressSpace, UserMapper}, 19 }; 20 21 pub mod allocator; 22 pub mod c_adapter; 23 pub mod early_ioremap; 24 pub mod kernel_mapper; 25 pub mod memblock; 26 pub mod mmio_buddy; 27 pub mod no_init; 28 pub mod page; 29 pub mod percpu; 30 pub mod syscall; 31 pub mod ucontext; 32 33 /// 内核INIT进程的用户地址空间结构体(仅在process_init中初始化) 34 static mut __INITIAL_PROCESS_ADDRESS_SPACE: Option<Arc<AddressSpace>> = None; 35 36 /// 获取内核INIT进程的用户地址空间结构体 37 #[allow(non_snake_case)] 38 #[inline(always)] 39 pub fn INITIAL_PROCESS_ADDRESS_SPACE() -> Arc<AddressSpace> { 40 unsafe { 41 return __INITIAL_PROCESS_ADDRESS_SPACE 42 .as_ref() 43 .expect("INITIAL_PROCESS_ADDRESS_SPACE is null") 44 .clone(); 45 } 46 } 47 48 /// 设置内核INIT进程的用户地址空间结构体全局变量 49 #[allow(non_snake_case)] 50 pub unsafe fn set_INITIAL_PROCESS_ADDRESS_SPACE(address_space: Arc<AddressSpace>) { 51 static INITIALIZED: AtomicBool = AtomicBool::new(false); 52 if INITIALIZED 53 .compare_exchange(false, true, Ordering::SeqCst, Ordering::Acquire) 54 .is_err() 55 { 56 panic!("INITIAL_PROCESS_ADDRESS_SPACE is already initialized"); 57 } 58 __INITIAL_PROCESS_ADDRESS_SPACE = Some(address_space); 59 } 60 61 /// @brief 将内核空间的虚拟地址转换为物理地址 62 #[inline(always)] 63 pub fn virt_2_phys(addr: usize) -> usize { 64 addr - PAGE_OFFSET as usize 65 } 66 67 /// @brief 将物理地址转换为内核空间的虚拟地址 68 #[inline(always)] 69 pub fn phys_2_virt(addr: usize) -> usize { 70 addr + PAGE_OFFSET as usize 71 } 72 73 #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] 74 pub enum PageTableKind { 75 /// 用户可访问的页表 76 User, 77 /// 内核页表 78 Kernel, 79 /// 内存虚拟化中使用的EPT 80 EPT, 81 } 82 83 /// 物理内存地址 84 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd, Hash)] 85 #[repr(transparent)] 86 pub struct PhysAddr(usize); 87 88 impl PhysAddr { 89 #[inline(always)] 90 pub const fn new(address: usize) -> Self { 91 Self(address) 92 } 93 94 /// @brief 获取物理地址的值 95 #[inline(always)] 96 pub const fn data(&self) -> usize { 97 self.0 98 } 99 100 /// @brief 将物理地址加上一个偏移量 101 #[inline(always)] 102 pub fn add(self, offset: usize) -> Self { 103 Self(self.0 + offset) 104 } 105 106 /// @brief 判断物理地址是否按照指定要求对齐 107 #[inline(always)] 108 pub fn check_aligned(&self, align: usize) -> bool { 109 return self.0 & (align - 1) == 0; 110 } 111 112 #[inline(always)] 113 pub fn is_null(&self) -> bool { 114 return self.0 == 0; 115 } 116 } 117 118 impl Debug for PhysAddr { 119 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 120 write!(f, "PhysAddr({:#x})", self.0) 121 } 122 } 123 124 impl core::ops::Add<usize> for PhysAddr { 125 type Output = Self; 126 127 #[inline(always)] 128 fn add(self, rhs: usize) -> Self::Output { 129 return Self(self.0 + rhs); 130 } 131 } 132 133 impl core::ops::AddAssign<usize> for PhysAddr { 134 #[inline(always)] 135 fn add_assign(&mut self, rhs: usize) { 136 self.0 += rhs; 137 } 138 } 139 140 impl core::ops::Add<PhysAddr> for PhysAddr { 141 type Output = Self; 142 143 #[inline(always)] 144 fn add(self, rhs: PhysAddr) -> Self::Output { 145 return Self(self.0 + rhs.0); 146 } 147 } 148 149 impl core::ops::AddAssign<PhysAddr> for PhysAddr { 150 #[inline(always)] 151 fn add_assign(&mut self, rhs: PhysAddr) { 152 self.0 += rhs.0; 153 } 154 } 155 156 impl core::ops::BitOrAssign<usize> for PhysAddr { 157 #[inline(always)] 158 fn bitor_assign(&mut self, rhs: usize) { 159 self.0 |= rhs; 160 } 161 } 162 163 impl core::ops::BitOrAssign<PhysAddr> for PhysAddr { 164 #[inline(always)] 165 fn bitor_assign(&mut self, rhs: PhysAddr) { 166 self.0 |= rhs.0; 167 } 168 } 169 170 impl core::ops::Sub<usize> for PhysAddr { 171 type Output = Self; 172 173 #[inline(always)] 174 fn sub(self, rhs: usize) -> Self::Output { 175 return Self(self.0 - rhs); 176 } 177 } 178 179 impl core::ops::SubAssign<usize> for PhysAddr { 180 #[inline(always)] 181 fn sub_assign(&mut self, rhs: usize) { 182 self.0 -= rhs; 183 } 184 } 185 186 impl core::ops::Sub<PhysAddr> for PhysAddr { 187 type Output = usize; 188 189 #[inline(always)] 190 fn sub(self, rhs: PhysAddr) -> Self::Output { 191 return self.0 - rhs.0; 192 } 193 } 194 195 impl core::ops::SubAssign<PhysAddr> for PhysAddr { 196 #[inline(always)] 197 fn sub_assign(&mut self, rhs: PhysAddr) { 198 self.0 -= rhs.0; 199 } 200 } 201 202 /// 虚拟内存地址 203 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd, Hash)] 204 #[repr(transparent)] 205 pub struct VirtAddr(usize); 206 207 impl VirtAddr { 208 #[inline(always)] 209 pub const fn new(address: usize) -> Self { 210 return Self(address); 211 } 212 213 /// @brief 获取虚拟地址的值 214 #[inline(always)] 215 pub const fn data(&self) -> usize { 216 return self.0; 217 } 218 219 /// @brief 判断虚拟地址的类型 220 #[inline(always)] 221 pub fn kind(&self) -> PageTableKind { 222 if self.check_user() { 223 return PageTableKind::User; 224 } else { 225 return PageTableKind::Kernel; 226 } 227 } 228 229 /// @brief 判断虚拟地址是否按照指定要求对齐 230 #[inline(always)] 231 pub fn check_aligned(&self, align: usize) -> bool { 232 return self.0 & (align - 1) == 0; 233 } 234 235 /// @brief 判断虚拟地址是否在用户空间 236 #[inline(always)] 237 pub fn check_user(&self) -> bool { 238 if self < &MMArch::USER_END_VADDR { 239 return true; 240 } else { 241 return false; 242 } 243 } 244 245 #[inline(always)] 246 pub fn as_ptr<T>(self) -> *mut T { 247 return self.0 as *mut T; 248 } 249 250 #[inline(always)] 251 pub fn is_null(&self) -> bool { 252 return self.0 == 0; 253 } 254 } 255 256 impl Add<VirtAddr> for VirtAddr { 257 type Output = Self; 258 259 #[inline(always)] 260 fn add(self, rhs: VirtAddr) -> Self::Output { 261 return Self(self.0 + rhs.0); 262 } 263 } 264 265 impl Add<usize> for VirtAddr { 266 type Output = Self; 267 268 #[inline(always)] 269 fn add(self, rhs: usize) -> Self::Output { 270 return Self(self.0 + rhs); 271 } 272 } 273 274 impl Sub<VirtAddr> for VirtAddr { 275 type Output = usize; 276 277 #[inline(always)] 278 fn sub(self, rhs: VirtAddr) -> Self::Output { 279 return self.0 - rhs.0; 280 } 281 } 282 283 impl Sub<usize> for VirtAddr { 284 type Output = Self; 285 286 #[inline(always)] 287 fn sub(self, rhs: usize) -> Self::Output { 288 return Self(self.0 - rhs); 289 } 290 } 291 292 impl AddAssign<usize> for VirtAddr { 293 #[inline(always)] 294 fn add_assign(&mut self, rhs: usize) { 295 self.0 += rhs; 296 } 297 } 298 299 impl AddAssign<VirtAddr> for VirtAddr { 300 #[inline(always)] 301 fn add_assign(&mut self, rhs: VirtAddr) { 302 self.0 += rhs.0; 303 } 304 } 305 306 impl SubAssign<usize> for VirtAddr { 307 #[inline(always)] 308 fn sub_assign(&mut self, rhs: usize) { 309 self.0 -= rhs; 310 } 311 } 312 313 impl SubAssign<VirtAddr> for VirtAddr { 314 #[inline(always)] 315 fn sub_assign(&mut self, rhs: VirtAddr) { 316 self.0 -= rhs.0; 317 } 318 } 319 320 impl Debug for VirtAddr { 321 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 322 write!(f, "VirtAddr({:#x})", self.0) 323 } 324 } 325 326 /// @brief 物理内存区域 327 #[derive(Clone, Copy, Debug)] 328 pub struct PhysMemoryArea { 329 /// 物理基地址 330 pub base: PhysAddr, 331 /// 该区域的物理内存大小 332 pub size: usize, 333 } 334 335 impl PhysMemoryArea { 336 pub const DEFAULT: Self = Self { 337 base: PhysAddr::new(0), 338 size: 0, 339 }; 340 341 pub fn new(base: PhysAddr, size: usize) -> Self { 342 Self { base, size } 343 } 344 345 /// 返回向上页面对齐的区域起始物理地址 346 pub fn area_base_aligned(&self) -> PhysAddr { 347 return PhysAddr::new( 348 (self.base.data() + (MMArch::PAGE_SIZE - 1)) & !(MMArch::PAGE_SIZE - 1), 349 ); 350 } 351 352 /// 返回向下页面对齐的区域截止物理地址 353 pub fn area_end_aligned(&self) -> PhysAddr { 354 return PhysAddr::new((self.base.data() + self.size) & !(MMArch::PAGE_SIZE - 1)); 355 } 356 } 357 358 impl Default for PhysMemoryArea { 359 fn default() -> Self { 360 return Self::DEFAULT; 361 } 362 } 363 364 pub trait MemoryManagementArch: Clone + Copy + Debug { 365 /// 页面大小的shift(假如页面4K,那么这个值就是12,因为2^12=4096) 366 const PAGE_SHIFT: usize; 367 /// 每个页表的页表项数目。(以2^n次幂来表示)假如有512个页表项,那么这个值就是9 368 const PAGE_ENTRY_SHIFT: usize; 369 /// 页表层级数量 370 const PAGE_LEVELS: usize; 371 372 /// 页表项的有效位的index(假如页表项的第0-51位有效,那么这个值就是52) 373 const ENTRY_ADDRESS_SHIFT: usize; 374 /// 页面的页表项的默认值 375 const ENTRY_FLAG_DEFAULT_PAGE: usize; 376 /// 页表的页表项的默认值 377 const ENTRY_FLAG_DEFAULT_TABLE: usize; 378 /// 页表项的present位被置位之后的值 379 const ENTRY_FLAG_PRESENT: usize; 380 /// 页表项为read only时的值 381 const ENTRY_FLAG_READONLY: usize; 382 /// 页表项为可读写状态的值 383 const ENTRY_FLAG_READWRITE: usize; 384 /// 页面项标记页面为user page的值 385 const ENTRY_FLAG_USER: usize; 386 /// 页面项标记页面为write through的值 387 const ENTRY_FLAG_WRITE_THROUGH: usize; 388 /// 页面项标记页面为cache disable的值 389 const ENTRY_FLAG_CACHE_DISABLE: usize; 390 /// 标记当前页面不可执行的标志位(Execute disable)(也就是说,不能从这段内存里面获取处理器指令) 391 const ENTRY_FLAG_NO_EXEC: usize; 392 /// 标记当前页面可执行的标志位(Execute enable) 393 const ENTRY_FLAG_EXEC: usize; 394 395 /// 虚拟地址与物理地址的偏移量 396 const PHYS_OFFSET: usize; 397 398 /// 每个页面的大小 399 const PAGE_SIZE: usize = 1 << Self::PAGE_SHIFT; 400 /// 通过这个mask,获取地址的页内偏移量 401 const PAGE_OFFSET_MASK: usize = Self::PAGE_SIZE - 1; 402 /// 通过这个mask,获取页的首地址 403 const PAGE_MASK: usize = !(Self::PAGE_OFFSET_MASK); 404 /// 页表项的地址、数据部分的shift。 405 /// 打个比方,如果这个值为52,那么意味着页表项的[0, 52)位,用于表示地址以及其他的标志位 406 const PAGE_ADDRESS_SHIFT: usize = Self::PAGE_LEVELS * Self::PAGE_ENTRY_SHIFT + Self::PAGE_SHIFT; 407 /// 最大的虚拟地址(对于不同的架构,由于上述PAGE_ADDRESS_SHIFT可能包括了reserved bits, 事实上能表示的虚拟地址应该比这个值要小) 408 const PAGE_ADDRESS_SIZE: usize = 1 << Self::PAGE_ADDRESS_SHIFT; 409 /// 页表项的值与这个常量进行与运算,得到的结果是所填写的物理地址 410 const PAGE_ADDRESS_MASK: usize = Self::PAGE_ADDRESS_SIZE - Self::PAGE_SIZE; 411 /// 每个页表项的大小 412 const PAGE_ENTRY_SIZE: usize = 1 << (Self::PAGE_SHIFT - Self::PAGE_ENTRY_SHIFT); 413 /// 每个页表的页表项数目 414 const PAGE_ENTRY_NUM: usize = 1 << Self::PAGE_ENTRY_SHIFT; 415 /// 该字段用于根据虚拟地址,获取该虚拟地址在对应的页表中是第几个页表项 416 const PAGE_ENTRY_MASK: usize = Self::PAGE_ENTRY_NUM - 1; 417 418 const PAGE_NEGATIVE_MASK: usize = !((Self::PAGE_ADDRESS_SIZE) - 1); 419 420 const ENTRY_ADDRESS_SIZE: usize = 1 << Self::ENTRY_ADDRESS_SHIFT; 421 /// 该mask用于获取页表项中地址字段 422 const ENTRY_ADDRESS_MASK: usize = Self::ENTRY_ADDRESS_SIZE - Self::PAGE_SIZE; 423 /// 这个mask用于获取页表项中的flags 424 const ENTRY_FLAGS_MASK: usize = !Self::ENTRY_ADDRESS_MASK; 425 426 /// 用户空间的最高地址 427 const USER_END_VADDR: VirtAddr; 428 /// 用户堆的起始地址 429 const USER_BRK_START: VirtAddr; 430 /// 用户栈起始地址(向下生长,不包含该值) 431 const USER_STACK_START: VirtAddr; 432 433 /// 内核的固定映射区的起始地址 434 const FIXMAP_START_VADDR: VirtAddr; 435 /// 内核的固定映射区的大小 436 const FIXMAP_SIZE: usize; 437 /// 内核的固定映射区的结束地址 438 const FIXMAP_END_VADDR: VirtAddr = 439 VirtAddr::new(Self::FIXMAP_START_VADDR.data() + Self::FIXMAP_SIZE); 440 441 /// @brief 用于初始化内存管理模块与架构相关的信息。 442 /// 该函数应调用其他模块的接口,把可用内存区域添加到memblock,提供给BumpAllocator使用 443 unsafe fn init(); 444 445 /// @brief 读取指定虚拟地址的值,并假设它是类型T的指针 446 #[inline(always)] 447 unsafe fn read<T>(address: VirtAddr) -> T { 448 return ptr::read(address.data() as *const T); 449 } 450 451 /// @brief 将value写入到指定的虚拟地址 452 #[inline(always)] 453 unsafe fn write<T>(address: VirtAddr, value: T) { 454 ptr::write(address.data() as *mut T, value); 455 } 456 457 #[inline(always)] 458 unsafe fn write_bytes(address: VirtAddr, value: u8, count: usize) { 459 ptr::write_bytes(address.data() as *mut u8, value, count); 460 } 461 462 /// @brief 刷新TLB中,关于指定虚拟地址的条目 463 unsafe fn invalidate_page(address: VirtAddr); 464 465 /// @brief 刷新TLB中,所有的条目 466 unsafe fn invalidate_all(); 467 468 /// @brief 获取顶级页表的物理地址 469 unsafe fn table(table_kind: PageTableKind) -> PhysAddr; 470 471 /// @brief 设置顶级页表的物理地址到处理器中 472 unsafe fn set_table(table_kind: PageTableKind, table: PhysAddr); 473 474 /// @brief 将物理地址转换为虚拟地址. 475 /// 476 /// @param phys 物理地址 477 /// 478 /// @return 转换后的虚拟地址。如果转换失败,返回None 479 #[inline(always)] 480 unsafe fn phys_2_virt(phys: PhysAddr) -> Option<VirtAddr> { 481 if let Some(vaddr) = phys.data().checked_add(Self::PHYS_OFFSET) { 482 return Some(VirtAddr::new(vaddr)); 483 } else { 484 return None; 485 } 486 } 487 488 /// 将虚拟地址转换为物理地址 489 /// 490 /// ## 参数 491 /// 492 /// - `virt` 虚拟地址 493 /// 494 /// ## 返回值 495 /// 496 /// 转换后的物理地址。如果转换失败,返回None 497 #[inline(always)] 498 unsafe fn virt_2_phys(virt: VirtAddr) -> Option<PhysAddr> { 499 if let Some(paddr) = virt.data().checked_sub(Self::PHYS_OFFSET) { 500 return Some(PhysAddr::new(paddr)); 501 } else { 502 return None; 503 } 504 } 505 506 /// @brief 判断指定的虚拟地址是否正确(符合规范) 507 fn virt_is_valid(virt: VirtAddr) -> bool; 508 509 /// 获取内存管理初始化时,创建的第一个内核页表的地址 510 fn initial_page_table() -> PhysAddr; 511 512 /// 初始化新的usermapper,为用户进程创建页表 513 fn setup_new_usermapper() -> Result<UserMapper, SystemError>; 514 } 515 516 /// @brief 虚拟地址范围 517 /// 该结构体用于表示一个虚拟地址范围,包括起始地址与大小 518 /// 519 /// 请注意与VMA进行区分,该结构体被VMA所包含 520 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 521 pub struct VirtRegion { 522 start: VirtAddr, 523 size: usize, 524 } 525 526 #[allow(dead_code)] 527 impl VirtRegion { 528 /// # 创建一个新的虚拟地址范围 529 pub fn new(start: VirtAddr, size: usize) -> Self { 530 VirtRegion { start, size } 531 } 532 533 /// 获取虚拟地址范围的起始地址 534 #[inline(always)] 535 pub fn start(&self) -> VirtAddr { 536 self.start 537 } 538 539 /// 获取虚拟地址范围的截止地址(不包括返回的地址) 540 #[inline(always)] 541 pub fn end(&self) -> VirtAddr { 542 return self.start().add(self.size); 543 } 544 545 /// # Create a new VirtRegion from a range [start, end) 546 /// 547 /// If end <= start, return None 548 pub fn between(start: VirtAddr, end: VirtAddr) -> Option<Self> { 549 if unlikely(end.data() <= start.data()) { 550 return None; 551 } 552 let size = end.data() - start.data(); 553 return Some(VirtRegion::new(start, size)); 554 } 555 556 /// # 取两个虚拟地址范围的交集 557 /// 558 /// 如果两个虚拟地址范围没有交集,返回None 559 pub fn intersect(&self, other: &VirtRegion) -> Option<VirtRegion> { 560 let start = self.start.max(other.start); 561 let end = self.end().min(other.end()); 562 return VirtRegion::between(start, end); 563 } 564 565 /// 设置虚拟地址范围的起始地址 566 #[inline(always)] 567 pub fn set_start(&mut self, start: VirtAddr) { 568 self.start = start; 569 } 570 571 #[inline(always)] 572 pub fn size(&self) -> usize { 573 self.size 574 } 575 576 /// 设置虚拟地址范围的大小 577 #[inline(always)] 578 pub fn set_size(&mut self, size: usize) { 579 self.size = size; 580 } 581 582 /// 判断虚拟地址范围是否为空 583 #[inline(always)] 584 pub fn is_empty(&self) -> bool { 585 self.size == 0 586 } 587 588 /// 将虚拟地址区域的大小向上对齐到页大小 589 #[inline(always)] 590 pub fn round_up_size_to_page(self) -> Self { 591 return VirtRegion::new(self.start, round_up_to_page_size(self.size)); 592 } 593 594 /// 判断两个虚拟地址范围是否由于具有交集而导致冲突 595 #[inline(always)] 596 pub fn collide(&self, other: &VirtRegion) -> bool { 597 return self.intersect(other).is_some(); 598 } 599 600 pub fn iter_pages(&self) -> VirtPageFrameIter { 601 return VirtPageFrame::iter_range( 602 VirtPageFrame::new(self.start), 603 VirtPageFrame::new(self.end()), 604 ); 605 } 606 607 /// 获取[self.start(), region.start())的虚拟地址范围 608 /// 609 /// 如果self.start() >= region.start(),返回None 610 pub fn before(self, region: &VirtRegion) -> Option<Self> { 611 return Self::between(self.start(), region.start()); 612 } 613 614 /// 获取[region.end(),self.end())的虚拟地址范围 615 /// 616 /// 如果 self.end() >= region.end() ,返回None 617 pub fn after(self, region: &VirtRegion) -> Option<Self> { 618 // if self.end() > region.end() none 619 return Self::between(region.end(), self.end()); 620 } 621 622 /// 把当前虚拟地址范围内的某个虚拟地址,转换为另一个虚拟地址范围内的虚拟地址 623 /// 624 /// 如果vaddr不在当前虚拟地址范围内,返回None 625 /// 626 /// 如果vaddr在当前虚拟地址范围内,返回vaddr在new_base中的虚拟地址 627 pub fn rebase(self, vaddr: VirtAddr, new_base: &VirtRegion) -> Option<VirtAddr> { 628 if !self.contains(vaddr) { 629 return None; 630 } 631 let offset = vaddr.data() - self.start().data(); 632 let new_start = new_base.start().data() + offset; 633 return Some(VirtAddr::new(new_start)); 634 } 635 636 /// 判断虚拟地址范围是否包含指定的虚拟地址 637 pub fn contains(&self, addr: VirtAddr) -> bool { 638 return self.start() <= addr && addr < self.end(); 639 } 640 641 /// 创建当前虚拟地址范围的页面迭代器 642 pub fn pages(&self) -> VirtPageFrameIter { 643 return VirtPageFrame::iter_range( 644 VirtPageFrame::new(self.start()), 645 VirtPageFrame::new(self.end()), 646 ); 647 } 648 } 649 650 impl PartialOrd for VirtRegion { 651 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { 652 return self.start.partial_cmp(&other.start); 653 } 654 } 655 656 impl Ord for VirtRegion { 657 fn cmp(&self, other: &Self) -> cmp::Ordering { 658 return self.start.cmp(&other.start); 659 } 660 } 661 662 /// ## 判断虚拟地址是否超出了用户空间 663 /// 664 /// 如果虚拟地址超出了用户空间,返回Err(SystemError::EFAULT). 665 /// 如果end < start,返回Err(SystemError::EOVERFLOW) 666 /// 667 /// 否则返回Ok(()) 668 pub fn verify_area(addr: VirtAddr, size: usize) -> Result<(), SystemError> { 669 let end = addr.add(size); 670 if unlikely(end.data() < addr.data()) { 671 return Err(SystemError::EOVERFLOW); 672 } 673 674 if !addr.check_user() || !end.check_user() { 675 return Err(SystemError::EFAULT); 676 } 677 678 return Ok(()); 679 } 680