Пример #1
0
bool neoSystemOpen(const char* szFileName)
{
	TNeoRomHeader header;
	int rom;
	u32 bit;

	ASSERT(g_neo->cpuClockDivide == 2 || g_neo->cpuClockDivide == 3);

	guiConsoleLogf("Loading %s...", szFileName);
	guiConsoleDump();

	rom = systemOpen(szFileName, false);

	ASSERTMSG(g_neo->cpuClockDivide == 2 || g_neo->cpuClockDivide == 3, "%d", g_neo->cpuClockDivide);

	if(rom < 0) {
		guiConsoleLogf(" -> Failed!");
		ASSERT(0);
		return false;
	}
	systemRead(rom, &header, sizeof(TNeoRomHeader));

	if(header.magic != NEO_ROM_MAGIC ||
		header.version != NEO_ROM_VERSION ||
		header.sectionCount != NEOROM_COUNT) {

		systemClose(rom);
		guiConsoleLogf(" -> invalid rom");
		guiConsoleLogf(" -> magic %08X / %08X", header.magic, NEO_ROM_MAGIC);
		guiConsoleLogf(" -> version %d / %d", header.version, NEO_ROM_VERSION);
		guiConsoleLogf(" -> section %d / %d", header.sectionCount, NEOROM_COUNT);
		ASSERT(0);
		return false;
	}

	neoSystemClose();

	g_romSize = systemFileSize(rom) - NEO_HEADER_SIZE;
	g_header = header;
	g_rom = rom;

	linearHeapReset(&g_vramHHeap);
	linearHeapClear(&g_vramHHeap);

	g_neo->scanline = 0;
	g_neo->frameCount = 0;
	g_neo->irqPending = 0;
	g_neo->paletteBank = 0;
	g_neo->fixedBank = 0;
	g_neo->sramProtectCount = 0;
	g_neo->debug = true;

	g_neo->irqVectorLatch = false;
	g_neo->screenDarkLatch = false;
	g_neo->fixedRomLatch = false;
	g_neo->sramProtectLatch = false;
	g_neo->paletteRamLatch = false;
	g_neo->smaRand = 0x2345;
	NEOIPC->audioCommandPending = 0;
	NEOIPC->audioResult = 0;
	
	//sram hack gets around watchdog protection check...values taken from GnGeo
	//added samsho5 variations
	g_neo->sramProtection = g_header.sramProtection;

	guiConsoleLogf("Loaded Game: %s", g_header.name);
	
	g_neo->spriteCount = g_header.romEntry[NEOROM_SPRITEDATA].size / SPRITE_SIZE;
	g_neo->spriteMask = 0xffffffff;
	for(bit = 0x80000000; bit != 0; bit >>= 1) {
		if((g_neo->spriteCount - 1) & bit) break;
		g_neo->spriteMask >>= 1;
	}

	g_neo->romBankCount = 0;
	const s32 bankSize = (s32)g_header.romEntry[NEOROM_MAINPROGRAM].size - 1*MB;
	if(bankSize > 0) {
		g_neo->romBankCount = bankSize / (1*MB);
		if(g_neo->romBankCount * 1*MB != bankSize) {
			g_neo->romBankCount++;
			guiConsoleLogf(" -> partial rom bank");
		}
	}

	guiConsoleLogf(" -> sprites: %d", g_neo->spriteCount);
	guiConsoleLogf(" -> mask: %08X", g_neo->spriteMask);
	guiConsoleLogf(" -> rom bank(s): %d", g_neo->romBankCount);
	if(g_neo->sramProtection == -1) {
		guiConsoleLogf(" -> sramProtection off");
	} else {
		guiConsoleLogf(" -> sramProtection: %08X", g_neo->sramProtection);
	}
	guiConsoleDump();

	systemRamReset();

	cpuInit();
	neoMemoryInit();
	neoIOInit();
	pd4990a_init();
	neoVideoInit();
	neoInstallProtection();
	//neoSystemIrq(INTR_COLDBOOT);
	if(NEOIPC->globalAudioEnabled) {
		neoAudioStreamInit();
		neoIPCSendCommand(NEOARM7_RESET);
	} else {
		//this is the value that needs to be set to bypass Z80 check
		NEOIPC->audioResult = 1;
	}
	cpuReset();

	neoLoadConfig(szFileName);
	neoResetContext();

	ASSERTMSG(g_neo->cpuClockDivide == 2 || g_neo->cpuClockDivide == 3, "%d",
		g_neo->cpuClockDivide);
	
	return true;
}
void CDAVCLanSettingsImpl::requestSettingInformationNotification_02A1(const DAVCLanSettings::SettingInformationNotificationType tSettingInformationNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestSettingInformationNotification_02A1( tSettingInformationNotification );
}
Пример #3
0
NTSTATUS
NTAPI
DiskReadPartitionTableEx(
    IN PFUNCTIONAL_DEVICE_EXTENSION Fdo,
    IN BOOLEAN BypassCache,
    OUT PDRIVE_LAYOUT_INFORMATION_EX* DriveLayout
    )
/*++

Routine Description:

    This routine will return the current layout information for the disk.
    If the cached information is still valid then it will be returned, 
    otherwise the layout will be retreived from the kernel and cached for 
    future use.
    
    This routine must be called with the partitioning lock held.  The 
    partition list which is returned is not guaranteed to remain valid 
    once the lock has been released.
    
Arguments:

    Fdo - a pointer to the FDO for the disk.
    
    DriveLayout - a location to store a pointer to the drive layout information.    

Return Value:

    STATUS_SUCCESS if successful or an error status indicating what failed.
    
--*/        
    
