void JobThread::Run() { while (job_manager->IsRunning()) { ProcessAll(); YieldExecution(); } ProcessAll(); }
/************************************************************ Start the unbind of a network driver from the protocol driver ************************************************************/ VOID NDIS_API PacketUnbindAdapter( OUT PNDIS_STATUS Status, IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_HANDLE UnbindContext ) { POPEN_INSTANCE Open; NDIS_STATUS nsCloseStatus; TRACE_ENTER( "UnbindAdapter" ); Open = (POPEN_INSTANCE)ProtocolBindingContext; Open->BindAdapterContext = UnbindContext; /*clean the pending requests*/ PacketCleanUp( Status, Open ); Open->Status = NDIS_STATUS_PENDING; /*Calls NDIS to close the selected adapter*/ NdisCloseAdapter( &nsCloseStatus, Open->AdapterHandle ); if ( nsCloseStatus == NDIS_STATUS_PENDING ) { while ( Open->Status == NDIS_STATUS_PENDING ) YieldExecution(); } else { PacketUnbindAdapterComplete( Open, nsCloseStatus ); } *Status = Open->Status; if ( *Status == NDIS_STATUS_SUCCESS ) { NdisFreeMemory( Open, sizeof( OPEN_INSTANCE ) , 0 ); } else { IF_TRACE( "Unbind Operation FAILED!" ); } TRACE_LEAVE( "CloseAdapter" ); return; }
VOID TryConnectPort(char *port_name) { DWORD Status = 0; HANDLE Port = 0; int i; UNICODE_STRING PortName; OBJECT_ATTRIBUTES ObjectAttributes; WORD Name [BUF_SIZE] = {0}; int dwx = 0; char * port_name_save = port_name; /* * Convert the port's name to Unicode. */ for ( PortName.Length = 0; ( *port_name && (PortName.Length < BUF_SIZE) ); ) { Name[PortName.Length++] = (WORD) *port_name++; } Name[PortName.Length] = 0; PortName.Length = PortName.Length * sizeof (WORD); PortName.MaximumLength = PortName.Length + sizeof (WORD); PortName.Buffer = (PWSTR) Name; /* * Prepare the port object attributes. */ ObjectAttributes.Length = sizeof (OBJECT_ATTRIBUTES); ObjectAttributes.RootDirectory = NULL; ObjectAttributes.ObjectName = NULL /*& PortName */; ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; ObjectAttributes.SecurityDescriptor = NULL; ObjectAttributes.SecurityQualityOfService = NULL; /* * Try to issue a connection request. */ Port = 0; Status = ConnectPort( & Port, /* & PortHandle */ & PortName, /* & PortName */ & ObjectAttributes, /* & PortAttributes */ NULL, /* & SecurityQos */ NULL, /* & SectionInfo */ NULL, /* & MapInfo */ NULL, /* & MaxMessageSize */ LPC_CONNECT_FLAG5 /* & ConnectInfoLength */ ); if (Status == STATUS_SUCCESS) { DumpInfo( Name, Status, "connected", Port ); /* Hot waiting */ for (dwx=0; dwx<MAXARG; ++dwx) { YieldExecution(); } if (FALSE == CloseHandle(Port)) { printf( "Could not close the port handle %08X.\n", Port ); } return; } printf( "Connection to port \"%s\" failed (Status = %08X).\n", port_name_save, Status ); }
int32 rwmain( Interface *engineInterface ) { // Matrix test. { static RwMatrix newMat = { { 1, 2, 3, 4 }, { 6, 5, 3, 7 }, { 2, 7, 5, 4 }, { 2, 5, 4, 6 } }; static RwMatrix srcIdent = { { 4, 5, 3, 4 }, { 8, 3, 7, 5 }, { 2, 1, 6, 3 }, { 5, 8, 4, 5 } }; static RwMatrix target( newMat * srcIdent ); target *= 4.5; __debugbreak(); } // Give information about the running application to the runtime. softwareMetaInfo metaInfo; metaInfo.applicationName = "RenderWare Sample"; metaInfo.applicationVersion = "test"; metaInfo.description = "A test application for the rwtools runtime"; engineInterface->SetApplicationInfo( metaInfo ); // Create a window and render into it. Window *rwWindow = MakeWindow( engineInterface, 640, 480 ); if ( !rwWindow ) return -1; // We hold an extra reference. AcquireObject( rwWindow ); // Handle the window closing event. RegisterEventHandler( rwWindow, event_t::WINDOW_CLOSING, window_closing_event_handler ); RegisterEventHandler( rwWindow, event_t::WINDOW_QUIT, window_closing_event_handler ); // Show the window, since we have set it up by now. rwWindow->SetVisible( true ); // Create the game renderer. Driver *d3dDriver = CreateDriver( engineInterface, "Direct3D12" ); assert( d3dDriver != NULL ); // Set up the game resources. DriverSwapChain *swapChain = d3dDriver->CreateSwapChain( rwWindow, 2 ); // we want to double-buffer. DrawingLayer2D *guiContext = CreateDrawingLayer2D( d3dDriver ); // We have to get the ref count over here, because the swap chain increases the ref count as well. uint32 wndBaseRefCount = GetRefCount( rwWindow ); // Execute the main loop while ( GetRefCount( rwWindow ) >= wndBaseRefCount ) // we wait until somebody requested to destroy the window. { // Draw the game scene. { // Set render states. guiContext->SetRenderState( DrawingLayer2D::RWSTATE_UTEXADDRESSMODE, RWTEXADDRESS_WRAP ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_VTEXADDRESSMODE, RWTEXADDRESS_WRAP ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ZWRITEENABLE, true ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_TEXFILTER, RWFILTER_POINT ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_SRCBLEND, RWBLEND_ONE ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_DSTBLEND, RWBLEND_ZERO ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ALPHABLENDENABLE, true ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ALPHAFUNC, RWCMP_ALWAYS ); guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ALPHAREF, 0 ); #if 0 // Execute draws. guiContext->Begin(); guiContext->DrawRect( 50, 50, 100, 100 ); guiContext->DrawRect( 60, 60, 80, 80 ); guiContext->DrawLine( 10, 10, 290, 150 ); guiContext->End(); #endif } // Give cycles to the window manager. // In the multi-threaded environment, this will effectively be a no-op. PulseWindowingSystem( engineInterface ); // We want to give some cycles to the OS. // Otherwise our thread would starve everything. YieldExecution( 1 ); } // Hide the window. // Do this because terminating resources takes some time and // the user already knows this application is terminating. rwWindow->SetVisible( false ); // Destroy drawing contexts. DeleteDrawingLayer2D( guiContext ); // Release the swap chain device resource. d3dDriver->DestroySwapChain( swapChain ); // Terminate the driver. DestroyDriver( engineInterface, d3dDriver ); // Release our window reference. // This will destroy it. engineInterface->DeleteRwObject( rwWindow ); return 0; }
VOID TryCreatePort(char *port_name) { DWORD Status = 0; HANDLE Port = 0; int i; UNICODE_STRING PortName; OBJECT_ATTRIBUTES ObjectAttributes; WORD Name [BUF_SIZE] = {0}; int dwx = 0; char * port_name_save = port_name; /* * Convert the port's name to Unicode. */ for ( PortName.Length = 0; ( *port_name && (PortName.Length < BUF_SIZE) ); ) { Name[PortName.Length++] = (WORD) *port_name++; } Name[PortName.Length] = 0; PortName.Length = PortName.Length * sizeof (WORD); PortName.MaximumLength = PortName.Length + sizeof (WORD); PortName.Buffer = (PWSTR) Name; /* * Prepare the port object attributes. */ ObjectAttributes.Length = sizeof (OBJECT_ATTRIBUTES); ObjectAttributes.RootDirectory = NULL; ObjectAttributes.ObjectName = & PortName; ObjectAttributes.Attributes = 0; //OBJ_CASE_INSENSITIVE --> STATUS_INVALID_PARAMETER ==> case sensitive!; ObjectAttributes.SecurityDescriptor = NULL; ObjectAttributes.SecurityQualityOfService = NULL; /* * Try to issue a connection request. */ Port = 0; Status = CreatePort( & Port, & ObjectAttributes, 0, /* ACCESS_MASK? */ 0, /* Unknown3 */ LPC_CONNECT_FLAG5 ); if (Status == STATUS_SUCCESS) { DumpInfo( Name, Status, "created", Port ); /* Hot waiting */ for (dwx=0; dwx<MAXARG; ++dwx) { YieldExecution(); } if (FALSE == CloseHandle(Port)) { printf( "Could not close the port handle %08X.\n", Port ); } return; } printf( "Creating port \"%s\" failed (Status = %08X).\n", port_name_save, Status ); }
DWORD PacketOpen(PNDIS_STRING AdapterName,DWORD dwDDB,DWORD hDevice,PDIOCPARAMETERS pDiocParms) { LARGE_INTEGER SystemTime; __int64 ltime1; PDEVICE_EXTENSION pde; POPEN_INSTANCE oiNew; NDIS_STATUS nsErrorStatus, nsOpenStatus; UINT i; UINT uiMedium; NDIS_STRING NameStr; NDIS_STATUS Status; pde = GlobalDeviceExtension; /*Allocate an element that describe an adapter*/ NdisAllocateMemory( (PVOID *)&oiNew, sizeof( OPEN_INSTANCE ), 0, -1 ); if ( oiNew == NULL ) { return NDIS_STATUS_FAILURE; } NdisZeroMemory( (PVOID)oiNew, sizeof( OPEN_INSTANCE ) ); /*allocate a pool for the packet headers*/ NdisAllocatePacketPool( &nsErrorStatus, &(oiNew->PacketPool), TRANSMIT_PACKETS, sizeof(PACKET_RESERVED) ); IF_TRACE_MSG( "PACKET_RESERVED_a :%lx",sizeof(PACKET_RESERVED)); if ( nsErrorStatus != NDIS_STATUS_SUCCESS ) { IF_TRACE_MSG( "Failed to allocate packet pool AllocStatus=%x", nsErrorStatus ); NdisFreeMemory( oiNew, sizeof( OPEN_INSTANCE ) , 0 ); TRACE_LEAVE( "BindAdapter" ); return NDIS_STATUS_FAILURE; } /*allocate a buffer pool for the packet data*/ NdisAllocateBufferPool( &nsErrorStatus, &(oiNew->BufferPool), TRANSMIT_PACKETS ); if ( nsErrorStatus != NDIS_STATUS_SUCCESS ) { IF_TRACE_MSG( "Failed to allocate packet pool AllocStatus=%x", nsErrorStatus ); NdisFreePacketPool( oiNew->PacketPool ); NdisFreeMemory( oiNew, sizeof( OPEN_INSTANCE ) , 0 ); TRACE_LEAVE( "BindAdapter" ); return NDIS_STATUS_FAILURE; } NdisAllocateSpinLock( &(oiNew->ResetSpinLock) ); InitializeListHead( &(oiNew->ResetIrpList) ); NdisAllocateSpinLock( &(oiNew->RcvQSpinLock) ); InitializeListHead( &(oiNew->RcvList) ); NdisAllocateSpinLock( &(oiNew->RequestSpinLock) ); InitializeListHead( &(oiNew->RequestList) ); for ( i=0; i<MAX_REQUESTS; i++ ) { InsertTailList( &(oiNew->RequestList), &(oiNew->Requests[i].Reserved.ListElement) ); } oiNew->Status = NDIS_STATUS_PENDING; /*initialize the timer variables for this session*/ SystemTime=GetDate(); ltime1=((__int64)SystemTime.HighPart*86400); ltime1+=(__int64)(SystemTime.LowPart/1000); //current time from 1980 in seconds ltime1+=(__int64)315532800; //current time from 1970 (Unix format) in seconds ltime1*=1193182; ltime1+=(SystemTime.LowPart%1000)*1193182/1000; //current time from 1970 in ticks ltime1-=QuerySystemTime(); //boot time from 1970 in ticks oiNew->StartTime=ltime1; oiNew->Dropped=0; //reset the dropped packets counter oiNew->Received=0; //reset the received packets counter oiNew->bpfprogram=NULL; //set an accept-all filter oiNew->bpfprogramlen=0; oiNew->BufSize=0; //set an empty buffer oiNew->Buffer=NULL; //reset the buffer oiNew->Bhead=0; oiNew->Btail=0; oiNew->BLastByte=0; oiNew->TimeOut=0; //reset the timeouts oiNew->ReadTimeoutTimer=0; oiNew->mode=0; //set capture mode oiNew->Nbytes=0; //reset the counters oiNew->Npackets=0; oiNew->hDevice=hDevice; oiNew->tagProcess=pDiocParms->tagProcess; oiNew->ReadEvent=0; //reset the read event NdisAllocateSpinLock( &(oiNew->CountersLock) ); /*open the MAC driver calling NDIS*/ NdisOpenAdapter( &nsOpenStatus, &nsErrorStatus, &oiNew->AdapterHandle, &uiMedium, MediumArray, NUM_NDIS_MEDIA, pde->NdisProtocolHandle, oiNew, AdapterName, 0, NULL ); IF_TRACE_MSG( "Open Status : %lx", nsOpenStatus ); IF_TRACE_MSG( "Error Status : %lx", nsErrorStatus ); IF_TRACE_MSG( "Completion Status : %lx", oiNew->Status ); if ( nsOpenStatus == NDIS_STATUS_PENDING ) { while ( oiNew->Status == NDIS_STATUS_PENDING ) YieldExecution(); } else { PacketOpenAdapterComplete( oiNew, nsOpenStatus, nsErrorStatus ); } Status = oiNew->Status; if ( Status != NDIS_STATUS_SUCCESS ) { NdisFreeMemory( oiNew, sizeof( OPEN_INSTANCE ) , 0 ); return NDIS_STATUS_FAILURE; } else { } TRACE_LEAVE( "BindAdapter" ); /*return succesfully*/ return STATUS_SUCCESS; }
/************************************************************ Function used by NDIS to update the VXD when a new MAC driver is added ************************************************************/ VOID NDIS_API PacketBindAdapter( OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindAdapterContext, IN PNDIS_STRING AdapterName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2 ) { PDEVICE_EXTENSION pde; POPEN_INSTANCE oiNew; NDIS_STATUS nsErrorStatus, nsOpenStatus; UINT uiMedium; UINT i; PWRAPPER_PROTOCOL_BLOCK pWPBlock; PNDIS_PROTOCOL_CHARACTERISTICS pNPChar; PADAPTER_NAME AName; PWRAPPER_MAC_BLOCK pWMBlock; PNDIS_MAC_CHARACTERISTICS pNMChar; BYTE *lpzName; TRACE_ENTER( "BindAdapter" ); pde = GlobalDeviceExtension; /*Allocate an element that describe an adapter*/ NdisAllocateMemory( (PVOID *)&AName, sizeof(ADAPTER_NAME), 0, -1 ); if ( AName == NULL ) { *Status = NDIS_STATUS_RESOURCES; return; } NdisAllocateMemory( (PVOID *)&oiNew, sizeof( OPEN_INSTANCE ), 0, -1 ); if ( oiNew == NULL ) { *Status = NDIS_STATUS_RESOURCES; return; } NdisZeroMemory( (PVOID)oiNew, sizeof( OPEN_INSTANCE ) ); /*Save Binding Context*/ oiNew->BindAdapterContext = BindAdapterContext; /*Save the device handle*/ oiNew->hDevice = (DWORD) SystemSpecific1; /*allocate a pool for the packet headers*/ NdisAllocatePacketPool( &nsErrorStatus, &(oiNew->PacketPool), TRANSMIT_PACKETS, sizeof(PACKET_RESERVED) ); IF_TRACE_MSG( "PACKET_RESERVED_b :%lx",sizeof(PACKET_RESERVED)); if ( nsErrorStatus != NDIS_STATUS_SUCCESS ) { IF_TRACE_MSG( "Failed to allocate packet pool AllocStatus=%x", nsErrorStatus ); NdisFreeMemory( oiNew, sizeof( OPEN_INSTANCE ) , 0 ); *Status = NDIS_STATUS_RESOURCES; TRACE_LEAVE( "BindAdapter" ); return; } /*allocate a pool for the packet data*/ NdisAllocateBufferPool( &nsErrorStatus, &(oiNew->BufferPool), TRANSMIT_PACKETS ); if ( nsErrorStatus != NDIS_STATUS_SUCCESS ) { IF_TRACE_MSG( "Failed to allocate packet pool AllocStatus=%x", nsErrorStatus ); NdisFreePacketPool( oiNew->PacketPool ); NdisFreeMemory( oiNew, sizeof( OPEN_INSTANCE ) , 0 ); *Status = NDIS_STATUS_RESOURCES; TRACE_LEAVE( "BindAdapter" ); return; } NdisAllocateSpinLock( &(oiNew->ResetSpinLock) ); InitializeListHead( &(oiNew->ResetIrpList) ); NdisAllocateSpinLock( &(oiNew->RcvQSpinLock) ); InitializeListHead( &(oiNew->RcvList) ); NdisAllocateSpinLock( &(oiNew->RequestSpinLock) ); InitializeListHead( &(oiNew->RequestList) ); for ( i=0; i<MAX_REQUESTS; i++ ) { InsertTailList( &(oiNew->RequestList), &(oiNew->Requests[i].Reserved.ListElement) ); } oiNew->Status = NDIS_STATUS_PENDING; oiNew->BindAdapterContext = BindAdapterContext; /*open the MAC driver calling NDIS*/ oiNew->hDevice=0; oiNew->tagProcess=0; NdisOpenAdapter( &nsOpenStatus, &nsErrorStatus, &oiNew->AdapterHandle, &uiMedium, MediumArray, NUM_NDIS_MEDIA, pde->NdisProtocolHandle, oiNew, AdapterName, 0, NULL ); IF_TRACE_MSG( "Open Status : %lx", nsOpenStatus ); IF_TRACE_MSG( "Error Status : %lx", nsErrorStatus ); IF_TRACE_MSG( "Completion Status : %lx", oiNew->Status ); if ( nsOpenStatus == NDIS_STATUS_PENDING ) { while ( oiNew->Status == NDIS_STATUS_PENDING ) YieldExecution(); } else { PacketOpenAdapterComplete( oiNew, nsOpenStatus, nsErrorStatus ); } pWPBlock = ((PWRAPPER_OPEN_BLOCK)(oiNew->AdapterHandle))->ProtocolHandle; pNPChar = &pWPBlock->ProtocolCharacteristics; IF_TRACE_MSG( "Protocol : %s", pNPChar->Name.Buffer ); IF_TRACE_MSG( "Protocol Handle : %lx", pde->NdisProtocolHandle ); IF_TRACE_MSG( "PWRAPPER_OPEN_BLOCK : %lx", oiNew->AdapterHandle ); IF_TRACE_MSG( "PWRAPPER_PROTOCOL_BLOCK : %lx", pWPBlock ); IF_TRACE_MSG( "NDIS_PROTOCOL_CHARACTERISTICS : %lx", pNPChar ); IF_TRACE_MSG( "Name : %lx", &pNPChar->Name ); IF_TRACE_MSG( "Adapter Name : %s", AdapterName->Buffer ); *Status = oiNew->Status; if ( *Status != NDIS_STATUS_SUCCESS ) { NdisFreeMemory( oiNew, sizeof( OPEN_INSTANCE ) , 0 ); IF_TRACE( "Bind Operation FAILED!" ); } else { AName->realnamestr.Length=AdapterName->Length; AName->realnamestr.MaximumLength=AdapterName->MaximumLength; AName->realnamestr.Buffer=AName->realname; for(i=0; i<32; i++)AName->realname[i]=AdapterName->Buffer[i]; pWMBlock = ((PWRAPPER_OPEN_BLOCK)(oiNew->AdapterHandle))->MacHandle; pNMChar = &pWMBlock->MacCharacteristics; lpzName = pNMChar->Name.Buffer; for(i=0; i<32; i++)AName->devicename[i]=lpzName[i]; InsertTailList( &GlobalDeviceExtension->AdapterNames, &AName->ListElement); //close the adapter NdisCloseAdapter(&nsErrorStatus,oiNew->AdapterHandle); if ( nsErrorStatus == NDIS_STATUS_PENDING ) { while ( oiNew->Status == NDIS_STATUS_PENDING ) YieldExecution(); } else { PacketUnbindAdapterComplete( oiNew, nsErrorStatus ); } *Status = oiNew->Status; if ( *Status == NDIS_STATUS_SUCCESS ) { //remove this adapter from the list of open adapters RemoveEntryList(&(oiNew->ListElement)); //free the memory NdisFreeMemory( oiNew, sizeof( OPEN_INSTANCE ) , 0 ); } else { IF_TRACE( "Close Operation FAILED!" ); } } TRACE_LEAVE( "BindAdapter" ); return; }
DWORD PacketClose(POPEN_INSTANCE Open,DWORD dwDDB,DWORD hDevice,PDIOCPARAMETERS pDiocParms) { NDIS_STATUS Status; NDIS_STATUS nsErrorStatus; UINT to; DWORD TEvent; TRACE_ENTER( "PacketClose" ); Open->BufSize=0; to=Open->ReadTimeoutTimer; Open->ReadTimeoutTimer=0; if(to!=0) { _asm push esi; _asm mov esi,to; CancelReadTimeOut(); _asm pop esi; } // Free the read event TEvent=Open->ReadEvent; _asm mov eax,TEvent; VxDCall(_VWIN32_CloseVxDHandle); //close the adapter NdisCloseAdapter(&nsErrorStatus,Open->AdapterHandle); if ( nsErrorStatus == NDIS_STATUS_PENDING ) { while ( Open->Status == NDIS_STATUS_PENDING ) YieldExecution(); if(Open->Status!=NDIS_STATUS_SUCCESS) { TRACE_LEAVE( "PacketClose" ); return NDIS_STATUS_FAILURE; } } else { PacketUnbindAdapterComplete( Open, nsErrorStatus ); if(nsErrorStatus!=NDIS_STATUS_SUCCESS) { TRACE_LEAVE( "PacketClose" ); return NDIS_STATUS_FAILURE; } } Status = Open->Status; if(Open->Buffer!=NULL)NdisFreeMemory(Open->Buffer,Open->BufSize,0); Open->Buffer=NULL; if(Open->bpfprogram!=NULL)NdisFreeMemory(Open->bpfprogram,Open->bpfprogramlen,0); //remove this adapter from the list of open adapters NdisAcquireSpinLock( &GlobalDeviceExtension->OpenSpinLock ); RemoveEntryList(&(Open->ListElement)); NdisReleaseSpinLock( &GlobalDeviceExtension->OpenSpinLock ); NdisFreeMemory( Open, sizeof( OPEN_INSTANCE ) , 0 ); if(pDiocParms!=NULL) *(DWORD *)(pDiocParms->lpcbBytesReturned) = 0; TRACE_LEAVE( "PacketClose" ); return Status; }