/** * Worker locking the memory in either kernel or user maps. * * @returns IPRT status code. * @param ppMem Where to store the allocated memory object. * @param pvStart The starting address. * @param cb The size of the block. * @param fAccess The mapping protection to apply. * @param R0Process The process to map the memory to (use NIL_RTR0PROCESS * for the kernel) * @param fFlags Memory flags (B_READ_DEVICE indicates the memory is * intended to be written from a "device"). */ static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTERNAL ppMem, void *pvStart, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process, int fFlags) { NOREF(fAccess); int rc; team_id TeamId = B_SYSTEM_TEAM; LogFlowFunc(("ppMem=%p pvStart=%p cb=%u fAccess=%x R0Process=%d fFlags=%x\n", ppMem, pvStart, cb, fAccess, R0Process, fFlags)); /* Create the object. */ PRTR0MEMOBJHAIKU pMemHaiku = (PRTR0MEMOBJHAIKU)rtR0MemObjNew(sizeof(*pMemHaiku), RTR0MEMOBJTYPE_LOCK, pvStart, cb); if (RT_UNLIKELY(!pMemHaiku)) return VERR_NO_MEMORY; if (R0Process != NIL_RTR0PROCESS) TeamId = (team_id)R0Process; rc = lock_memory_etc(TeamId, pvStart, cb, fFlags); if (rc == B_OK) { pMemHaiku->AreaId = -1; pMemHaiku->Core.u.Lock.R0Process = R0Process; *ppMem = &pMemHaiku->Core; return VINF_SUCCESS; } rtR0MemObjDelete(&pMemHaiku->Core); return RTErrConvertFromHaikuKernReturn(rc); }
status_t IOBuffer::LockMemory(team_id team, bool isWrite) { if (fMemoryLocked) { panic("memory already locked!"); return B_BAD_VALUE; } for (uint32 i = 0; i < fVecCount; i++) { status_t status = lock_memory_etc(team, fVecs[i].iov_base, fVecs[i].iov_len, isWrite ? 0 : B_READ_DEVICE); if (status != B_OK) { _UnlockMemory(team, i, isWrite); return status; } } fMemoryLocked = true; return B_OK; }