Changeset 21314 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jul 7, 2009 11:31:52 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 49659
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c
r20525 r21314 421 421 if (pMemLnx->Core.u.Lock.R0Process != NIL_RTR0PROCESS) 422 422 { 423 size_t iPage;424 423 struct task_struct *pTask = rtR0ProcessToLinuxTask(pMemLnx->Core.u.Lock.R0Process); 424 size_t iPage; 425 425 Assert(pTask); 426 426 if (pTask && pTask->mm) … … 438 438 up_read(&pTask->mm->mmap_sem); 439 439 } 440 else 441 AssertFailed(); /* not implemented for R0 */ 440 /* else: kernel memory - nothing to do here. */ 442 441 break; 443 442 … … 813 812 int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb) 814 813 { 815 /* What is there to lock? Should/Can we fake this? */ 816 return VERR_NOT_SUPPORTED; 814 void *pvLast = (uint8_t *)pv + cb - 1; 815 size_t const cPages = cb >> PAGE_SHIFT; 816 PRTR0MEMOBJLNX pMemLnx; 817 bool fLinearMapping; 818 int rc; 819 uint8_t *pbPage; 820 size_t iPage; 821 822 /* 823 * Classify the memory and check that we can deal with it. 824 */ 825 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) 826 fLinearMapping = virt_addr_valid(pvLast) && virt_addr_valid(pv); 827 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) 828 fLinearMapping = VALID_PAGE(virt_to_page(pvLast)) && VALID_PAGE(virt_to_page(pv)); 829 #else 830 # error "not supported" 831 #endif 832 if (!fLinearMapping) 833 { 834 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 19) 835 if ( !RTR0MemKernelIsValidAddr(pv) 836 || !RTR0MemKernelIsValidAddr(pv + cb)) 837 #endif 838 return VERR_INVALID_PARAMETER; 839 } 840 841 /* 842 * Allocate the memory object. 843 */ 844 pMemLnx = (PRTR0MEMOBJLNX)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJLNX, apPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb); 845 if (!pMemLnx) 846 return VERR_NO_MEMORY; 847 848 /* 849 * Gather the pages. 850 * We ASSUME all kernel pages are non-swappable. 851 */ 852 rc = VINF_SUCCESS; 853 pbPage = (uint8_t *)pvLast; 854 iPage = cPages; 855 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 19) 856 if (!fLinearMapping) 857 { 858 while (iPage-- > 0) 859 { 860 struct page *pPage = vmalloc_to_page(pbPage); 861 if (RT_UNLIKELY(!pPage)) 862 { 863 rc = VERR_LOCK_FAILED; 864 break; 865 } 866 pMemLnx->apPages[iPage] = pPage; 867 pbPage -= PAGE_SIZE; 868 } 869 } 870 else 871 #endif 872 { 873 while (iPage-- > 0) 874 { 875 pMemLnx->apPages[iPage] = virt_to_page(pbPage); 876 pbPage -= PAGE_SIZE; 877 } 878 } 879 if (RT_SUCCESS(rc)) 880 { 881 /* 882 * Complete the memory object and return. 883 */ 884 pMemLnx->Core.u.Lock.R0Process = NIL_RTR0PROCESS; 885 pMemLnx->cPages = cPages; 886 Assert(!pMemLnx->fMappedToRing0); 887 *ppMem = &pMemLnx->Core; 888 889 return VINF_SUCCESS; 890 } 891 892 rtR0MemObjDelete(&pMemLnx->Core); 893 return rc; 817 894 } 818 895
Note:
See TracChangeset
for help on using the changeset viewer.