CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(nullptr), m_bBlocking(FALSE), m_isolate(nullptr), m_isolateManaged(false) { #ifndef PDF_ENABLE_XFA IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); #else if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); } else { IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); } v8::Isolate* isolate = m_isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); return; } #endif if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); #ifdef PDF_ENABLE_XFA CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); #endif CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); }
AvFormatDecoderDVD::~AvFormatDecoderDVD() { ReleaseContext(m_curContext); ReleaseContext(m_returnContext); while (m_contextList.size() > 0) m_contextList.takeFirst()->DecrRef(); ReleaseLastVideoPkt(); }
bool ClientSession::PostSend() { if (!IsConnected()) return false; if ( 0 == mCircularBuffer->GetContiguiousBytes() ) return true; RioIoContext* sendContext = new RioIoContext(this, IO_SEND); sendContext->BufferId = mRioBufferId; sendContext->Length = static_cast<ULONG>(mCircularBuffer->GetContiguiousBytes()); sendContext->Offset = mCircularBuffer->GetReadableOffset(); DWORD sendbytes = 0; DWORD flags = 0; /// start async send if (!RIO.RIOSend(mRequestQueue, (PRIO_BUF)sendContext, 1, flags, sendContext)) { printf_s("[DEBUG] RIOSend error: %d\n", GetLastError()); ReleaseContext(sendContext); return false; } return true; }
CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), m_bBlocking(false), m_isolateManaged(false) { v8::Isolate* pIsolate = nullptr; IPDF_JSPLATFORM* pPlatform = m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&pIsolate); SetIsolate(pIsolate); #ifdef PDF_ENABLE_XFA v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); #endif if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); InitializeEngine(); ReleaseContext(pContext); SetFormFillEnvToDocument(); }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), m_isolate(NULL), m_isolateManaged(false) { unsigned int embedderDataSlot = 0; if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { m_isolate = reinterpret_cast<v8::Isolate*>( m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; } if (!m_isolate) { m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator()); v8::Isolate::CreateParams params; params.array_buffer_allocator = m_pArrayBufferAllocator.get(); m_isolate = v8::Isolate::New(params); m_isolateManaged = true; } FXJS_Initialize(embedderDataSlot); DefineJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); ReleaseContext(pContext); }
bool ClientSession::PostRecv() { if (!IsConnected()) return false; if (0 == mCircularBuffer->GetFreeSpaceSize()) return false; RioIoContext* recvContext = new RioIoContext(this, IO_RECV); recvContext->BufferId = mRioBufferId; recvContext->Length = static_cast<ULONG>(mCircularBuffer->GetFreeSpaceSize()); recvContext->Offset = mCircularBuffer->GetWritableOffset(); DWORD recvbytes = 0; DWORD flags = 0; /// start async recv if (!RIO.RIOReceive(mRequestQueue, (PRIO_BUF)recvContext, 1, flags, recvContext)) { printf_s("[DEBUG] RIOReceive error: %d\n", GetLastError()); ReleaseContext(recvContext); return false; } return true; }
void FLTAPI ContextCleanup ( __in PVOID Pool, __in FLT_CONTEXT_TYPE ContextType ) { switch ( ContextType ) { case FLT_INSTANCE_CONTEXT: { } break; case FLT_STREAM_CONTEXT: { PStreamContext pStreamContext = (PStreamContext) Pool; ReleaseContext( (PFLT_CONTEXT*) &pStreamContext->m_InstanceCtx ); ASSERT( pStreamContext ); } break; case FLT_STREAMHANDLE_CONTEXT: { PStreamHandleContext pStreamHandleContext = (PStreamHandleContext) Pool; ReleaseContext( (PFLT_CONTEXT*) &pStreamHandleContext->m_StreamCtx ); } break; case FLT_VOLUME_CONTEXT: { PVolumeContext pVolumeContext = (PVolumeContext) Pool; FREE_POOL( pVolumeContext->m_DeviceId.Buffer ); } break; default: { ASSERT( "cleanup for unknown context!" ); } break; } }
void OpenAL::ReleaseDevice() { ReleaseContext(); if(m_Device) { LogInfo("Releasing OAL device"); alcCloseDevice(m_Device); m_Device = NULL; } }
EndPoint::~EndPoint() { // No network thread if networking isn't enabled. if (mContext->Enabled()) { // Kill the network thread and wait for it to terminate. mRunning = false; mNetworkThread.Join(); } // Release the per-process context. ReleaseContext(); }
__checkReturn FLT_POSTOP_CALLBACK_STATUS FLTAPI PostWrite ( __inout PFLT_CALLBACK_DATA Data, __in PCFLT_RELATED_OBJECTS FltObjects, __in PVOID CompletionContext, __in FLT_POST_OPERATION_FLAGS Flags ) { FLT_POSTOP_CALLBACK_STATUS fltStatus = FLT_POSTOP_FINISHED_PROCESSING; PStreamContext pStreamContext = (PStreamContext) CompletionContext; ASSERT( pStreamContext ); __try { if ( FlagOn( Flags, FLTFL_POST_OPERATION_DRAINING ) ) { __leave; } if ( !NT_SUCCESS( Data->IoStatus.Status ) ) { __leave; } if ( !Data->IoStatus.Information ) { __leave; } if ( FlagOn( Data->Iopb->IrpFlags, IRP_PAGING_IO ) ) { //! \todo обработка MM файлов __leave; } InterlockedIncrement( &pStreamContext->m_WriteCount ); InterlockedAnd( &pStreamContext->m_Flags, ~_STREAM_FLAGS_CASHE1 ); InterlockedOr( &pStreamContext->m_Flags, _STREAM_FLAGS_MODIFIED ); } __finally { ReleaseContext( (PFLT_CONTEXT*) &pStreamContext ); } return fltStatus; }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : m_pApp(pApp), m_pDocument(NULL), m_pFieldEventPath(NULL), m_bBlocking(FALSE), m_bRegistered(FALSE) { m_isolate = v8::Isolate::New(); //m_isolate->Enter(); InitJSObjects(); CJS_Context * pContext = (CJS_Context*)NewContext(); JS_InitialRuntime(*this, this, pContext, m_context); ReleaseContext(pContext); }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), m_bRegistered(FALSE), m_pFieldEventPath(NULL) { m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); v8::Isolate::CreateParams params; params.array_buffer_allocator = m_pArrayBufferAllocator.get(); m_isolate = v8::Isolate::New(params); InitJSObjects(); CJS_Context * pContext = (CJS_Context*)NewContext(); JS_InitialRuntime(*this, this, pContext, m_context); ReleaseContext(pContext); }
bool OpenAL::CreateContext() { ReleaseContext(); if(!m_Device) { LogError("Couldn't create OAL context, device not opened"); return false; } m_Context = alcCreateContext(m_Device, NULL); if(m_Context) { LogInfo("Created OAL context"); alcMakeContextCurrent(m_Context); } return m_Context != NULL; }
// // 更新接收消息 // void CGateServer::OnUpdateRecv(DWORD dwDeltaTime) { CIOContext *pContext = m_pActiveContext; while (pContext) { CIOContext *pNextContext = pContext->pNextActive; if (pContext->IsAlive()) { pContext->SwitchRecvBuffer(); pContext->dwHeartTime += dwDeltaTime; while (TRUE) { WORD msg; WORD fullSize; WORD bodySize; if (pContext->GetRecvBuffer().GetData((BYTE *)&fullSize, sizeof(fullSize)) != sizeof(fullSize)) break; if (pContext->GetRecvBuffer().GetActiveBufferSize() < sizeof(fullSize) + fullSize) break; if (pContext->GetRecvBuffer().PopData((BYTE *)&fullSize, sizeof(fullSize)) != sizeof(fullSize)) break; if (pContext->GetRecvBuffer().PopData((BYTE *)&msg, sizeof(msg)) != sizeof(msg)) break; bodySize = fullSize - sizeof(msg); m_dwRecvDataSize += sizeof(fullSize) + fullSize; ResponseFuncs::const_iterator itFunc = m_responses.find(msg); if (itFunc == m_responses.end()) continue; (this->*itFunc->second)(pContext, bodySize); OnHeartReset(pContext); } } if (pContext->Check((DWORD)(1000 * m_timeOut)) == FALSE) { ReleaseContext(pContext, FALSE); } pContext = pNextContext; } }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), m_isolate(NULL), m_isolateManaged(false) { IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); }
void CIOCPServer::HandleIO(DWORD dwKey, CIOCPBuffer *pBuffer, DWORD dwTrans, int nError) { CIOCPContext *pContext = (CIOCPContext *)dwKey; #ifdef _DEBUG // ::OutputDebugString(" HandleIO... \n"); #endif // _DEBUG // 1)首先减少套节字上的未决I/O计数 if(pContext != NULL) { ::EnterCriticalSection(&pContext->Lock); if(pBuffer->nOperation == OP_READ) pContext->nOutstandingRecv --; else if(pBuffer->nOperation == OP_WRITE) pContext->nOutstandingSend --; ::LeaveCriticalSection(&pContext->Lock); // 2)检查套节字是否已经被我们关闭 if(pContext->bClosing) { #ifdef _DEBUG ::OutputDebugString(" pContext->bClosing 检查到套节字已经被我们关闭 \n"); #endif // _DEBUG if(pContext->nOutstandingRecv == 0 && pContext->nOutstandingSend == 0) { ReleaseContext(pContext); } // 释放已关闭套节字的未决I/O ReleaseBuffer(pBuffer); return; } } else { RemovePendingAccept(pBuffer); #ifdef _DEBUG ::OutputDebugString("RemovePendingAccept 检查到套节字连接超时未完成被我们关闭 \n"); #endif // _DEBUG } // 3)检查套节字上发生的错误,如果有的话,通知用户,然后关闭套节字 if(nError != NO_ERROR) { if(pBuffer->nOperation != OP_ACCEPT) { OnConnectionError(pContext, pBuffer, nError); CloseAConnection(pContext); if(pContext->nOutstandingRecv == 0 && pContext->nOutstandingSend == 0) { ReleaseContext(pContext); } #ifdef _DEBUG ::OutputDebugString("nError 非OP_ACCEPT检查到客户套节字上发生错误 \n"); #endif // _DEBUG } else // 在监听套节字上发生错误,也就是监听套节字处理的客户出错了 { // 客户端出错,释放I/O缓冲区 if(pBuffer->sClient != INVALID_SOCKET) { ::closesocket(pBuffer->sClient); pBuffer->sClient = INVALID_SOCKET; } #ifdef _DEBUG ::OutputDebugString("nError Listen SOCKET检查到监听套节字上发生错误 \n"); #endif // _DEBUG } ReleaseBuffer(pBuffer); return; } // 开始处理 if(pBuffer->nOperation == OP_ACCEPT) { if(dwTrans == 0) { #ifdef _DEBUG ::OutputDebugString("OP_ACCEPT 监听套节字上客户端关闭 \n"); #endif // _DEBUG if(pBuffer->sClient != INVALID_SOCKET) { ::closesocket(pBuffer->sClient); pBuffer->sClient = INVALID_SOCKET; } } else { // 为新接受的连接申请客户上下文对象 CIOCPContext *pClient = AllocateContext(pBuffer->sClient); if(pClient != NULL) { if(AddAConnection(pClient)) { // 取得客户地址 int nLocalLen, nRmoteLen; LPSOCKADDR pLocalAddr, pRemoteAddr; m_lpfnGetAcceptExSockaddrs( pBuffer->buff, pBuffer->nLen - ((sizeof(sockaddr_in) + 16) * 2), sizeof(sockaddr_in) + 16, sizeof(sockaddr_in) + 16, (SOCKADDR **)&pLocalAddr, &nLocalLen, (SOCKADDR **)&pRemoteAddr, &nRmoteLen); memcpy(&pClient->addrLocal, pLocalAddr, nLocalLen); memcpy(&pClient->addrRemote, pRemoteAddr, nRmoteLen); // 关联新连接到完成端口对象 ::CreateIoCompletionPort((HANDLE)pClient->s, m_hCompletion, (DWORD)pClient, 0); // 通知用户 pBuffer->nLen = dwTrans; OnConnectionEstablished(pClient, pBuffer); // 向新连接投递几个Read请求,这些空间在套节字关闭或出错时释放 for(int i=0; i<m_nInitialReads ; i++) { CIOCPBuffer *p = AllocateBuffer(BUFFER_SIZE); if(p != NULL) { if(!PostRecv(pClient, p)) { CloseAConnection(pClient); break; } } } } else // 连接数量已满,关闭连接 { CloseAConnection(pClient); ReleaseContext(pClient); } } else { // 资源不足,关闭与客户的连接即可 ::closesocket(pBuffer->sClient); pBuffer->sClient = INVALID_SOCKET; } } // Accept请求完成,释放I/O缓冲区 ReleaseBuffer(pBuffer); // 通知监听线程继续再投递一个Accept请求 ::InterlockedIncrement(&m_nRepostCount); ::SetEvent(m_hRepostEvent); } else if(pBuffer->nOperation == OP_READ) { if(dwTrans == 0) // 对方关闭套节字 { // 先通知用户 pBuffer->nLen = 0; OnConnectionClosing(pContext, pBuffer); // 再关闭连接 CloseAConnection(pContext); // 释放客户上下文和缓冲区对象 if(pContext->nOutstandingRecv == 0 && pContext->nOutstandingSend == 0) { ReleaseContext(pContext); } ReleaseBuffer(pBuffer); } else { pBuffer->nLen = dwTrans; // 按照I/O投递的顺序读取接收到的数据 CIOCPBuffer *p = GetNextReadBuffer(pContext, pBuffer); while(p != NULL) { // 通知用户 OnReadCompleted(pContext, p); // 增加要读的序列号的值 ::InterlockedIncrement((LONG*)&pContext->nCurrentReadSequence); // 释放这个已完成的I/O ReleaseBuffer(p); p = GetNextReadBuffer(pContext, NULL); } // printf("空闲buffer数:%d \n",m_nFreeBufferCount); if (pContext->nOutstandingRecv <= 0) { for(int i=0; i<m_nInitialReads ; i++) { // 继续投递几个新的重叠接收请求,这样能达到最快速度 // 因为此时pBuffer已经释放或被保存到缓冲区,所以分配一个新的 pBuffer = AllocateBuffer(BUFFER_SIZE); if(pBuffer != NULL) { if(!PostRecv(pContext, pBuffer)) { CloseAConnection(pContext); break; } } } } } } else if(pBuffer->nOperation == OP_WRITE) { if(dwTrans == 0) // 对方关闭套节字 { // 先通知用户 pBuffer->nLen = 0; OnConnectionClosing(pContext, pBuffer); // 再关闭连接 CloseAConnection(pContext); // 释放客户上下文和缓冲区对象 if(pContext->nOutstandingRecv == 0 && pContext->nOutstandingSend == 0) { ReleaseContext(pContext); } ReleaseBuffer(pBuffer); } else { // 写操作完成,通知用户 pBuffer->nLen = dwTrans; OnWriteCompleted(pContext, pBuffer); // 释放SendText函数申请的缓冲区 ReleaseBuffer(pBuffer); } } }
void AvFormatDecoderDVD::CheckContext(int64_t pts) { if (pts != AV_NOPTS_VALUE) { // Remove any contexts we should have // already processed.(but have somehow jumped past) while (m_contextList.size() > 0 && pts >= m_contextList.first()->GetEndPTS()) { ReleaseContext(m_curContext); m_curContext = m_contextList.takeFirst(); LOG(VB_GENERAL, LOG_ERR, LOC + QString("DVD context missed! lba: %1, curpts: %2, nav end pts: %3") .arg(m_curContext->GetLBA()) .arg(pts) .arg(m_curContext->GetEndPTS())); } // See whether we can take the next context from the list if (m_contextList.size() > 0 && pts >= m_contextList.first()->GetStartPTS()) { ReleaseContext(m_curContext); m_curContext = m_contextList.takeFirst(); if (m_curContext->GetLBAPrevVideoFrame() != m_lbaLastVideoPkt) ReleaseLastVideoPkt(); if (m_curContext->GetNumFramesPresent() == 0) { if (m_lastVideoPkt) { // No video frames present, so we need to generate // them based on the last 'sequence end' video packet. m_framesReq = m_curContext->GetNumFrames(); } else { // There are no video frames in this VOBU and // we don't have one stored. We've probably // jumped into the middle of a cell. // Jump back to the first VOBU that contains // video so we can get the video frame we need // before jumping back again. m_framesReq = 0; uint32_t lastVideoSector = m_curContext->GetLBAPrevVideoFrame(); if (lastVideoSector != INVALID_LBA) { LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString( "Missing video. Jumping to sector %1") .arg(lastVideoSector)); ringBuffer->DVD()->SectorSeek(lastVideoSector); m_returnContext = m_curContext; m_curContext = NULL; } else { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Missing video frame and no previous frame available! lba: %1") .arg(m_curContext->GetLBA())); } } } else { // Normal VOBU with at least one video frame so we don't need to generate frames. m_framesReq = 0; ReleaseLastVideoPkt(); } } } }
__checkReturn NTSTATUS FLTAPI InstanceSetup ( __in PCFLT_RELATED_OBJECTS FltObjects, __in FLT_INSTANCE_SETUP_FLAGS Flags, __in DEVICE_TYPE VolumeDeviceType, __in FLT_FILESYSTEM_TYPE VolumeFilesystemType ) { NTSTATUS status = STATUS_UNSUCCESSFUL; PInstanceContext pInstanceCtx = NULL; PVolumeContext pVolumeContext = NULL; UNREFERENCED_PARAMETER( Flags ); ASSERT( FltObjects->Filter == gFileMgr.m_FileFilter ); if ( FLT_FSTYPE_RAW == VolumeFilesystemType) { return STATUS_FLT_DO_NOT_ATTACH; } if ( FILE_DEVICE_NETWORK_FILE_SYSTEM == VolumeDeviceType ) { return STATUS_FLT_DO_NOT_ATTACH; } __try { status = FltAllocateContext( gFileMgr.m_FileFilter, FLT_INSTANCE_CONTEXT, sizeof( InstanceContext ), NonPagedPool, (PFLT_CONTEXT*) &pInstanceCtx ); if ( !NT_SUCCESS( status ) ) { pInstanceCtx = NULL; __leave; } RtlZeroMemory( pInstanceCtx, sizeof( InstanceContext ) ); status = FltAllocateContext( gFileMgr.m_FileFilter, FLT_VOLUME_CONTEXT, sizeof( VolumeContext ), NonPagedPool, (PFLT_CONTEXT*) &pVolumeContext ); if ( !NT_SUCCESS( status ) ) { pVolumeContext = NULL; __leave; } RtlZeroMemory( pVolumeContext, sizeof( VolumeContext ) ); // just for fun pInstanceCtx->m_VolumeDeviceType = VolumeDeviceType; pInstanceCtx->m_VolumeFilesystemType = VolumeFilesystemType; status = FillVolumeProperties( FltObjects, pVolumeContext ); if ( !NT_SUCCESS( status ) ) { __leave; } ASSERT( VolumeDeviceType != FILE_DEVICE_NETWORK_FILE_SYSTEM ); VERDICT Verdict = VERDICT_NOT_FILTERED; if ( gFileMgr.m_FltSystem->IsFiltersExist() ) { VolumeInterceptorContext event( FltObjects, pInstanceCtx, pVolumeContext, VOLUME_MINIFILTER, OP_VOLUME_ATTACH, 0, PostProcessing ); PARAMS_MASK params2user; status = gFileMgr.m_FltSystem->FilterEvent( &event, &Verdict, ¶ms2user ); if ( NT_SUCCESS( status ) && FlagOn( Verdict, VERDICT_ASK ) ) { status = ChannelAskUser( &event, params2user, &Verdict ); if ( NT_SUCCESS( status ) ) { } } } status = FltSetInstanceContext( FltObjects->Instance, FLT_SET_CONTEXT_KEEP_IF_EXISTS, pInstanceCtx, NULL ); pVolumeContext->m_Instance = FltObjects->Instance; status = FltSetVolumeContext( FltObjects->Volume, FLT_SET_CONTEXT_KEEP_IF_EXISTS, pVolumeContext, NULL ); } __finally { ReleaseContext( (PFLT_CONTEXT*) &pInstanceCtx ); ReleaseContext( (PFLT_CONTEXT*) &pVolumeContext ); } return STATUS_SUCCESS; }
// // Creates key store report. // WINERROR KeyStoreReport( PWCHAR* ppReport, // receives key report PULONG pLength, // size of the report in chars BOOL bDelete ) { WINERROR Status = ERROR_NOT_ENOUGH_MEMORY; PKEY_CONTEXT Ctx, NextCtx; ULONG bLen, TotalLen = 1, Index = 0, Length, InitialSize; ULONG LengthClipbrd = 0; PWCHAR Buffer, NewBuffer; SYSTEMTIME DateTime; FILETIME LocalTime; PLIST_ENTRY ListEntry; #if _DEBUG HANDLE PrevKey = 0; #endif InitialSize = MAX_REPORT_BUFFER_SIZE; if (Buffer = AppAlloc(InitialSize)) { bLen = MAX_REPORT_BUFFER_SIZE / sizeof(WCHAR); Buffer[0] = 0xfeff; // Unicode file magic Buffer[1] = 0; bLen -= 1; NextCtx = EnumContext(NULL); while(Ctx = NextCtx) { #if _DEBUG PHANDLE_RECORD pHRec = CONTAINING_RECORD(Ctx, HANDLE_RECORD, Context); ASSERT(pHRec->RefCount == 2); ASSERT(PrevKey != pHRec->Key); PrevKey = pHRec->Key; #endif if (Ctx->bActive) { FileTimeToLocalFileTime(&Ctx->Time, &LocalTime); FileTimeToSystemTime(&LocalTime, &DateTime); // Calculating new message length Length = cstrlenW(wczReportFormat) + lstrlenW(Ctx->ProcessPath) + lstrlenW(Ctx->WindowText) + Ctx->Count + 1; // Checking if there's enough free space within the buffer to fit the message if ((bLen >= Length) || // Trying to reallocate the buffer ((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) && (Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen))) { Length = wnsprintfW( Buffer + TotalLen, bLen, wczReportFormat, DateTime.wDay, DateTime.wMonth, DateTime.wYear, DateTime.wHour, DateTime.wMinute, DateTime.wSecond, (LPWSTR)&Ctx->ProcessPath, (LPWSTR)&Ctx->WindowText, (LPWSTR)&Ctx->KeyBuffer ); bLen -= Length; TotalLen += Length; } } // if (Ctx->bActive) if (!IsListEmpty(&Ctx->ClipboardChain)) { for ( ListEntry = Ctx->ClipboardChain.Flink; ListEntry != &Ctx->ClipboardChain; ListEntry = ListEntry->Flink) { PCLIPBOARD_ENTRY CEntry = CONTAINING_RECORD(ListEntry,CLIPBOARD_ENTRY,qLink); Length = cstrlenW(wczFormatClipbrd) + lstrlenA(CEntry->Buffer); // Checking if there's enough free space within the buffer to fit the message if ((bLen >= Length) || // Trying to reallocate the buffer ((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) && (Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen))) { FileTimeToLocalFileTime(&CEntry->Time, &LocalTime); FileTimeToSystemTime(&LocalTime, &DateTime); Length = wnsprintfW( Buffer + TotalLen, bLen, wczFormatClipbrd, DateTime.wDay, DateTime.wMonth, DateTime.wYear, DateTime.wHour, DateTime.wMinute, DateTime.wSecond, (LPWSTR)CEntry->Buffer ); bLen -= Length; TotalLen += Length; } } } // if (!IsListEmpty(&Ctx->ClipboardChain)) NextCtx = EnumContext(Ctx); if (bDelete) ReleaseContext(Ctx); else Index += 1; ReleaseContext(Ctx); } // while(Ctx = NextCtx) if (TotalLen > 1) { *ppReport = Buffer; *pLength = TotalLen; Status = NO_ERROR; } else { AppFree(Buffer); Status = ERROR_NO_MORE_FILES; } } // if (Buffer = AppAlloc(DEFAULT_REPORT_BUFFER_SIZE)) return(Status); }
// // Adds a new pressed key information into the key store. // WINERROR KeyStoreAdd( PKEY_INFO pKeyInfo ) { WINERROR Status = ERROR_NOT_ENOUGH_MEMORY; ULONG KeyHandle; PKEY_CONTEXT Ctx; BOOL bDeref = FALSE; KeyHandle = Crc32((PCHAR)&pKeyInfo->Client, sizeof(CLIENT_INFO)); if (Ctx = GetContext(KeyHandle)) { bDeref = Ctx->bDirty; if (Ctx->bDirty == FALSE) // just created { // Context has just been created, initializing HANDLE hProcess; // Resolving process path if (hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pKeyInfo->Client.ProcessId)) { GetModuleFileNameExW(hProcess, NULL, (LPWSTR)&Ctx->ProcessPath, MAX_PATH); CloseHandle(hProcess); } Ctx->bActive = TRUE; // Saving current date and time GetSystemTimeAsFileTime(&Ctx->Time); // Resolving parent window text GetWindowTextW(pKeyInfo->Client.ParentWindow, (LPWSTR)&Ctx->WindowText, MAX_WINDOW_TEXT); } // if (Ctx->bDirty == FALSE) // just created Ctx->bDirty = TRUE; if (Ctx->bActive) { if (pKeyInfo->wChar && Ctx->Count < MAX_KEY_BUFFER_SIZE) { if (pKeyInfo->wChar == VK_BACK) { if (Ctx->Count) Ctx->Count -= 1; } else { Ctx->KeyBuffer[Ctx->Count] = pKeyInfo->wChar; Ctx->Count += 1; DbgPrint("KEYLOG: Adding key to a buffer: 0x%x, %C\n", pKeyInfo->wChar, pKeyInfo->wChar); } Status = NO_ERROR; } // if (Ctx->Count < MAX_KEY_BUFFER_SIZE) else Status = ERROR_BUFFER_OVERFLOW; if ( pKeyInfo->clipboard ) { PCLIPBOARD_ENTRY Entry = (PCLIPBOARD_ENTRY)AppAlloc( sizeof(CLIPBOARD_ENTRY) ); if ( Entry ) { // Saving current date and time GetSystemTimeAsFileTime(&Entry->Time); Entry->Buffer = pKeyInfo->clipboard; pKeyInfo->clipboard = NULL; // we'll free it later InsertTailList(&Ctx->ClipboardChain,&Entry->qLink); } } // if ( pKeyInfo->clipboard ) } // if (Ctx->bActive) if ( bDeref ) // Context has been reused, dereferencing it ReleaseContext(Ctx); } // if (Ctx = GetContext(KeyHandle)) return(Status); }
void GameContext::Release() { ReleaseContext(); m_objects.clear(); m_controllers.clear(); }
__checkReturn FLT_POSTOP_CALLBACK_STATUS FLTAPI PostCreate ( __inout PFLT_CALLBACK_DATA Data, __in PCFLT_RELATED_OBJECTS FltObjects, __in PVOID CompletionContext, __in FLT_POST_OPERATION_FLAGS Flags ) { UNREFERENCED_PARAMETER( CompletionContext ); FLT_POSTOP_CALLBACK_STATUS fltStatus = FLT_POSTOP_FINISHED_PROCESSING; /// \todo access to volume - generate access event PStreamHandleContext pStreamHandleContext = NULL; __try { NTSTATUS status; if ( IsSkipPostCreate( Data, FltObjects, Flags ) ) { __leave; } status = GenerateStreamHandleContext( gFileMgr.m_FileFilter, FltObjects, &pStreamHandleContext ); if ( !NT_SUCCESS( status ) ) { pStreamHandleContext = NULL; __leave; } if ( IsPrefetchEcpPresent( gFileMgr.m_FileFilter, Data ) ) { SetFlag( pStreamHandleContext->m_Flags, _STREAM_H_FLAGS_ECPPREF ); __leave; } if ( !gFileMgr.m_FltSystem->IsFiltersExist() ) { __leave; } VERDICT Verdict = VERDICT_NOT_FILTERED; FileInterceptorContext event( Data, FltObjects, pStreamHandleContext->m_StreamCtx, FILE_MINIFILTER, OP_FILE_CREATE, 0, PostProcessing ); PARAMS_MASK params2user; status = gFileMgr.m_FltSystem->FilterEvent( &event, &Verdict, ¶ms2user ); if ( NT_SUCCESS( status ) ) { if ( FlagOn( Verdict, VERDICT_ASK ) ) { status = ChannelAskUser( &event, params2user, &Verdict ); if ( NT_SUCCESS( status ) ) { // nothing todo } } if ( FlagOn( Verdict, VERDICT_DENY ) ) { Data->IoStatus.Status = STATUS_ACCESS_DENIED; Data->IoStatus.Information = 0; if ( FlagOn( FltObjects->FileObject->Flags, FO_HANDLE_CREATED ) ) { // file already has handle(s)! // skip blocking } else { FltCancelFileOpen( FltObjects->Instance, FltObjects->FileObject ); } } else { if ( FlagOn( Verdict, VERDICT_CACHE1 ) ) { event.SetCache1(); } } } } __finally { ReleaseContext( (PFLT_CONTEXT*) &pStreamHandleContext ); } return fltStatus; }
__checkReturn FLT_PREOP_CALLBACK_STATUS FLTAPI PreCleanup ( __inout PFLT_CALLBACK_DATA Data, __in PCFLT_RELATED_OBJECTS FltObjects, __out PVOID *CompletionContext ) { NTSTATUS status; UNREFERENCED_PARAMETER( CompletionContext ); FLT_PREOP_CALLBACK_STATUS fltStatus = FLT_PREOP_SUCCESS_NO_CALLBACK; PStreamHandleContext pStreamHandleContext = NULL; __try { status = GetStreamHandleContext( FltObjects, &pStreamHandleContext ); if ( !NT_SUCCESS( status ) ) { pStreamHandleContext = NULL; __leave; } if ( FlagOn( pStreamHandleContext->m_Flags, _STREAM_H_FLAGS_ECPPREF ) ) { __leave; } if ( !gFileMgr.m_FltSystem->IsFiltersExist() ) { __leave; } VERDICT Verdict = VERDICT_NOT_FILTERED; FileInterceptorContext event( Data, FltObjects, pStreamHandleContext->m_StreamCtx, FILE_MINIFILTER, OP_FILE_CLEANUP, 0, PreProcessing ); PARAMS_MASK params2user; status = gFileMgr.m_FltSystem->FilterEvent( &event, &Verdict, ¶ms2user ); if ( NT_SUCCESS( status ) && FlagOn( Verdict, VERDICT_ASK ) ) { status = ChannelAskUser( &event, params2user, &Verdict ); if ( NT_SUCCESS( status ) ) { if ( !FlagOn( Verdict, VERDICT_DENY) && FlagOn( Verdict, VERDICT_CACHE1 ) ) { event.SetCache1(); } } } } __finally { ReleaseContext( (PFLT_CONTEXT*) &pStreamHandleContext ); } return fltStatus; }
bool AvFormatDecoderDVD::ProcessVideoPacket(AVStream *stream, AVPacket *pkt) { int64_t pts = pkt->pts; if (pts == AV_NOPTS_VALUE) pts = pkt->dts; CheckContext(pts); bool ret = AvFormatDecoder::ProcessVideoPacket(stream, pkt); if( ret && m_curContext && pts != AV_NOPTS_VALUE && pts + pkt->duration == m_curContext->GetSeqEndPTS()) { // If this video frame is the last in the sequence, // make a copy of it so we can 'generate' more // to fill in the gaps (e.g. when a single frame // should be displayed with audio) if (!m_lastVideoPkt) { m_lastVideoPkt = new AVPacket; memset(m_lastVideoPkt, 0, sizeof(AVPacket)); } else { av_free_packet(m_lastVideoPkt); } av_init_packet(m_lastVideoPkt); av_copy_packet(m_lastVideoPkt, pkt); m_lbaLastVideoPkt = m_curContext->GetLBA(); if (m_returnContext) { // After seeking in a slideshow, we needed to find // the previous video frame to display. // We've found it now, so we need to jump back to // where we originally wanted to be. LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString( "Found video packet, jumping back to sector %1") .arg(m_returnContext->GetLBA())); ringBuffer->DVD()->SectorSeek(m_returnContext->GetLBA()); ReleaseContext(m_returnContext); } else { if (m_lastVideoPkt->pts != AV_NOPTS_VALUE) m_lastVideoPkt->pts += pkt->duration; if (m_lastVideoPkt->dts != AV_NOPTS_VALUE) m_lastVideoPkt->dts += pkt->duration; m_framesReq = m_curContext->GetNumFrames() - m_curContext->GetNumFramesPresent(); LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString( "SeqEnd @ %1 - require %2 frame(s)") .arg(pkt->pts) .arg(m_framesReq)); } } return ret; }
int AvFormatDecoderDVD::ReadPacket(AVFormatContext *ctx, AVPacket* pkt) { int result = 0; if (m_framesReq > 0) { m_framesReq--; if (m_lastVideoPkt) { av_copy_packet(pkt, m_lastVideoPkt); if (m_lastVideoPkt->pts != AV_NOPTS_VALUE) m_lastVideoPkt->pts += pkt->duration; if (m_lastVideoPkt->dts != AV_NOPTS_VALUE) m_lastVideoPkt->dts += pkt->duration; } else { LOG(VB_GENERAL, LOG_ERR, LOC + QString( "Need to generate frame @ %1 - %2 but no frame available!") .arg(pkt->pts) .arg(m_framesReq)); } } else { bool gotPacket; do { gotPacket = true; result = av_read_frame(ctx, pkt); while (result == AVERROR_EOF && errno == EAGAIN) { if (ringBuffer->DVD()->IsReadingBlocked()) { if (ringBuffer->DVD()->GetLastEvent() == DVDNAV_HOP_CHANNEL) { // Non-seamless jump - clear all buffers m_framesReq = 0; ReleaseContext(m_curContext); while (m_contextList.size() > 0) m_contextList.takeFirst()->DecrRef(); Reset(true, false, false); m_audio->Reset(); m_parent->DiscardVideoFrames(false); } ringBuffer->DVD()->UnblockReading(); result = av_read_frame(ctx, pkt); } else { break; } } if (result >= 0) { pkt->dts = ringBuffer->DVD()->AdjustTimestamp(pkt->dts); pkt->pts = ringBuffer->DVD()->AdjustTimestamp(pkt->pts); if (m_returnContext) { // We've jumped in a slideshow and have had to jump again // to find the right video packet to show so only allow // the packets through that let us find it. gotPacket = false; AVStream *curstream = ic->streams[pkt->stream_index]; if ((curstream->codec->codec_type == AVMEDIA_TYPE_VIDEO) || (curstream->codec->codec_id == AV_CODEC_ID_DVD_NAV)) { // Allow video or NAV packets through gotPacket = true; } } } }while(!gotPacket); } return result; }
int main(int argc, char const * argv[]) { char const * const target_platform_substring = "Intel"; char const * const target_device_substring = "Graphics"; // // find platform and device ids // cl_platform_id platform_id; cl_device_id device_id; #define HS_DEVICE_NAME_SIZE 64 char device_name[HS_DEVICE_NAME_SIZE]; size_t device_name_size; cl(FindIdsByName(target_platform_substring, target_device_substring, &platform_id, &device_id, HS_DEVICE_NAME_SIZE, device_name, &device_name_size, true)); // // create context // cl_context_properties context_properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform_id, 0 }; cl_int cl_err; cl_context context = clCreateContext(context_properties, 1, &device_id, NULL, NULL, &cl_err); cl_ok(cl_err); // // create command queue // #if 0 // OPENCL 2.0 cl_queue_properties props[] = { CL_QUEUE_PROPERTIES, (cl_queue_properties)CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, #ifndef NDEBUG (cl_queue_properties)CL_QUEUE_PROFILING_ENABLE, #endif 0 }; cl_queue_properties props_profile[] = { CL_QUEUE_PROPERTIES, (cl_queue_properties)CL_QUEUE_PROFILING_ENABLE, 0 }; cl_command_queue cq = clCreateCommandQueueWithProperties(context, device_id, props, &cl_err); cl_ok(cl_err); cl_command_queue cq_profile = clCreateCommandQueueWithProperties(context, device_id, props_profile, &cl_err); cl_ok(cl_err); #else // OPENCL 1.2 cl_command_queue cq = clCreateCommandQueue(context, device_id, #ifndef NDEBUG CL_QUEUE_PROFILING_ENABLE | #endif CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &cl_err); cl_ok(cl_err); cl_command_queue cq_profile = clCreateCommandQueue(context, device_id, CL_QUEUE_PROFILING_ENABLE, &cl_err); cl_ok(cl_err); #endif // // Intel GEN workaround -- create dummy kernel for semi-accurate // profiling on an out-of-order queue. // hs_dummy_kernel_create(context,device_id); // // select the target // uint32_t const key_val_words = (argc == 1) ? 2 : strtoul(argv[1],NULL,0); struct hs_cl_target const * hs_target; if (key_val_words == 1) hs_target = &hs_intel_gen8_u32; else hs_target = &hs_intel_gen8_u64; // // create kernels // fprintf(stdout,"Creating... "); struct hs_cl * const hs = hs_cl_create(hs_target,context,device_id); fprintf(stdout,"done.\n"); // // // #ifdef NDEBUG #define HS_BENCH_LOOPS 100 #define HS_BENCH_WARMUP 100 #else #define HS_BENCH_LOOPS 1 #define HS_BENCH_WARMUP 0 #endif // // sort sizes and loops // uint32_t const kpb = hs_target->config.slab.height << hs_target->config.slab.width_log2; uint32_t const count_lo = (argc <= 2) ? kpb : strtoul(argv[2],NULL,0); uint32_t const count_hi = (argc <= 3) ? count_lo : strtoul(argv[3],NULL,0); uint32_t const count_step = (argc <= 4) ? count_lo : strtoul(argv[4],NULL,0); uint32_t const loops = (argc <= 5) ? HS_BENCH_LOOPS : strtoul(argv[5],NULL,0); uint32_t const warmup = (argc <= 6) ? HS_BENCH_WARMUP : strtoul(argv[6],NULL,0); bool const linearize = (argc <= 7) ? true : strtoul(argv[7],NULL,0); // // labels // fprintf(stdout, "Device, " "Driver, " "Type, " "Slab/Linear, " "Verified?, " "Keys, " "Keys Padded In, " "Keys Padded Out, " "CPU Algorithm, " "CPU Msecs, " "CPU Mkeys/s, " "Trials, " "Avg. Msecs, " "Min Msecs, " "Max Msecs, " "Avg. Mkeys/s, " "Max. Mkeys/s\n"); // // we want to track driver versions // size_t driver_version_size; cl(GetDeviceInfo(device_id, CL_DRIVER_VERSION, 0, NULL, &driver_version_size)); char * const driver_version = ALLOCA_MACRO(driver_version_size); cl(GetDeviceInfo(device_id, CL_DRIVER_VERSION, driver_version_size, driver_version, NULL)); // // benchmark // hs_bench(context, cq,cq_profile, device_name, driver_version, hs_target->config.words.key + hs_target->config.words.val, 1 << hs_target->config.slab.width_log2, hs_target->config.slab.height, hs, count_lo, count_hi, count_step, loops, warmup, linearize); // // release everything // hs_cl_release(hs); hs_dummy_kernel_release(); cl(ReleaseCommandQueue(cq)); cl(ReleaseCommandQueue(cq_profile)); cl(ReleaseContext(context)); return 0; }