{
    PDISK_DATA diskData = Fdo->CommonExtension.DriverData;
    NTSTATUS status;
    PDRIVE_LAYOUT_INFORMATION_EX layoutEx;

    layoutEx = NULL;

    if(BypassCache) {
        diskData->CachedPartitionTableValid = FALSE;
        DebugPrint((PtCache, "DiskRPTEx: cache bypassed and invalidated for "
                             "FDO %#p\n", Fdo));
    }

    //
    // If the cached partition table is present then return a copy of it.
    //

    if(diskData->CachedPartitionTableValid == TRUE) {

        ULONG partitionNumber;
        PDRIVE_LAYOUT_INFORMATION_EX layout = diskData->CachedPartitionTable;

        //
        // Clear the partition numbers from the list entries
        //

        for(partitionNumber = 0;
            partitionNumber < layout->PartitionCount;
            partitionNumber++) {
            layout->PartitionEntry[partitionNumber].PartitionNumber = 0;
        }

        *DriveLayout = diskData->CachedPartitionTable;

        DebugPrint((PtCache, "DiskRPTEx: cached PT returned (%#p) for "
                             "FDO %#p\n", 
                    *DriveLayout, Fdo));
                    
        return STATUS_SUCCESS;
    }

    ASSERTMSG("DiskReadPartitionTableEx is not using cached partition table",
              (DiskBreakOnPtInval == FALSE));

    //
    // If there's a cached partition table still around then free it.
    //

    if(diskData->CachedPartitionTable) {
        DebugPrint((PtCache, "DiskRPTEx: cached PT (%#p) freed for FDO %#p\n",
                    diskData->CachedPartitionTable, Fdo));

        ExFreePool(diskData->CachedPartitionTable);
        diskData->CachedPartitionTable = NULL;
    }

    //
    // By default, X86 disables recognition of GPT disks. Instead we
    // return the protective MBR partition. Use IoReadPartitionTable
    // to get this.
    //
    
    status = IoReadPartitionTableEx(Fdo->DeviceObject, &layoutEx);

    if (DiskDisableGpt) {
        PDRIVE_LAYOUT_INFORMATION layout;

        if (NT_SUCCESS (status) &&
            layoutEx->PartitionStyle == PARTITION_STYLE_GPT) {

            //
            // ISSUE - 2000/29/08 - math: Remove from final product.
            // Leave this debug print in for a while until everybody
            // has had a chance to convert their GPT disks to MBR.
            //
            
            DbgPrint ("DISK: Disk %p recognized as a GPT disk on a system without GPT support.\n"
                      "      Disk will appear as RAW.\n",
                      Fdo->DeviceObject);

            ExFreePool (layoutEx);
            status = IoReadPartitionTable(Fdo->DeviceObject,
                                          Fdo->DiskGeometry.BytesPerSector,
                                          FALSE,
                                          &layout);
            if (NT_SUCCESS (status)) {
                layoutEx = DiskConvertLayoutToExtended(layout);
                ExFreePool (layout);
            }
        }
    }

    diskData->CachedPartitionTable = layoutEx;

    //
    // If the routine fails make sure we don't have a stale partition table 
    // pointer.  Otherwise indicate that the table is now valid.
    //

    if(!NT_SUCCESS(status)) {
        diskData->CachedPartitionTable = NULL;
    } else {
        diskData->CachedPartitionTableValid = TRUE;
    }

    *DriveLayout = diskData->CachedPartitionTable;

    DebugPrint((PtCache, "DiskRPTEx: returning PT %#p for FDO %#p with status "
                         "%#08lx.  PT is %scached\n",
                *DriveLayout,
                Fdo,
                status,
                (diskData->CachedPartitionTableValid ? "" : "not ")));


    return status;
}
void CDAVCLanSettingsImpl::requestForcedBeepNotification_64(const DAVCLanSettings::ForcedBeepNotificationType tForcedBeepNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestForcedBeepNotification_64( tForcedBeepNotification );
}
void CDAVCLanSettingsImpl::requestGPSTimeDataNotification_029D(const DAVCLanSettings::GPSTimeDataNotificationType tGPSTimeDataNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestGPSTimeDataNotification_029D( tGPSTimeDataNotification );
}
Пример #6
0
NTSTATUS
HwSetControl(
    PMIXER_INFO MixerInfo,
    ULONG ControlId,
    ULONG DataLength,
    PVOID ControlData
)
{
    PLOCAL_MIXER_CONTROL_INFO ControlInfo;
    int i;
    BOOLEAN Changed;
    LONG Values[2];
    BOOLEAN MixerSetResult;
    PGLOBAL_DEVICE_INFO pGDI;

    pGDI = CONTAINING_RECORD(MixerInfo, GLOBAL_DEVICE_INFO, MixerInfo);

    /*
    **  Validate control ID
    */

    if (ControlId > MAXCONTROLS) {
        return STATUS_INVALID_PARAMETER;
    }

    /*
    **  Establish pointers to our structures
    */

    ControlInfo = &pGDI->LocalMixerData.ControlInfo[ControlId];

    ASSERTMSG("Set index out of range",
              ControlInfo->SetIndex < MAXSETTABLECONTROLS ||
              ControlInfo->SetIndex == MIXER_SET_INDEX_INVALID);

    /*
    **  Validate data length and values
    */

    switch (DataLength) {
        case sizeof(LONG):
            Values[0] = *(PLONG)ControlData;
            Values[1] = Values[0];
            break;

        case sizeof(LONG) * 2:
            Values[0] = *(PLONG)ControlData;
            Values[1] = ((PLONG)ControlData)[1];
            break;

        default:
            return STATUS_BUFFER_TOO_SMALL;
    }

    /*
    **  Apparently Boolean values can be anything
    */

    if (ControlInfo->Boolean) {
        Values[0] = (ULONG)!!Values[0];
        Values[1] = (ULONG)!!Values[1];
    }

    /*
    **  Check the item ranges and assign the values.  Note that
    **  this stuff only works for <= 2 channels/items.
    */

    for (i = 0, Changed = FALSE; i < 2; i++) {
        if (ControlInfo->Signed) {
            if (Values[i] < (LONG)ControlInfo->Range.Min.s ||
                Values[i] > (LONG)ControlInfo->Range.Max.s) {

                return STATUS_INVALID_PARAMETER;
            } else {
                if ((SHORT)((PLONG)Values)[i] != ControlInfo->Data.v[i].s) {
                    Changed = TRUE;
                    ControlInfo->Data.v[i].s = (SHORT)((PLONG)Values)[i];
                }
            }
        } else {

            if ((((PULONG)Values)[i] < (ULONG)ControlInfo->Range.Min.u ||
                 ((PULONG)Values)[i] > (ULONG)ControlInfo->Range.Max.u)) {

                return STATUS_INVALID_PARAMETER;
            } else {

                /*
                **  Do muxes slightly differently so we don't store a big
                **  array of n - 1 zeros and 1 one
                */

                if (ControlInfo->Mux) {
                    if (Values[i] != (LONG)ControlInfo->Range.Min.s) {
                        /*
                        **  'On' - only turn ONE on
                        */

                        if ((USHORT)i != ControlInfo->Data.v[0].u) {
                            Changed = TRUE;

                            /*
                            **  Notify the one turned off and the
                            **  one turned on
                            */

                            SoundMixerChangedMuxItem(
                                pGDI,
                                ControlId,
                                ControlInfo->Data.v[0].u);

                            ControlInfo->Data.v[0].u = (USHORT)i;

                            SoundMixerChangedMuxItem(
                                pGDI,
                                ControlId,
                                ControlInfo->Data.v[0].u);

                        }
                        /*
                        **  Mux ONLY changes ONE thing
                        */

                        break;
                    }
                } else {
                    if ((USHORT)((PULONG)Values)[i] != ControlInfo->Data.v[i].u) {
                        Changed = TRUE;
                        ControlInfo->Data.v[i].u = (USHORT)((PULONG)Values)[i];
                    }
                }
            }
        }
    }

    if (!Changed) {
        return STATUS_SUCCESS;
    }

    /*
    **  Notify the Win32 Midi driver of changes
    */

    if (ControlId == ControlLineoutMidioutVolume) {
        SoundNotifySynth(pGDI);
    }

    /*
    **  Now pass on to the relevant handler which must :
    **     Set the hardware
    **     Determine if there is a real change so it can generate notifications
    **     Generate related changes (eg mux handling)
    */

    switch (ControlId) {
    case ControlWaveInMux:
    case ControlVoiceInMux:
    case ControlWaveInAux1Volume:
    case ControlWaveInMicVolume:
    case ControlVoiceInAux1Volume:
    case ControlVoiceInMicVolume:
        MixerSetResult = MixSetADCHardware(pGDI, ControlId);
        break;

    case ControlLineoutAux1Volume:
    case ControlLineoutWaveoutVolume:
        MixerSetResult = MixSetVolume(pGDI, ControlId);
        break;

    case ControlLineoutVolume:
        MixerSetResult = MixSetMasterVolume(pGDI, ControlId);
        SoundNotifySynth(pGDI);
        break;

    case ControlLineoutMute:
        MixerSetResult = MixSetMute(pGDI, ControlId);
        SoundNotifySynth(pGDI);
        break;

    case ControlLineoutAux1Mute:
    case ControlLineoutWaveoutMute:
        MixerSetResult = MixSetMute(pGDI, ControlId);
        break;

    case ControlLineoutMidioutVolume:
    case ControlLineoutMidioutMute:
        MixerSetResult = TRUE;
        SoundNotifySynth(pGDI);
        break;

    case ControlLineoutWaveoutPeak:
    case ControlWaveInAux1Peak:
    case ControlWaveInMicPeak:
    case ControlVoiceInAux1Peak:
    case ControlVoiceInMicPeak:
        MixerSetResult = FALSE;
        break;

    default:
        MixerSetResult = FALSE;
        break;
    }

    if (MixerSetResult) {

        SoundMixerChangedItem(MixerInfo,
                              &pGDI->LocalMixerData.ControlNotification[
                                  ControlInfo->SetIndex]);

        return STATUS_SUCCESS;
    } else {
        return STATUS_INVALID_PARAMETER;
    }
}
void CDAVCLanSettingsImpl::requestHomeSettingStatusNotification_0288(const DAVCLanSettings::HomeSettingStatusNotificationType tHomeSettingStatusNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestHomeSettingStatusNotification_0288( tHomeSettingStatusNotification );
}
Пример #8
0
NTSTATUS
NICHandleSendInterrupt(
    __in  PFDO_DATA  FdoData
    )
/*++
Routine Description:

    Interrupt handler for sending processing. Re-claim the send resources,
    complete sends and get more to send from the send wait queue.

    Assumption: Send spinlock has been acquired

Arguments:

    FdoData     Pointer to our FdoData

Return Value:

    NTSTATUS code

--*/
{
    NTSTATUS        status = STATUS_SUCCESS;
    PMP_TCB         pMpTcb;

#if DBG
    LONG            i;
#endif

    DebugPrint(TRACE, DBG_WRITE, "---> NICHandleSendInterrupt\n");

    //
    // Any packets being sent? Any packet waiting in the send queue?
    //
    if (FdoData->nBusySend == 0 &&
        IsListEmpty(&FdoData->SendQueueHead))
    {
        ASSERT(FdoData->CurrSendHead == FdoData->CurrSendTail);
        DebugPrint(TRACE, DBG_WRITE, "<--- NICHandleSendInterrupt\n");
        return status;
    }

    //
    // Check the first TCB on the send list
    //
    while (FdoData->nBusySend > 0)
    {

#if DBG
        pMpTcb = FdoData->CurrSendHead;
        for (i = 0; i < FdoData->nBusySend; i++)
        {
            pMpTcb = pMpTcb->Next;
        }

        if (pMpTcb != FdoData->CurrSendTail)
        {
            DebugPrint(ERROR, DBG_WRITE, "nBusySend= %d\n", FdoData->nBusySend);
            DebugPrint(ERROR, DBG_WRITE, "CurrSendhead= %p\n", FdoData->CurrSendHead);
            DebugPrint(ERROR, DBG_WRITE, "CurrSendTail= %p\n", FdoData->CurrSendTail);
            ASSERT(FALSE);
        }
#endif

        pMpTcb = FdoData->CurrSendHead;

        //
        // Is this TCB completed?
        //
        if (pMpTcb->HwTcb->TxCbHeader.CbStatus & CB_STATUS_COMPLETE)
        {
            //
            // Check if this is a multicast hw workaround packet
            //
            if ((pMpTcb->HwTcb->TxCbHeader.CbCommand & CB_CMD_MASK) != CB_MULTICAST)
            {
                MP_FREE_SEND_PACKET(FdoData, pMpTcb, STATUS_SUCCESS);

            } else {
                ASSERTMSG("Not sure what to do", FALSE);
            }
        }
        else
        {
            break;
        }
    }

    //
    // If we queued any transmits because we didn't have any TCBs earlier,
    // dequeue and send those packets now, as long as we have free TCBs.
    //
    while (!IsListEmpty(&FdoData->SendQueueHead) &&
        MP_TCB_RESOURCES_AVAIABLE(FdoData))
    {
        PIRP irp;
        PLIST_ENTRY pEntry;

        pEntry = RemoveHeadList(&FdoData->SendQueueHead);

        ASSERT(pEntry);

        FdoData->nWaitSend--;

        irp = CONTAINING_RECORD(pEntry, IRP, Tail.Overlay.ListEntry);
        DebugPrint(LOUD, DBG_WRITE, "NICHandleSendInterrupt - send a queued packet\n");

        NICWritePacket(FdoData, irp, TRUE);
    }

    DebugPrint(TRACE, DBG_WRITE, "<--- NICHandleSendInterrupt\n");
    return status;
}
String SensorFileSysWalker::getFileOnly( String file ) {
	int index = file.findLast( '\\' );
	ASSERTMSG( index >= 0 , "Unexpected: " + file );

	return( file.getMid( index + 1 ) );
}
Пример #10
0
NTSTATUS SoundReportResourceUsage(
    IN PDEVICE_OBJECT DeviceObject,
    IN INTERFACE_TYPE BusType,
    IN ULONG BusNumber,
    IN PULONG InterruptNumber OPTIONAL,
    IN KINTERRUPT_MODE InterruptMode,
    IN BOOLEAN InterruptShareDisposition,
    IN PULONG DmaChannel OPTIONAL,
    IN PULONG FirstIoPort OPTIONAL,
    IN ULONG IoPortLength
)
/*++

Routine Description :

    Calls IoReportResourceUsage for the device and resources
    passed in.  NOTE that this supercedes previous resources
    declared for this device.

    It is assumed that all resources owned by the device cannot
    be shared, except for level-sensitive interrupts which can be
    shared.

Arguments :

    DeviceObject - The device which 'owns' the resources
                   This can also be a pointer to a driver object
    BusType      - The type of bus on which the device lives
    BusNumber    - The bus number (of type BusType) where the device is
    InterruptNumber - The interrupt the devices uses (if any)
    DmaChannel   - The DMA channel the device uses
    FirstIoPort  - The start Io port for the device
    IoPortLength - The number of bytes of IO space the device uses
                   (starting at FirstIoPort)

Return Value :

    STATUS_SUCCESS if no problems
    The return from IoReportResourceUsage if this fails
    STATUS_DEVICE_CONFIGURATION_ERROR is IoReportResourceUsage reports
        a conflict

--*/

