Beispiel #1
0
static tEplKernel EplApiProcessImageDeleteCompletion(
    tEplApiProcessImageCopyJobInt* pCopyJob_p)
{
tEplKernel      Ret = kEplSuccessful;

#if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
    if (pCopyJob_p->m_Event.m_pCompletion != NULL)
    {
        EplApiProcessImagePutUserPages(
                pCopyJob_p->m_Event.m_pCompletion->m_apPageIn, FALSE);
        EplApiProcessImagePutUserPages(
                pCopyJob_p->m_Event.m_pCompletion->m_apPageOut, TRUE);
        EPL_FREE(pCopyJob_p->m_Event.m_pCompletion);
        pCopyJob_p->m_Event.m_pCompletion = NULL;
    }

#elif (TARGET_SYSTEM == _LINUX_) && !defined(__KERNEL__)
    sem_destroy(&pCopyJob_p->m_Event.m_semCompletion);

#elif (TARGET_SYSTEM == _WIN32_)
    if ((pCopyJob_p->m_Event.m_hEvent != NULL)
        && (pCopyJob_p->m_Event.m_hEvent != INVALID_HANDLE_VALUE))
    {
        CloseHandle(pCopyJob_p->m_Event.m_hEvent);
        pCopyJob_p->m_Event.m_hEvent = INVALID_HANDLE_VALUE;
    }

#else
#error "OS currently not supported by EplApiProcessImage!"
#endif

//Exit:
    return Ret;
}
static void EplApiProcessImageReleaseCompletion(struct kref* pKref_p)
{
    tEplApiProcessImageCompletion* pCompletion = container_of(pKref_p, tEplApiProcessImageCompletion, m_Kref);

    EplApiProcessImagePutUserPages(
        pCompletion->m_apPageIn, FALSE);
    EplApiProcessImagePutUserPages(
        pCompletion->m_apPageOut, TRUE);
    EPL_FREE(pCompletion);
}
static tEplKernel EplApiProcessImageGetUserPages(
    tEplApiProcessImage* pImage_p,
    tEplApiProcessImagePart* pPart_p, BOOL fOut_p,
    struct page** ppPage_p)
{
    tEplKernel      Ret = kEplSuccessful;
    int             iRet;
    unsigned int    uiNrOfPages;

    if (pPart_p->m_uiSize > EPL_API_PI_MAX_SIZE)
    {
        Ret = kEplApiPISizeExceeded;
        goto Exit;
    }

    if ((pPart_p->m_uiSize > 0)
            && (pPart_p->m_pPart != NULL)
            && (pImage_p->m_pImage != NULL)
            && ((pPart_p->m_uiOffset + pPart_p->m_uiSize)
                <= pImage_p->m_uiSize))
    {
        uiNrOfPages = (((unsigned long)pPart_p->m_pPart & ~PAGE_MASK)
                       + pPart_p->m_uiSize + PAGE_SIZE - 1) >> PAGE_SHIFT;
        down_read(&current->mm->mmap_sem);
        iRet = get_user_pages(current, current->mm,
                              (unsigned long)pPart_p->m_pPart,
                              uiNrOfPages, fOut_p, 0, ppPage_p,
                              NULL);
        up_read(&current->mm->mmap_sem);
        if (iRet != uiNrOfPages)
        {
            PRINTF("%s: get_user_pages(%p, %u, %d, %p) returned %d\n",
                   __func__,
                   pPart_p->m_pPart,
                   uiNrOfPages, fOut_p,
                   ppPage_p, iRet);
            EplApiProcessImagePutUserPages(ppPage_p, FALSE);
            Ret = kEplApiPIOutOfMemory;
            goto Exit;
        }
    }