{
    NTSTATUS Status;

    //
    // Our resource list to report back to the system
    //

    /*

     Compiler rejects this

    UCHAR ResBuffer[FIELD_OFFSET(
                       CM_RESOURCE_LIST,
                       List[0].PartialResourceList.PartialDescriptors[3].Type)];

     */

    UCHAR ResBuffer[3 * sizeof(CM_RESOURCE_LIST)];

    BOOLEAN ResourceConflict;

    PCM_RESOURCE_LIST ResourceList;
    PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor;

    ResourceList = (PCM_RESOURCE_LIST)ResBuffer;
    Descriptor = ResourceList->List[0].PartialResourceList.PartialDescriptors;
    ResourceConflict = FALSE;

    //
    // Zero out any unused data
    //

    RtlZeroMemory(ResBuffer, sizeof(ResBuffer));

    //
    // We assume there's only 1 bus so we only need one list.
    // Fill in the bus description
    //

    ResourceList->Count = 1;
    ResourceList->List[0].InterfaceType = BusType;
    ResourceList->List[0].BusNumber = BusNumber;

    //
    // If the device is using IO Ports add this to the list
    //

    if (ARGUMENT_PRESENT(FirstIoPort)) {
        PHYSICAL_ADDRESS PortAddress;
        ULONG MemType;
        PHYSICAL_ADDRESS MappedAddress;

        PortAddress.LowPart = *FirstIoPort;
        PortAddress.HighPart = 0;
        MemType = 1;

        HalTranslateBusAddress(
                    BusType,
                    BusNumber,
                    PortAddress,
                    &MemType,
                    &MappedAddress);


        ResourceList->List[0].PartialResourceList.Count++;

        Descriptor->Type = CmResourceTypePort;

        Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;

        Descriptor->u.Port.Start.LowPart = *FirstIoPort;

        Descriptor->u.Port.Length = IoPortLength;

        Descriptor->Flags = MemType == 0 ? CM_RESOURCE_PORT_MEMORY :
                                           CM_RESOURCE_PORT_IO;

        //
        // Move on to next resource descriptor entry
        //

        Descriptor++;
    }

    //
    // Add interrupt information (if any) to the list
    //

    if (ARGUMENT_PRESENT(InterruptNumber)) {

        KAFFINITY Affinity;
        KIRQL InterruptRequestLevel;
        ULONG InterruptVector;

        //
        // Get the processor affinity and vector
        //


        InterruptVector = HalGetInterruptVector(BusType,
                                                BusNumber,
                                                *InterruptNumber,
                                                *InterruptNumber,
                                                &InterruptRequestLevel,
                                                &Affinity);



        ResourceList->List[0].PartialResourceList.Count++;

        Descriptor->Type = CmResourceTypeInterrupt;

        Descriptor->ShareDisposition = (UCHAR)(InterruptShareDisposition ?
                                               CmResourceShareShared :
                                               CmResourceShareDeviceExclusive);

        Descriptor->Flags =
           InterruptMode == Latched ? CM_RESOURCE_INTERRUPT_LATCHED :
                                      CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;

        Descriptor->u.Interrupt.Level = *InterruptNumber;

        Descriptor->u.Interrupt.Vector = InterruptVector;

        Descriptor->u.Interrupt.Affinity = (ULONG)Affinity;

        //
        // Move on to next resource descriptor entry
        //

        Descriptor++;
    }

    //
    // Add DMA description if any
    //

    if (ARGUMENT_PRESENT(DmaChannel)) {
        ResourceList->List[0].PartialResourceList.Count++;

        Descriptor->Type = CmResourceTypeDma;

        Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;

        Descriptor->u.Dma.Channel = *DmaChannel;

        Descriptor->u.Dma.Port = 0;  // ???

        //
        // Move on to next resource descriptor entry
        //

        Descriptor++;
    }

    //
    // Report our resource usage and detect conflicts
    //

    switch (DeviceObject->Type) {
    case IO_TYPE_DEVICE:
        Status = IoReportResourceUsage(NULL,
                                       DeviceObject->DriverObject,
                                       NULL,
                                       0,
                                       DeviceObject,
                                       ResourceList,
                                       (PUCHAR)Descriptor - (PUCHAR)ResourceList,
                                       FALSE,
                                       &ResourceConflict);
        break;
    case IO_TYPE_DRIVER:
        Status = IoReportResourceUsage(NULL,
                                       (PDRIVER_OBJECT)DeviceObject,
                                       ResourceList,
                                       (PUCHAR)Descriptor - (PUCHAR)ResourceList,
                                       NULL,
                                       NULL,
                                       0,
                                       FALSE,
                                       &ResourceConflict);
        break;

    default:
        ASSERTMSG("SoundReportResourceUsage - invalid object", FALSE);
    }

    if (ResourceConflict) {
        dprintf1(("Resource conflict reported"));
        Status = STATUS_DEVICE_CONFIGURATION_ERROR;
    }

    return Status;
}
Пример #11
0
NTSTATUS
NTAPI
SmpExecuteImage(IN PUNICODE_STRING FileName,
                IN PUNICODE_STRING Directory,
                IN PUNICODE_STRING CommandLine,
                IN ULONG MuSessionId,
                IN ULONG Flags,
                IN PRTL_USER_PROCESS_INFORMATION ProcessInformation)
{
    PRTL_USER_PROCESS_INFORMATION ProcessInfo;
    NTSTATUS Status;
    RTL_USER_PROCESS_INFORMATION LocalProcessInfo;
    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;

    /* Use the input process information if we have it, otherwise use local */
    ProcessInfo = ProcessInformation;
    if (!ProcessInfo) ProcessInfo = &LocalProcessInfo;

    /* Create parameters for the target process */
    Status = RtlCreateProcessParameters(&ProcessParameters,
                                        FileName,
                                        SmpDefaultLibPath.Length ?
                                        &SmpDefaultLibPath : NULL,
                                        Directory,
                                        CommandLine,
                                        SmpDefaultEnvironment,
                                        NULL,
                                        NULL,
                                        NULL,
                                        0);
    if (!NT_SUCCESS(Status))
    {
        /* This is a pretty bad failure. ASSERT on checked builds and exit */
        ASSERTMSG("RtlCreateProcessParameters", NT_SUCCESS(Status));
        DPRINT1("SMSS: RtlCreateProcessParameters failed for %wZ - Status == %lx\n",
                FileName, Status);
        return Status;
    }

    /* Set the size field as required */
    ProcessInfo->Size = sizeof(RTL_USER_PROCESS_INFORMATION);

    /* Check if the debug flag was requested */
    if (Flags & SMP_DEBUG_FLAG)
    {
        /* Write it in the process parameters */
        ProcessParameters->DebugFlags = 1;
    }
    else
    {
        /* Otherwise inherit the flag that was passed to SMSS itself */
        ProcessParameters->DebugFlags = SmpDebug;
    }

    /* Subsystems get the first 1MB of memory reserved for DOS/IVT purposes */
    if (Flags & SMP_SUBSYSTEM_FLAG)
    {
        ProcessParameters->Flags |= RTL_USER_PROCESS_PARAMETERS_RESERVE_1MB;
    }

    /* And always force NX for anything that SMSS launches */
    ProcessParameters->Flags |= RTL_USER_PROCESS_PARAMETERS_NX;

    /* Now create the process */
    Status = RtlCreateUserProcess(FileName,
                                  OBJ_CASE_INSENSITIVE,
                                  ProcessParameters,
                                  NULL,
                                  NULL,
                                  NULL,
                                  FALSE,
                                  NULL,
                                  NULL,
                                  ProcessInfo);
    RtlDestroyProcessParameters(ProcessParameters);
    if (!NT_SUCCESS(Status))
    {
        /* If we couldn't create it, fail back to the caller */
        DPRINT1("SMSS: Failed load of %wZ - Status  == %lx\n",
                FileName, Status);
        return Status;
    }

    /* Associate a session with this process */
    Status = SmpSetProcessMuSessionId(ProcessInfo->ProcessHandle, MuSessionId);

    /* If the application is deferred (suspended), there's nothing to do */
    if (Flags & SMP_DEFERRED_FLAG) return Status;

    /* Otherwise, get ready to start it, but make sure it's a native app */
    if (ProcessInfo->ImageInformation.SubSystemType == IMAGE_SUBSYSTEM_NATIVE)
    {
        /* Resume it */
        NtResumeThread(ProcessInfo->ThreadHandle, NULL);
        if (!(Flags & SMP_ASYNC_FLAG))
        {
            /* Block on it unless Async was requested */
            NtWaitForSingleObject(ProcessInfo->ThreadHandle, FALSE, NULL);
        }

        /* It's up and running now, close our handles */
        NtClose(ProcessInfo->ThreadHandle);
        NtClose(ProcessInfo->ProcessHandle);
    }
    else
    {
        /* This image is invalid, so kill it, close our handles, and fail */
        Status = STATUS_INVALID_IMAGE_FORMAT;
        NtTerminateProcess(ProcessInfo->ProcessHandle, Status);
        NtWaitForSingleObject(ProcessInfo->ThreadHandle, 0, 0);
        NtClose(ProcessInfo->ThreadHandle);
        NtClose(ProcessInfo->ProcessHandle);
        DPRINT1("SMSS: Not an NT image - %wZ\n", FileName);
    }

    /* Return the outcome of the process create */
    return Status;
}
Пример #12
0
BOOL CTileManager::CollisonCheck(VECTOR3* pStart,VECTOR3* pEnd,VECTOR3* pRtCollisonPos,CObject* pObj)
{	
	if( pStart->x >= 51200 || pStart->x < 0 ||
		pStart->z >= 51200 || pStart->z < 0 )
	{
		ASSERTMSG(0,"À̵¿¿µ¿ªÀ» ¹þ¾î³µ½À´Ï´Ù.");
		pRtCollisonPos->x = 25000;
		pRtCollisonPos->z = 25000;
		return TRUE;
	}

	int x0 = int(pStart->x / fTILE_WIDTH);
	int y0 = int(pStart->z / fTILE_HEIGHT);
	int x1 = int(pEnd->x / fTILE_WIDTH);
	int y1 = int(pEnd->z / fTILE_HEIGHT);
	
	int dx = x1-x0,dy = y1-y0;
	int sx,sy;
	if(dx >= 0)
	{
		sx = 1;
	}
	else
	{
		sx = -1;
		dx *= -1;
	}
	if(dy >= 0)
	{
		sy = 1;
	}
	else
	{
		sy = -1;
		dy *= -1;
	}
	
	int ax = 2*dx,ay = 2*dy;

	int x = x0, y = y0;
	int lastx = x, lasty = y;
	
	BOOL bFirst = TRUE;
	if(dx == 0 && dy == 0)
	{
		//bFirst = FALSE;
		return FALSE;	//CSW
	}
	
	if(dx >= dy)
	{
		for(int desc = ay - dx; ;x += sx,desc += ay)
		{
			if(bFirst == TRUE)
			{
				bFirst = FALSE;
				continue;
			}

			CTile *pTile = GetTile((DWORD)x, (DWORD)y);
			
#ifdef _DEBUG
			if(pTile == NULL)
			{
				//LOGFILE("TILENOTFOUND\t%s",OBJECTLOG(pObj));
				//LOGFILE("StartPos\t%4.2f\t%4.2f\t\tEndPos\t%4.2f\t%4.2f",
				//	pStart->x,pStart->z,pEnd->x,pEnd->z);
				ASSERTMSG(0,"ÀÌ ¿¡·¯ ¸Þ¼¼Áö º¸½Ã¸é À±È£ÇÑÅ× ²À! ¿¬¶ôÇØÁÖ¼¼¿ä");
				break;
			}			
#endif
			if(pTile == NULL || pTile->IsCollisonTile())
			{
				pRtCollisonPos->x = (float)(lastx*fTILE_WIDTH);
				pRtCollisonPos->y = 0;
				pRtCollisonPos->z = (float)(lasty*fTILE_HEIGHT);
				return TRUE;
			}

			if(x == x1)
				break;

			lastx = x;
			lasty = y;

			if(desc > 0)
			{
				y += sy;
				desc -= ax;
			}
		}
	}
	else
	{
		for(int desc = ax - dy; ;y += sy,desc += ax)
		{
			if(bFirst == TRUE)
			{
				bFirst = FALSE;
				continue;
			}

			CTile *pTile = GetTile((DWORD)x, (DWORD)y);
			
#ifdef _DEBUG
			if(pTile == NULL)
			{
				//LOGFILE("TILENOTFOUND\t%s",OBJECTLOG(pObj));
				//LOGFILE("StartPos\t%4.2f\t%4.2f\t\tEndPos\t%4.2f\t%4.2f",
				//	pStart->x,pStart->z,pEnd->x,pEnd->z);
				ASSERTMSG(0,"ÀÌ ¿¡·¯ ¸Þ¼¼Áö º¸½Ã¸é À±È£ÇÑÅ× ²À! ¿¬¶ôÇØÁÖ¼¼¿ä");
				break;
			}			
#endif
			if(pTile == NULL || pTile->IsCollisonTile())
			{
				pRtCollisonPos->x = (float)(lastx*fTILE_WIDTH);
				pRtCollisonPos->y = 0;
				pRtCollisonPos->z = (float)(lasty*fTILE_HEIGHT);
				return TRUE;
			}

			if(y == y1)
				break;
			
			lastx = x;
			lasty = y;

			if(desc > 0)
			{
				x += sx;
				desc -= ay;
			}
		}
	}
	return FALSE;
}
Пример #13
0
BOOL CTileManager::NonCollisionLine( VECTOR3* pStart, VECTOR3* pEnd, VECTOR3* pRtNonCollisonPos, MAPTYPE MapNum, CObject* pObj )
{
	int x1 = int(pStart->x / TILECOLLISON_DETAIL);
	int y1 = int(pStart->z / TILECOLLISON_DETAIL);
	int x2 = int(pEnd->x / TILECOLLISON_DETAIL);
	int y2 = int(pEnd->z / TILECOLLISON_DETAIL);

	int dx = x1 - x2;
	int dy = y1 - y2;
	
	int absDX = abs(dx);
	int absDY = abs(dy);
	int MaxDelta = max(absDX, absDY);
	
	int CellX = x1;
	int CellY = y1;

	CTile *pCurTile = GetTile((DWORD)CellX, (DWORD)CellY);
	if(pCurTile == NULL)
	{
		if(pRtNonCollisonPos)
		{
			pRtNonCollisonPos->x = CellX * TILECOLLISON_DETAIL;
			pRtNonCollisonPos->y = 0;
			pRtNonCollisonPos->z = CellY * TILECOLLISON_DETAIL;
		}

		char temp[256] = {0,};
		sprintf(temp, "%d %d %s", CellX, CellY, pObj->GetObjectName() );
		ASSERTMSG(0,temp);

		return FALSE;
	}
	if(FALSE == pCurTile->IsCollisonTile())	//현재 위치가 충돌 타일이 아니면 이 함수의 역할과 무관
	{
		if(pRtNonCollisonPos)
		{
			pRtNonCollisonPos->x = CellX * TILECOLLISON_DETAIL;
			pRtNonCollisonPos->y = 0;
			pRtNonCollisonPos->z = CellY * TILECOLLISON_DETAIL;
		}

		return FALSE;
	}

	int x = 0;
	int y = 0;

	int signDX = -sign(dx);
	int signDY = -sign(dy);
	
	int PrevCellX = 0;
	int PrevCellY = 0;

#define THROUGH_PERMIT_TILE_INDEX 2

	for( int i = 0 ; i <= MaxDelta ; ++i )
	{
		if( i > THROUGH_PERMIT_TILE_INDEX )
		{
			if(pRtNonCollisonPos)
			{
				pRtNonCollisonPos->x = CellX*TILECOLLISON_DETAIL;
				pRtNonCollisonPos->y = 0;
				pRtNonCollisonPos->z = CellY*TILECOLLISON_DETAIL;
			}

			return FALSE;
		}

		PrevCellX = CellX;
		PrevCellY = CellY;

		x += absDX;  
		y += absDY;
		
		if( x > MaxDelta)  
		{  
			x -= MaxDelta;
			CellX += signDX;
		}
		
		if( y > MaxDelta ) 
		{  
			y -= MaxDelta;  
			CellY += signDY;  
		}
		CTile *pTile = GetTile((DWORD)CellX, (DWORD)CellY);
		if(pTile == NULL)
		{
			if(pRtNonCollisonPos)
			{
				pRtNonCollisonPos->x = PrevCellX*TILECOLLISON_DETAIL;
				pRtNonCollisonPos->y = 0;
				pRtNonCollisonPos->z = PrevCellY*TILECOLLISON_DETAIL;
			}
			
			char temp[256];
			sprintf(temp,"%d %d %s",CellX,CellY,pObj->GetObjectName());
			ASSERTMSG(0,temp);
			
			return FALSE;
		}
		if( FALSE == pTile->IsCollisonTile() )
		{
			if(pRtNonCollisonPos)
			{
				pRtNonCollisonPos->x = CellX*TILECOLLISON_DETAIL;
				pRtNonCollisonPos->y = 0;
				pRtNonCollisonPos->z = CellY*TILECOLLISON_DETAIL;
			}
			return TRUE;
		}
	}

	if(pRtNonCollisonPos)
	{
		pRtNonCollisonPos->x = x1*TILECOLLISON_DETAIL;
		pRtNonCollisonPos->y = 0;
		pRtNonCollisonPos->z = y1*TILECOLLISON_DETAIL;
	}
	return FALSE;
}
Пример #14
0
BOOL CTileManager::CollisionLine(VECTOR3* pSrc,VECTOR3* pDest, VECTOR3 * pTarget, MAPTYPE MapNum,CObject* pObject)
{
	BOOL bEscape = FALSE;

	int x1 = int(pSrc->x / TILECOLLISON_DETAIL);
	int y1 = int(pSrc->z / TILECOLLISON_DETAIL);
	int x2 = int(pDest->x / TILECOLLISON_DETAIL);
	int y2 = int(pDest->z / TILECOLLISON_DETAIL);

	int dx = x2 - x1;
	int dy = y2 - y1;
	
	int absDX = abs(dx);
	int absDY = abs(dy);
	int MaxDelta = max(absDX, absDY);
	
	int CellX = x1;
	int CellY = y1;
	int x = 0;
	int y = 0;

	int signDX = sign(dx);
	int signDY = sign(dy);
	
	int PrevCellX = 0;
	int PrevCellY = 0;

	for( int i = 0 ; i <= MaxDelta ; ++i )
	{
		PrevCellX = CellX;
		PrevCellY = CellY;

		x += absDX;  
		y += absDY;
		
		if( x > MaxDelta)  
		{  
			x -= MaxDelta;
			CellX += signDX;
		}
		
		if( y > MaxDelta ) 
		{  
			y -= MaxDelta;  
			CellY += signDY;  
		}
		CTile *pTile = GetTile((DWORD)CellX, (DWORD)CellY);
		if(pTile == NULL)
		{
			if(pTarget)
			{
				pTarget->x = PrevCellX*TILECOLLISON_DETAIL;
				pTarget->y = 0;
				pTarget->z = PrevCellY*TILECOLLISON_DETAIL;
			}
			
			char temp[256];
			sprintf(temp,"%d %d %s",CellX,CellY,pObject->GetObjectName());
			ASSERTMSG(0,temp);
			
			return TRUE;
		}
		if(pTile->IsCollisonTile())
		{
			/// 현재위치가 비정상적인 위치라면 탈출을 시도한다.
			if( i == 0 )
			{
				bEscape = TRUE;
				continue;
			}
			/// 탈출을 시도할때는 현재위치와 바로 앞 위치를 무시한다.
			if( bEscape && i < 2)
			{
				continue;
			}
			if(pTarget)
			{
				pTarget->x = PrevCellX*TILECOLLISON_DETAIL;
				pTarget->y = 0;
				pTarget->z = PrevCellY*TILECOLLISON_DETAIL;
				/*
				CTile *p2Tile = GetTile((DWORD)PrevCellX, (DWORD)PrevCellY);
								if(p2Tile->IsCollisonTile())
								{
									int a = 3;
								}*/
				
			}
			return TRUE;
		}
	}

	if(pTarget)
	{
		pTarget->x = x2*TILECOLLISON_DETAIL;
		pTarget->y = 0;
		pTarget->z = y2*TILECOLLISON_DETAIL;
	}
	return FALSE;
}
Пример #15
0
NTSTATUS
SoundMixerInit(
    PLOCAL_DEVICE_INFO pLDI,
    PMIXER_CONTROL_DATA_ITEM SavedControlData,
    BOOLEAN MixerSettingsFound
)
{
    int i, SetIndex;
    PLOCAL_MIXER_DATA LocalMixerData;
    PGLOBAL_DEVICE_INFO pGDI;
    PMIXER_INFO MixerInfo;

    pGDI = pLDI->pGlobalInfo;
    MixerInfo = &pGDI->MixerInfo;

    /*
    **  Init the generic mixer stuff first so we can use it
    */

    SoundInitMixerInfo(&pGDI->MixerInfo,
                       HwGetLineFlags,
                       HwGetControl,
                       HwGetCombinedControl,
                       HwSetControl);

    /*
    **  Set this device up with its mixer data
    */
    pLDI->DeviceType         = MIXER_DEVICE;
    pLDI->DeviceSpecificData = (PVOID)MixerInfo;

    /*
    ** Make sure everyone can find the mixer device
    */

    {
        PDEVICE_OBJECT pDO;
        PLOCAL_DEVICE_INFO pLDIDev;

        for (pDO = pGDI->DeviceObject[WaveInDevice]->DriverObject->DeviceObject;
             pDO != NULL;
             pDO = pDO->NextDevice) {


            pLDIDev = (PLOCAL_DEVICE_INFO)pDO->DeviceExtension;

            /*
            **  For multiple cards the following test may fail
            */

            if (pLDIDev->pGlobalInfo == pGDI ||
                pDO == pGDI->Synth.DeviceObject) {
                pLDIDev->MixerDevice = pLDI;
            }
        }
    }

    LocalMixerData = &pGDI->LocalMixerData;

    /*
    **  Create control info
    */

    for (i = 0, SetIndex = 0; i < MAXCONTROLS ; i++) {

        /*
        **  Read limits
        */

        if ((MixerControlInit[i].dwControlType & MIXERCONTROL_CT_UNITS_MASK) ==
                MIXERCONTROL_CT_UNITS_SIGNED) {

            pGDI->LocalMixerData.ControlInfo[i].Signed = TRUE;
            pGDI->LocalMixerData.ControlInfo[i].Range.Min.s =
                (SHORT)MixerControlInit[i].Bounds.lMinimum;
            pGDI->LocalMixerData.ControlInfo[i].Range.Max.s =
                (SHORT)MixerControlInit[i].Bounds.lMaximum;
        } else {

            if ((MixerControlInit[i].dwControlType & MIXERCONTROL_CT_UNITS_MASK) ==
                     MIXERCONTROL_CT_UNITS_BOOLEAN) {
                pGDI->LocalMixerData.ControlInfo[i].Boolean = TRUE;
            }
            pGDI->LocalMixerData.ControlInfo[i].Range.Min.u =
                (USHORT)MixerControlInit[i].Bounds.dwMinimum;
            pGDI->LocalMixerData.ControlInfo[i].Range.Max.u =
                (USHORT)MixerControlInit[i].Bounds.dwMaximum;
        }

        /*
        **  Remember if it's a mux
        */

        if (MixerControlInit[i].dwControlType == MIXERCONTROL_CONTROLTYPE_MUX) {
            pGDI->LocalMixerData.ControlInfo[i].Mux = TRUE;
        }

        /*
        **  Only meters are not settable here
        */

        if ((MixerControlInit[i].dwControlType & MIXERCONTROL_CT_CLASS_MASK) !=
            MIXERCONTROL_CT_CLASS_METER)
        {
            pGDI->LocalMixerData.ControlInfo[i].SetIndex = SetIndex;
            SoundInitDataItem(MixerInfo,
                              &pGDI->LocalMixerData.ControlNotification[SetIndex],
                              (USHORT)MM_MIXM_CONTROL_CHANGE,
                              (USHORT)i);
            if (MixerSettingsFound) {

                    /*
                    **  What if it's invalid?
                    */

                pGDI->LocalMixerData.ControlInfo[i].Data =
                    SavedControlData[SetIndex];
            } else {
                /*
                **  For us it's either Mute, a volume or a Mux.
                **
                **    Muxes are assumed to be set to MUXINPUT_MIC as default
                **    Only one mute is set
                **
                **    Volumes are set to a fixed value
                **
                **    Nothing is muted
                */

                switch (i) {
                case ControlLineoutVolume:
                case ControlLineoutAux1Volume:
                case ControlLineoutWaveoutVolume:
                case ControlLineoutMidioutVolume:
                case ControlWaveInAux1Volume:
                case ControlWaveInMicVolume:
                case ControlVoiceInAux1Volume:
                case ControlVoiceInMicVolume:

                    /*
                    **  Half volume
                    */

                    pGDI->LocalMixerData.ControlInfo[i].Data.v[0].u = 32767;
                    pGDI->LocalMixerData.ControlInfo[i].Data.v[1].u = 32767;
                    break;

                case ControlWaveInMux:
                case ControlVoiceInMux:

                    /*
                    **  Microphone input
                    */

                    pGDI->LocalMixerData.ControlInfo[i].Data.v[0].u = MUXINPUT_MIC;
                    break;
                }
            }
            SetIndex++;
        } else {
            pGDI->LocalMixerData.ControlInfo[i].SetIndex = MIXER_SET_INDEX_INVALID;
        }
    }

    ASSERTMSG("MAXSETTABLECONTROLS wrong!", SetIndex == MAXSETTABLECONTROLS);

    /*
    **  Create line info
    */

    for (i = 0; i < MAXLINES; i++) {
        SoundInitDataItem(MixerInfo,
                          &pGDI->LocalMixerData.LineNotification[i],
                          (USHORT)MM_MIXM_LINE_CHANGE,
                          (USHORT)i);
    }

    /*
    **  Set up line notifications and volume control ids for non-mixer devices
    */

    SoundSetLineNotify(
        (PLOCAL_DEVICE_INFO)pGDI->DeviceObject[WaveInDevice]->DeviceExtension,
        SoundWaveinLineChanged);
    SoundSetLineNotify(
        (PLOCAL_DEVICE_INFO)pGDI->DeviceObject[WaveOutDevice]->DeviceExtension,
        SoundWaveoutLineChanged);


    if (pGDI->Synth.DeviceObject) {
        SoundSetLineNotify(
            (PLOCAL_DEVICE_INFO)pGDI->Synth.DeviceObject->DeviceExtension,
            SoundSynthLineChanged);
    }

    SoundSetVolumeControlId(
        (PLOCAL_DEVICE_INFO)pGDI->DeviceObject[WaveOutDevice]->DeviceExtension,
        ControlLineoutWaveoutVolume);

    SoundSetVolumeControlId(
        (PLOCAL_DEVICE_INFO)pGDI->DeviceObject[LineInDevice]->DeviceExtension,
        ControlLineoutAux1Volume);

    /*
    **  Set the volume levels - this only affects the output for this card's
    **  initial settings (ie wave in not active).
    */

    MixSetMasterVolume(pGDI, 0);

    return STATUS_SUCCESS;
}
Пример #16
0
VOID NTAPI
ConDrvDeleteConsole(IN PCONSOLE Console)
{
    DPRINT("ConDrvDeleteConsole(0x%p)\n", Console);

    /*
     * Forbid validation of any console by other threads
     * during the deletion of this console.
     */
    ConDrvLockConsoleListExclusive();

    /*
     * If the console is already being destroyed, i.e. not running
     * or finishing to be initialized, just return.
     */
    if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE) &&
        !ConDrvValidateConsoleUnsafe(Console, CONSOLE_INITIALIZING, TRUE))
    {
        /* Unlock the console list and return */
        ConDrvUnlockConsoleList();
        return;
    }

    /*
     * We are about to be destroyed. Signal it to other people
     * so that they can terminate what they are doing, and that
     * they cannot longer validate the console.
     */
    Console->State = CONSOLE_TERMINATING;

    /*
     * Allow other threads to finish their job: basically, unlock
     * all other calls to EnterCriticalSection(&Console->Lock); by
     * ConDrvValidateConsoleUnsafe functions so that they just see
     * that we are not in CONSOLE_RUNNING state anymore, or unlock
     * other concurrent calls to ConDrvDeleteConsole so that they
     * can see that we are in fact already deleting the console.
     */
    LeaveCriticalSection(&Console->Lock);
    ConDrvUnlockConsoleList();

    /* Deregister the terminal */
    DPRINT("Deregister terminal\n");
    ConDrvDetachTerminal(Console);
    DPRINT("Terminal deregistered\n");

    /***
     * Check that the console is in terminating state before continuing
     * (the cleanup code must not change the state of the console...
     * ...unless to cancel console deletion ?).
     ***/

    ConDrvLockConsoleListExclusive();

    if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_TERMINATING, TRUE))
    {
        ConDrvUnlockConsoleList();
        return;
    }

    /* We are now in destruction */
    Console->State = CONSOLE_IN_DESTRUCTION;

    /* We really delete the console. Reset the count to be sure. */
    Console->ReferenceCount = 0;

    /* Remove the console from the list */
    RemoveConsole(Console);

    /* Delete the last screen buffer */
    ConDrvDeleteScreenBuffer(Console->ActiveBuffer);
    Console->ActiveBuffer = NULL;
    if (!IsListEmpty(&Console->BufferList))
    {
        /***ConDrvUnlockConsoleList();***/
        ASSERTMSG("BUGBUGBUG!! screen buffer list not empty\n", FALSE);
    }

    /* Deinitialize the input buffer */
    ConDrvDeinitInputBuffer(Console);

    if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent);

    DPRINT("ConDrvDeleteConsole - Unlocking\n");
    LeaveCriticalSection(&Console->Lock);
    DPRINT("ConDrvDeleteConsole - Destroying lock\n");
    DeleteCriticalSection(&Console->Lock);
    DPRINT("ConDrvDeleteConsole - Lock destroyed ; freeing console\n");

    ConsoleFreeHeap(Console);
    DPRINT("ConDrvDeleteConsole - Console destroyed\n");

    /* Unlock the console list and return */
    ConDrvUnlockConsoleList();
}
Пример #17
0
NTSTATUS
HwGetControl(
    PMIXER_INFO MixerInfo,
    ULONG ControlId,
    ULONG DataLength,
    PVOID ControlData
)
{
    PLOCAL_MIXER_CONTROL_INFO ControlInfo;
    PGLOBAL_DEVICE_INFO pGDI;
    LONG Values[2];

    /*
    **  Validate control ID
    */

    if (ControlId > MAXCONTROLS) {
        return STATUS_INVALID_PARAMETER;
    }

    /*
    **  Establish pointers to our structures
    */

    pGDI = CONTAINING_RECORD(MixerInfo, GLOBAL_DEVICE_INFO, MixerInfo);
    ControlInfo = &pGDI->LocalMixerData.ControlInfo[ControlId];

    /*
    **  Validate data length and values
    */

    switch (DataLength) {
        case sizeof(LONG):
            break;

        case sizeof(LONG) * 2:
            break;

        default:
            return STATUS_BUFFER_TOO_SMALL;
    }

    /*
    **  Pull out the data
    */

    if (ControlInfo->SetIndex == MIXER_SET_INDEX_INVALID) {
        /*
        **  Must be a peak meter - see if it's valid to query it
        */

        PWAVE_INFO WaveInfo;
        BOOLEAN ComputePeak;

        ComputePeak = FALSE;

        /*
        **  Set defaults
        */

        Values[0] = 0;
        Values[1] = 0;

        WaveInfo = &pGDI->WaveInfo;

        switch (ControlId) {
            case ControlLineoutWaveoutPeak:
                if (pGDI->DeviceInUse == WaveOutDevice) {
                    ComputePeak = TRUE;
                }
                break;

            case ControlWaveInAux1Peak:
            case ControlWaveInMicPeak:
                if (pGDI->DeviceInUse != WaveInDevice) {
                    break;
                }

                if (WaveInfo->LowPriorityHandle != NULL &&
                    !WaveInfo->LowPrioritySaved) {
                    break;
                }

                if (pGDI->LocalMixerData.ControlInfo[ControlWaveInMux].Data.v[0].u ==
                    MUXINPUT_MIC) {

                    if (ControlId == ControlWaveInAux1Peak) {
                        break;
                    }
                } else {
                    if (ControlId == ControlWaveInMicPeak) {
                        break;
                    }
                }
                ComputePeak = TRUE;
                break;

            case ControlVoiceInAux1Peak:
            case ControlVoiceInMicPeak:

                if (pGDI->DeviceInUse != WaveInDevice) {
                    break;
                }
                if (WaveInfo->LowPriorityHandle == NULL ||
                    WaveInfo->LowPrioritySaved) {
                    break;
                }

                if (pGDI->LocalMixerData.ControlInfo[ControlVoiceInMux].Data.v[0].u ==
                    MUXINPUT_MIC) {

                    if (ControlId == ControlVoiceInAux1Peak) {
                        break;
                    }
                } else {
                    if (ControlId == ControlVoiceInMicPeak) {
                        break;
                    }
                }
                ComputePeak = TRUE;
                break;

            default:
                ASSERTMSG("Invalid control id", FALSE);
                break;
        }

        if (ComputePeak) {
            SoundPeakMeter(WaveInfo, Values);
        }

        /*
        **  Note that we should round these values to the min/max
        **  expected in the control but in this case these values
        **  are always within range
        */

    } else {
        ASSERTMSG("Set index out of range",
                  ControlInfo->SetIndex < MAXSETTABLECONTROLS);

        if (ControlInfo->Mux) {
            Values[ControlInfo->Data.v[0].s] = (LONG)ControlInfo->Range.Max.s;
            Values[1 - ControlInfo->Data.v[0].s] = (LONG)ControlInfo->Range.Min.s;
        } else {
            if (ControlInfo->Signed) {
                Values[0] = (LONG)ControlInfo->Data.v[0].s;
                Values[1] = (LONG)ControlInfo->Data.v[1].s;
            } else {
                Values[0] = (LONG)(ULONG)ControlInfo->Data.v[0].u;
                Values[1] = (LONG)(ULONG)ControlInfo->Data.v[1].u;
            }
        }
    }

    /*
    **  If only 1 channel was asked for then munge the data accordingly
    */

    if (DataLength == sizeof(LONG)) {
        switch (MixerControlInit[ControlId].dwControlType &
                MIXERCONTROL_CT_UNITS_MASK) {

        case MIXERCONTROL_CT_UNITS_BOOLEAN:
            Values[0] = Values[0] != 0 || Values[1] != 0;
            break ;

        case MIXERCONTROL_CT_UNITS_SIGNED:

            /*
            **  Assumes signed values...
            */

            if (absval(Values[1]) > absval(Values[0])) {
                Values[0] = Values[1];
            }

            break ;

        case MIXERCONTROL_CT_UNITS_UNSIGNED:
        case MIXERCONTROL_CT_UNITS_DECIBELS:
        case MIXERCONTROL_CT_UNITS_PERCENT:

            /*
            **  Assumes unsigned values...
            */

            if ((ULONG)Values[0] < (ULONG)Values[1]) {
                Values[0] = Values[1];
            }
            break ;
        }

        /*
        **  Copy the single value back
        */

    } else {
        ((PLONG)ControlData)[1] = Values[1];
    }

    *(PLONG)ControlData = Values[0];

    return STATUS_SUCCESS;
}
Пример #18
0
NTSTATUS
ExInitializeResource (
    IN PNTDDK_ERESOURCE Resource
    )

/*++

Routine Description:

    This routine initializes the input resource variable

Arguments:

    Resource - Supplies the resource variable being initialized

Return Value:

    Status of the operation.

--*/

{
    ULONG   i;

    ASSERTMSG("A resource cannot be in paged pool ", MmDeterminePoolType(Resource) == NonPagedPool);
    //
    //  Initialize the shared and exclusive waiting counters and semaphore.
    //  The counters indicate how many are waiting for access to the resource
    //  and the semaphores are used to wait on the resource.  Note that
    //  the semaphores can also indicate the number waiting for a resource
    //  however there is a race condition in the algorithm on the acquire
    //  side if count if not updated before the critical section is exited.
    //  So we need to have an outside counter.
    //

    Resource->NumberOfSharedWaiters    = 0;
    Resource->NumberOfExclusiveWaiters = 0;

    KeInitializeSemaphore ( &Resource->SharedWaiters, 0, MAXLONG );
    KeInitializeEvent     ( &Resource->ExclusiveWaiters, SynchronizationEvent, FALSE );
    KeInitializeSpinLock  ( &Resource->SpinLock );

    Resource->OwnerThreads = Resource->InitialOwnerThreads;
    Resource->OwnerCounts  = Resource->InitialOwnerCounts;

    Resource->TableSize    = INITIAL_TABLE_SIZE;
    Resource->ActiveCount  = 0;
    Resource->TableRover   = 1;
    Resource->Flag         = 0;

    for(i=0; i < INITIAL_TABLE_SIZE; i++) {
        Resource->OwnerThreads[i] = 0;
        Resource->OwnerCounts[i] = 0;
    }

    Resource->ContentionCount = 0;
    InitializeListHead( &Resource->SystemResourcesList );

#if defined(_X86_) && !FPO
    if (NtGlobalFlag & FLG_KERNEL_STACK_TRACE_DB) {
        Resource->CreatorBackTraceIndex = RtlLogStackBackTrace();
        }
    else {
        Resource->CreatorBackTraceIndex = 0;
        }
#endif // _X86_ && !FPO
    if (Resource >= (PNTDDK_ERESOURCE)MM_USER_PROBE_ADDRESS) {
        ExInterlockedInsertTailList (
                &ExpSystemResourcesList,
                &Resource->SystemResourcesList,
                &ExpResourceSpinLock );
    }

    return STATUS_SUCCESS;
}
Пример #19
0
NTSTATUS
PortIOEvtDevicePrepareHardware(
    _In_ WDFDEVICE  Device,    
    _In_ WDFCMRESLIST  ResourcesRaw,    
    _In_ WDFCMRESLIST  ResourcesTranslated    
    )
/*++

Routine Description:

    This event is called by the Framework when the device is started
    or restarted after a suspend operation.

Arguments:

    Device - Handle to a framework device object.

Return Value:

    NTSTATUS - Failures will result in the device stack being torn down.

--*/
{
    ULONG  i;
    PCM_PARTIAL_RESOURCE_DESCRIPTOR  desc;
    PCM_PARTIAL_RESOURCE_DESCRIPTOR  descTranslated;
    PDEVICE_CONTEXT deviceContext = NULL;
    NTSTATUS status = STATUS_SUCCESS;

    PAGED_CODE();
    
    if ((NULL == ResourcesRaw) || 
        (NULL == ResourcesTranslated)){
        return STATUS_DEVICE_CONFIGURATION_ERROR;        
    }
        
    deviceContext = PortIOGetDeviceContext(Device);
    
    for (i=0; i < WdfCmResourceListGetCount(ResourcesRaw); i++) {
        
        desc = WdfCmResourceListGetDescriptor(ResourcesRaw, i);
        descTranslated =  WdfCmResourceListGetDescriptor(ResourcesTranslated, i);
        
        switch(desc ->Type) {
        case CmResourceTypePort:

            switch(descTranslated -> Type) {
            case CmResourceTypePort:
                deviceContext -> PortWasMapped = FALSE;
                deviceContext -> PortBase = ULongToPtr(descTranslated->u.Port.Start.LowPart);
                deviceContext -> PortCount = descTranslated ->u.Port.Length;
                KdPrint(("Resource Translated Port: (%x) Length: (%d)\n",
                         descTranslated->u.Port.Start.LowPart,
                         descTranslated->u.Port.Length));                        
                break;
            case CmResourceTypeMemory:
                //
                // Map the memory
                //
                deviceContext-> PortBase = (PVOID)
                                    MmMapIoSpace(descTranslated->u.Memory.Start,
                                                 descTranslated->u.Memory.Length,
                                                 MmNonCached);
                deviceContext-> PortCount = descTranslated->u.Memory.Length;

                deviceContext-> PortWasMapped = TRUE;
                
                KdPrint(("Resource Translated Memory: (%x) Length: (%d)\n",
                         descTranslated->u.Memory.Start.LowPart,
                         descTranslated->u.Memory.Length));                        
                break;
            default:
                KdPrint(("Unhandled resource_type (0x%x)\n", descTranslated->Type));
                status = STATUS_UNSUCCESSFUL;
                ASSERTMSG("Unhandled resource_type in start request\n", FALSE);                        
            }
            break;

        case CmResourceTypeMemory:
            deviceContext-> PortBase = (PVOID)
                                    MmMapIoSpace (descTranslated->u.Memory.Start,
                                    descTranslated->u.Memory.Length,
                                    MmNonCached);
            deviceContext-> PortCount = descTranslated->u.Memory.Length;

            deviceContext-> PortWasMapped = TRUE;
                    
            KdPrint(("Resource Translated Memory: (%x) Length: (%d)\n",
                    descTranslated->u.Memory.Start.LowPart,
                    descTranslated->u.Memory.Length));                        
            
            break;
        case CmResourceTypeInterrupt:
        default:
        KdPrint(("Unhandled resource type (0x%x)\n", desc->Type));
        status = STATUS_UNSUCCESSFUL;
        break;
        }

    }

    return status;
}
Пример #20
0
BOOLEAN
ExAcquireResourceExclusive(
    IN PNTDDK_ERESOURCE Resource,
    IN BOOLEAN Wait
    )

/*++

Routine Description:

    The routine acquires the resource for exclusive access.  Upon return from
    the procedure the resource is acquired for exclusive access.

Arguments:

    Resource - Supplies the resource to acquire

    Wait - Indicates if the call is allowed to wait for the resource
        to become available for must return immediately

Return Value:

    BOOLEAN - TRUE if the resource is acquired and FALSE otherwise

--*/

{
    KIRQL OldIrql;
    ERESOURCE_THREAD  OurThread;

    ASSERTMSG("Routine cannot be called at DPC ", !KeIsExecutingDpc() );

    ASSERT((Resource->Flag & ResourceNeverExclusive) == 0);

    OurThread = (ULONG_PTR)ExGetCurrentResourceThread();

    //
    //  Get exclusive access to this resource structure
    //

    AcquireResourceLock( Resource, &OldIrql );

    //
    //  Loop until the resource is ours or exit if we cannot wait.
    //

    while (TRUE) {
        if (Resource->ActiveCount == 0) {

            //
            // Resource is un-owned, obtain it exclusive
            //

            Resource->InitialOwnerThreads[0] = OurThread;
            Resource->OwnerThreads[0] = OurThread;
            Resource->OwnerCounts[0]  = 1;
            Resource->ActiveCount     = 1;
            Resource->Flag           |= ResourceOwnedExclusive;
            ReleaseResourceLock ( Resource, OldIrql );
            return TRUE;
        }

        if (IsOwnedExclusive(Resource) &&
            Resource->OwnerThreads[0] == OurThread) {

            //
            // Our thread is already the exclusive resource owner
            //

            Resource->OwnerCounts[0] += 1;
            ReleaseResourceLock( Resource, OldIrql );
            return TRUE;
        }

        //
        //  Check if we are allowed to wait or must return immediately, and
        //  indicate that we didn't acquire the resource
        //

        if (!Wait) {
            ReleaseResourceLock( Resource, OldIrql );
            return FALSE;
        }

        //
        //  Otherwise we need to wait to acquire the resource.
        //

        WaitForResourceExclusive ( Resource, OldIrql );
    }
}
void CDAVCLanSettingsImpl::requestBeepNotification_60(const DAVCLanSettings::BeepNotificationType tBeepNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestBeepNotification_60( tBeepNotification );
}
SchedulerTask::~SchedulerTask() {
	ASSERTMSG( taskThread == ( RFC_HND )NULL , "thread is running for task name=" + name );
	rfc_hnd_evdestroy( stopEvent );
}
void CDAVCLanSettingsImpl::requestAllAtOnceInitializationCompletionNotification_02BB(const DAVCLanSettings::AllAtOnceInitializationCompletionNotificationType tAllAtOnceInitializationCompletionNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestAllAtOnceInitializationCompletionNotification_02BB( tAllAtOnceInitializationCompletionNotification );
}
Пример #24
0
/*++

Routine Name:

    CPTManager::GetTicket

Routine Description:

    This routine retrieves the PrintTicket at the requested scope

Arguments:

    ptScope  - The scope of the PrintTicket to be retrieved
    ppTicket - Pointer to an IXMLDOMDocument2 interface pointer that recieves the PrintTicket

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CPTManager::GetTicket(
    _In_        CONST EPrintTicketScope ptScope,
    _Outptr_ IXMLDOMDocument2**      ppTicket
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(ppTicket, E_POINTER)) &&
        SUCCEEDED(hr = UpdateDefaultPTs(ptScope)))
    {
        *ppTicket = NULL;

        switch (ptScope)
        {
            case kPTPageScope:
            {
                //
                // Pointer should either be default or FP ticket but never NULL
                //
                ASSERTMSG(m_pPagePT != NULL, "NULL Page PrintTicket.\n");

                if (SUCCEEDED(hr = CHECK_POINTER(m_pPagePT, E_PENDING)))
                {
                    *ppTicket = m_pPagePT;
                }
            }
            break;

            case kPTDocumentScope:
            {
                //
                // Pointer should either be default or FD ticket but never NULL
                //
                ASSERTMSG(m_pDocPT != NULL, "NULL Document PrintTicket.\n");

                if (SUCCEEDED(hr = CHECK_POINTER(m_pDocPT, E_PENDING)))
                {
                    *ppTicket = m_pDocPT;
                }
            }
            break;

            case kPTJobScope:
            {
                //
                // Pointer should either be default or FDS ticket but never NULL
                //
                ASSERTMSG(m_pJobPT != NULL, "NULL Job PrintTicket.\n");

                if (SUCCEEDED(hr = CHECK_POINTER(m_pJobPT, E_PENDING)))
                {
                    *ppTicket = m_pJobPT;
                }
            }
            break;

            default:
            {
                RIP("Unrecognised PT scope\n");

                hr = E_INVALIDARG;
            }
            break;
        }

        if (*ppTicket == NULL)
        {
            RIP("Failed to retrieve a valid PrintTicket\n");

            hr = E_FAIL;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
void CDAVCLanSettingsImpl::requestTZStatusNotification_0299(const DAVCLanSettings::TZStatusNotificationType tTZStatusNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestTZStatusNotification_0299( tTZStatusNotification );
}
Пример #26
0
/*++

Routine Name:

    CPTManager::MergeTicket

Routine Description:

    This routine merges a PrintTicket (supplied as a IXMLDOMDocument2 pointer) into
    the DOM representation of the PrintTicket at the requested scope

Arguments:

    ptScope - The scope at which the PrintTicket is to be merged
    pPT     - Pointer to an IXMLDOMDocument2 interface containing the PrintTicket to be merged

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CPTManager::MergeTicket(
    _In_ CONST EPrintTicketScope ptScope,
    _In_ CONST IXMLDOMDocument2* pPT
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pPT, E_POINTER)))
    {
        CComPtr<IXMLDOMDocument2> pPTLevelUp(NULL);
        CComPtr<IXMLDOMDocument2> pResult(NULL);

        switch (ptScope)
        {
            case kPTJobScope:
            {
                pPTLevelUp = m_pDefaultPT;
            }
            break;

            case kPTDocumentScope:
            {
                pPTLevelUp = m_pJobPT;
            }
            break;

            case kPTPageScope:
            {
                pPTLevelUp = m_pDocPT;
            }
            break;

            default:
            {
                RIP("Unrecognised PT scope\n");

                hr = E_INVALIDARG;
            }
            break;
        }

        ASSERTMSG(pPTLevelUp != NULL, "PrintTicket at the level up has not been set (check part handler is attempting to)\n");

        if (SUCCEEDED(hr) &&
            SUCCEEDED(hr = CHECK_POINTER(pPTLevelUp, E_PENDING)) &&
            SUCCEEDED(hr = GetMergedTicket(ptScope, pPT, pPTLevelUp, &pResult)))
        {
            switch (ptScope)
            {
                case kPTJobScope:
                {
                    m_pJobPT = pResult;
                }
                break;

                case kPTDocumentScope:
                {
                    m_pDocPT = pResult;
                }
                break;

                case kPTPageScope:
                {
                    m_pPagePT = pResult;
                }
                break;
            }
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
void CDAVCLanSettingsImpl::requestSettingStatusUpdateNotification_02A0(const DAVCLanSettings::SettingStatusUpdateNotificationType eSettingStatusUpdateNotification)
{
   ASSERTMSG ( "mpLogic is 0", 0 != mpLogic );
   mpLogic->requestSettingStatusUpdateNotification_02A0( eSettingStatusUpdateNotification );
}
Пример #28
0
/*++

Routine Name:

    CPTManager::GetMergedTicket

Routine Description:

    This routine retrieves a merged PrintTicket at the requested scope given the base
    and delta PrintTickets as IXMLDOMDocument2 interface pointers

Arguments:

    ptScope  - The scope at which the merge should take place
    pDelta   - The delta PrintTicket as an IXMLDOMDocument2 pointer
    pBase    - The base PrintTicket as an IXMLDOMDocument2 pointer
    ppResult - The resulting PrintTicket after the merge has completed

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CPTManager::GetMergedTicket(
    _In_        CONST EPrintTicketScope ptScope,
    _In_        CONST IXMLDOMDocument2* pDelta,
    _In_        IXMLDOMDocument2*       pBase,
    _Outptr_ IXMLDOMDocument2**      ppResult
    )
{
    ASSERTMSG(pDelta != NULL, "NULL PT reference part passed.\n");
    ASSERTMSG(pBase != NULL, "NULL base PT passed.\n");
    ASSERTMSG(ppResult != NULL, "NULL out PT passed.\n");

    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_HANDLE(m_hProvider, E_PENDING)) &&
        SUCCEEDED(hr = CHECK_POINTER(ppResult, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pDelta, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pBase, E_POINTER)))
    {
        *ppResult = NULL;
    }

    CComPtr<IStream> pResultStream(NULL);
    CComPtr<IStream> pBaseStream(NULL);
    CComPtr<IStream> pDeltaStream(NULL);

    CComPtr<IXMLDOMDocument2> pNewPT(NULL);

    //
    // Create a new DOM doc based off the result ticket and
    // assign to the resultant DOM doc
    //
    try
    {
        CComBSTR bstrErrorMessage;

        if (SUCCEEDED(hr) &&
            SUCCEEDED(hr = CreateStreamOnHGlobal(NULL, TRUE, &pResultStream)) &&
            SUCCEEDED(hr = pBase->QueryInterface(IID_IStream, reinterpret_cast<VOID**>(&pBaseStream)))  &&
            SUCCEEDED(hr = const_cast<IXMLDOMDocument2*>(pDelta)->QueryInterface(IID_IStream, reinterpret_cast<VOID**>(&pDeltaStream))))
        {
            if (SetThreadToken(NULL, m_hToken))
            {
                if (SUCCEEDED(hr = PTMergeAndValidatePrintTicket(m_hProvider,
                                                                 pBaseStream,
                                                                 pDeltaStream,
                                                                 ptScope,
                                                                 pResultStream,
                                                                 &bstrErrorMessage)))
                {
                    if (SUCCEEDED(hr = SetPTFromStream(pResultStream, &pNewPT)))
                    {
                        //
                        // Assign the outgoing element pointer - detach from CComPtr to release ownership
                        //
                        *ppResult = pNewPT.Detach();
                    }
                }
                else
                {
                    CStringXDA cstrMessage;
                    CStringXDA cstrError(bstrErrorMessage);
                    cstrMessage.Format("PTMergeAndValidatePrintTicket failed with message: %s\n", cstrError);

                    ERR(cstrMessage.GetBuffer());
                }

                //
                // Always revert back to the default security context
                //
                if (!SetThreadToken(NULL, NULL))
                {
                    //
                    // We couldn't revert the security context. The filter pipeline
                    // manager will clean up the thread when operation is complete,
                    // when it is determined that the security context was not 
                    // reverted. Since there are no security implications with 
                    // running this filter in an elevated context, we can 
                    // continue to run.
                    //
                }
            }
            else
            {
                hr = HRESULT_FROM_WIN32(GetLastError());

                //
                // If SetThreadToken fails, GetLastError will return an error
                //
                _Analysis_assume_(FAILED(hr));
            }
        }
    }
    catch (CXDException& e)
    {
        hr = e;
    }

    ERR_ON_HR(hr);
    return hr;
}
Пример #29
0
NTSYSAPI
NTSTATUS
NTAPI
IoAcquireRemoveLockEx(
    IN PIO_REMOVE_LOCK PublicLock,
    IN OPTIONAL PVOID   Tag,
    IN PCSTR            File,
    IN ULONG            Line,
    IN ULONG            RemlockSize // are we checked or free
    )

/*++

Routine Description:

    This routine is called to acquire the remove lock for a device object.
    While the lock is held, the caller can assume that no pending pnp REMOVE
    requests will be completed.

    The lock should be acquired immediately upon entering a dispatch routine.
    It should also be acquired before creating any new reference to the
    device object if there's a chance of releasing the reference before the
    new one is done.

Arguments:

    RemoveLock - A pointer to an initialized REMOVE_LOCK structure.

    Tag - Used for tracking lock allocation and release.  If an irp is
          specified when acquiring the lock then the same Tag must be
          used to release the lock before the Tag is completed.

    File - set to __FILE__ as the location in the code where the lock was taken.

    Line - set to __LINE__.

Return Value:

    Returns whether or not the remove lock was obtained.
    If successful the caller should continue with work calling
    IoReleaseRemoveLock when finished.

    If not successful the lock was not obtained.  The caller should abort the
    work but not call IoReleaseRemoveLock.

--*/

{
    PIO_PRIVATE_REMOVE_LOCK Lock = (PIO_PRIVATE_REMOVE_LOCK) PublicLock;
    LONG        lockValue;
    NTSTATUS    status;

    PIO_REMOVE_LOCK_TRACKING_BLOCK trackingBlock;

    //
    // Grab the remove lock
    //

    lockValue = InterlockedIncrement(&Lock->Common.IoCount);

    ASSERTMSG("IoAcquireRemoveLock - lock value was negative : ",
              (lockValue > 0));

    if (! Lock->Common.Removed) {

        switch (RemlockSize) {
        case CHECKEDSIZE:

            ASSERTMSG("RemoveLock increased to meet LockHighWatermark",
                      ((0 == Lock->Dbg.HighWatermark) ||
                       (lockValue <= Lock->Dbg.HighWatermark)));

            trackingBlock = ExAllocatePoolWithTag(
                                NonPagedPool,
                                sizeof(IO_REMOVE_LOCK_TRACKING_BLOCK),
                                Lock->Dbg.AllocateTag);

            if (NULL == trackingBlock) {

                // ASSERTMSG ("insufficient resources", FALSE);
                InterlockedIncrement (& Lock->Dbg.LowMemoryCount);
                //
                // Let the acquire go through but without adding the
                // tracking block.
                // When we are later releasing the lock, but the tracking
                // block does not exist, deduct from this value to see if the
                // release was still valuable.
                //

            } else {

                KIRQL oldIrql;

                RtlZeroMemory (trackingBlock,
                               sizeof (IO_REMOVE_LOCK_TRACKING_BLOCK));

                trackingBlock->Tag = Tag;
                trackingBlock->File = File;
                trackingBlock->Line = Line;

                KeQueryTickCount(&trackingBlock->TimeLocked);

                ExAcquireSpinLock (&Lock->Dbg.Spin, &oldIrql);
                trackingBlock->Link = Lock->Dbg.Blocks;
                Lock->Dbg.Blocks = trackingBlock;
                ExReleaseSpinLock(&Lock->Dbg.Spin, oldIrql);
            }
            break;

        case FREESIZE:
            break;

        default:
            break;
        }

        status = STATUS_SUCCESS;

    } else {

        if (0 == InterlockedDecrement (&Lock->Common.IoCount)) {
            KeSetEvent (&Lock->Common.RemoveEvent, 0, FALSE);
        }
        status = STATUS_DELETE_PENDING;
    }

    return status;
}
INDEX CDynamicStackArray<Type>::Index(Type *ptMember) {
  ASSERT(this!=NULL);
  INDEX i = CDynamicArray<Type>::Index(ptMember);
  ASSERTMSG(i<da_ctUsed, "CDynamicStackArray<>::Index(): Not a member of this array!");
  return i;
}