Esempio n. 1
0
File: sup.c Progetto: GYGit/reactos
NTSTATUS
CompareProductName(
    IN HANDLE hSubKey,
    IN LPWSTR PnpName,
    IN ULONG ProductNameSize,
    OUT LPWSTR ProductName)
{
    PKEY_VALUE_PARTIAL_INFORMATION PartialInformation;
    UNICODE_STRING DriverDescName = RTL_CONSTANT_STRING(L"DriverDesc");
    UNICODE_STRING MatchingDeviceIdName = RTL_CONSTANT_STRING(L"MatchingDeviceId");
    ULONG Length;
    LPWSTR DeviceName;

    /* read MatchingDeviceId value */
    PartialInformation = ReadKeyValue(hSubKey, &MatchingDeviceIdName);

    if (!PartialInformation)
        return STATUS_UNSUCCESSFUL;


    /* extract last '&' */
    DeviceName = wcsrchr((LPWSTR)PartialInformation->Data, L'&');
    ASSERT(DeviceName);
    /* terminate it */
    DeviceName[0] = L'\0';

    Length = wcslen((LPWSTR)PartialInformation->Data);

    DPRINT("DeviceName %S PnpName %S Length %u\n", (LPWSTR)PartialInformation->Data, PnpName, Length);

    if (_wcsnicmp((LPWSTR)PartialInformation->Data, &PnpName[4], Length))
    {
        FreeItem(PartialInformation);
        return STATUS_NO_MATCH;
    }

    /* free buffer */
    FreeItem(PartialInformation);

    /* read DriverDescName value */
    PartialInformation = ReadKeyValue(hSubKey, &DriverDescName);

    if (!PartialInformation)
    {
        /* failed to read driver desc key */
        return STATUS_UNSUCCESSFUL;
    }

    /* copy key name */
    Length = min(ProductNameSize * sizeof(WCHAR), PartialInformation->DataLength);
    RtlMoveMemory(ProductName, (PVOID)PartialInformation->Data, Length);

    /* zero terminate it */
    ProductName[ProductNameSize-1] = L'\0';

    /* free buffer */
    FreeItem(PartialInformation);

    return STATUS_SUCCESS;
}
Esempio n. 2
0
VOID
FreeEventData(IN PVOID EventData)
{
    PKSEVENTDATA Data = (PKSEVENTDATA)EventData;

    FreeItem(Data->EventHandle.Event);
    FreeItem(Data);
}
Esempio n. 3
0
NTSTATUS
NTAPI
USBCCGP_GetStringDescriptor(
    IN PDEVICE_OBJECT DeviceObject,
    IN ULONG DescriptorLength,
    IN UCHAR DescriptorIndex,
    IN LANGID LanguageId,
    OUT PVOID *OutDescriptor)
{
    NTSTATUS Status;
    PUSB_STRING_DESCRIPTOR StringDescriptor;
    ULONG Size;
    PVOID Buffer;

    // retrieve descriptor
    Status = USBCCGP_GetDescriptor(DeviceObject, USB_STRING_DESCRIPTOR_TYPE, DescriptorLength, DescriptorIndex, LanguageId, OutDescriptor);
    if (!NT_SUCCESS(Status))
    {
        // failed
        return Status;
    }

    // get descriptor structure
    StringDescriptor = (PUSB_STRING_DESCRIPTOR)*OutDescriptor;

    // sanity check
    ASSERT(StringDescriptor->bLength < DescriptorLength - 2);

    if (StringDescriptor->bLength == 2)
    {
        // invalid descriptor
        FreeItem(StringDescriptor);
        return STATUS_DEVICE_DATA_ERROR;
    }

    // calculate size
    Size = StringDescriptor->bLength + sizeof(WCHAR);

    // allocate buffer
    Buffer = AllocateItem(NonPagedPool, Size);
    if (!Buffer)
    {
        // no memory
        FreeItem(StringDescriptor);
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    // copy result
    RtlCopyMemory(Buffer, StringDescriptor->bString, Size - FIELD_OFFSET(USB_STRING_DESCRIPTOR, bString));

    // free buffer
    FreeItem(StringDescriptor);

    // store result
    *OutDescriptor = (PVOID)Buffer;
    return STATUS_SUCCESS;
}
Esempio n. 4
0
TEST
test_Enqueue(){
	Queue q;
	Node *newItem, *newItem2, *newItem3;
	InitQueue(&q);
	
	newItem = NewItem();
	
	//add item to queue
	AddQueue(&q, newItem);

	ASSERT(q.head == newItem);
	ASSERT(q.tail == newItem);
	ASSERT(q.count == 1);

	newItem2 = NewItem();
	AddQueue(&q, newItem2);

	//make sure that head val has not changed, and only tail val has changed
	ASSERT(q.head == newItem);
	ASSERT(q.tail == newItem2);
	ASSERT(q.count == 2);
	//head should point at tail
	ASSERT(q.head->next == q.tail);

	//one more for good measure
	newItem3 = NewItem();
	AddQueue(&q, newItem3);
	//head has not changed, as we add to the end
	ASSERT(q.head == newItem);
	//tail is our new item
	ASSERT(q.tail == newItem3);
	//count updated correctly
	ASSERT(q.count == 3);
	//head.prev points to tail
	ASSERT(q.head->prev == q.tail);
	//head.next does not point to tail, points to middle
	ASSERT(q.head->next == newItem2);
	//3 items, all connected
	ASSERT(q.head->next->next == q.tail);
	//tail.next == head
	ASSERT(q.tail->next == q.head);
	
	//free items
	FreeItem(newItem);
	FreeItem(newItem2);
	FreeItem(newItem3);


	PASS();
}
Esempio n. 5
0
TEST
test_RotateQ(){

	Queue q;
	InitQueue(&q);
	Node *newItem1, *newItem2, *newItem3, *newItem4;

	newItem1 = NewItem();
	newItem2 = NewItem();
	newItem3 = NewItem();
	newItem4 = NewItem();

	AddQueue(&q, newItem1);
	AddQueue(&q, newItem2);
	AddQueue(&q, newItem3);
	AddQueue(&q, newItem4);

	//Queue is 1 2 3 4
	ASSERT(q.head == newItem1);
	ASSERT(q.tail == newItem4);

	RotateQ(&q);
	//Queue is 2 3 4 1
	ASSERT(q.head == newItem2);
	ASSERT(q.tail == newItem1);

	RotateQ(&q);
	//Queue is 3 4 1 2
	ASSERT(q.head == newItem3);
	ASSERT(q.tail == newItem2);

	RotateQ(&q);
	//Queue is 4 1 2 3
	ASSERT(q.head == newItem4);
	ASSERT(q.tail == newItem3);

	RotateQ(&q);
	//Queue is 1 2 3 4
	ASSERT(q.head == newItem1);
	ASSERT(q.tail == newItem4);

	FreeItem(newItem1);
	FreeItem(newItem2);
	FreeItem(newItem3);
	FreeItem(newItem4);
	
	PASS();
}
Esempio n. 6
0
/**
 * Remove the specified DrmData item <code>d</code>.
 *
 * @param p - the pointer of the DRM content InputStream object.
 *
 * @return <code>JNI_DRM_SUCCESS</code> if remove successfuly,
 *         otherwise return <code>JNI_DRM_FAILURE</code>
 */
static int32_t RemoveItem(int32_t id)
{
    DrmData *curItem, *preItem;

    if (NULL == drmTable)
        return CDrmRawContent::JNI_DRM_FAILURE;

    preItem = NULL;
    for (curItem = drmTable; curItem != NULL; curItem = curItem->next) {
        if (id == curItem->id) {
            if (curItem == drmTable)
                drmTable = curItem->next;
            else
                preItem->next = curItem->next;

            FreeItem(curItem);

            return CDrmRawContent::JNI_DRM_SUCCESS;
        }

        preItem = curItem;
    }

    return CDrmRawContent::JNI_DRM_FAILURE;
}
Esempio n. 7
0
NTSTATUS
NTAPI
KspCreateObjectType(
    IN HANDLE ParentHandle,
    IN LPWSTR ObjectType,
    PVOID CreateParameters,
    UINT CreateParametersSize,
    IN  ACCESS_MASK DesiredAccess,
    OUT PHANDLE NodeHandle)
{
    NTSTATUS Status;
    IO_STATUS_BLOCK IoStatusBlock;
    OBJECT_ATTRIBUTES ObjectAttributes;
    UNICODE_STRING Name;

    /* calculate request length */
    Name.Length = 0;
    Name.MaximumLength = wcslen(ObjectType) * sizeof(WCHAR) + CreateParametersSize +  1 * sizeof(WCHAR);
    Name.MaximumLength += sizeof(WCHAR);
    /* acquire request buffer */
    Name.Buffer = AllocateItem(NonPagedPool, Name.MaximumLength);
    /* check for success */
    if (!Name.Buffer)
    {
        /* insufficient resources */
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* build a request which looks like {ObjectClass}\CreateParameters
     * For pins the parent is the reference string used in registration
     * For clocks it is full path for pin\{ClockGuid}\ClockCreateParams
     */
    RtlAppendUnicodeToString(&Name, ObjectType);
    RtlAppendUnicodeToString(&Name, L"\\");
    /* append create parameters */
    RtlMoveMemory(Name.Buffer + (Name.Length / sizeof(WCHAR)), CreateParameters, CreateParametersSize);
    Name.Length += CreateParametersSize;
    Name.Buffer[Name.Length / 2] = L'\0';

    InitializeObjectAttributes(&ObjectAttributes, &Name, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE | OBJ_OPENIF, ParentHandle, NULL);
    /* create the instance */
    Status = IoCreateFile(NodeHandle,
                          DesiredAccess,
                          &ObjectAttributes,
                          &IoStatusBlock,
                          NULL,
                          0,
                          0,
                          FILE_OPEN,
                          0,
                          NULL,
                          0,
                          CreateFileTypeNone,
                          NULL,
                          IO_NO_PARAMETER_CHECKING | IO_FORCE_ACCESS_CHECK);

    /* free request buffer */
    FreeItem(Name.Buffer);
    return Status;
}
Esempio n. 8
0
/*
    @implemented
*/
KSDDKAPI
VOID
NTAPI
KsUnregisterWorker(
    IN  PKSWORKER Worker)
{
    PKSIWORKER KsWorker;
    KIRQL OldIrql;

    if (!Worker)
        return;

    /* get ks worker implementation */
    KsWorker = (PKSIWORKER)Worker;
    /* acquire spinlock */
    KeAcquireSpinLock(&KsWorker->Lock, &OldIrql);
    /* fake status running to avoid work items to be queued by the counted worker */
    KsWorker->Counter = 1;
    /* is there currently a work item active */
    if (KsWorker->QueuedWorkItemCount)
    {
        /* release the lock */
        KeReleaseSpinLock(&KsWorker->Lock, OldIrql);
        /* wait for the worker routine to finish */
        KeWaitForSingleObject(&KsWorker->Event, Executive, KernelMode, FALSE, NULL);
    }
    else
    {
        /* no work item active, just release the lock */
        KeReleaseSpinLock(&KsWorker->Lock, OldIrql);
    }
    /* free worker context */
    FreeItem(KsWorker);
}
Esempio n. 9
0
NTSTATUS
NTAPI
Dispatch_fnClose(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp)
{
    PIO_STACK_LOCATION IoStack;
    PDISPATCH_CONTEXT DispatchContext;
    NTSTATUS Status;

    // get current irp stack
    IoStack = IoGetCurrentIrpStackLocation(Irp);
    // get dispatch context
    DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;

    // let IrpTarget handle request
    Status = DispatchContext->Target->Close(DeviceObject, Irp);

    if (NT_SUCCESS(Status))
    {
       KsFreeObjectHeader(DispatchContext->ObjectHeader);
       FreeItem(DispatchContext, TAG_PORTCLASS);
    }
    // done
    return Status;
}
Esempio n. 10
0
/*
    @implemented
*/
KSDDKAPI
NTSTATUS
NTAPI
KsValidateClockCreateRequest(
    IN  PIRP Irp,
    OUT PKSCLOCK_CREATE* OutClockCreate)
{
    PKSCLOCK_CREATE ClockCreate;
    NTSTATUS Status;
    ULONG Size;

    /* minimum request size */
    Size = sizeof(KSCLOCK_CREATE);

    /* copy create request */
    Status = KspCopyCreateRequest(Irp, 
                                  KSSTRING_Clock,
                                  &Size,
                                  (PVOID*)&ClockCreate);

    if (!NT_SUCCESS(Status))
        return Status;

    if (ClockCreate->CreateFlags != 0)
    {
        /* flags must be zero */
        FreeItem(ClockCreate);
        return STATUS_INVALID_PARAMETER;
    }

    *OutClockCreate = ClockCreate;
    return STATUS_SUCCESS;
}
Esempio n. 11
0
File: pin.c Progetto: GYGit/reactos
NTSTATUS
NTAPI
Pin_fnClose(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp)
{
    PDISPATCH_CONTEXT Context;
    PIO_STACK_LOCATION IoStack;

    //DPRINT("Pin_fnClose called DeviceObject %p Irp %p\n", DeviceObject, Irp);

    /* Get current stack location */
    IoStack = IoGetCurrentIrpStackLocation(Irp);

    /* The dispatch context is stored in the FsContext member */
    Context = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;

    if (Context->Handle)
    {
        ZwClose(Context->Handle);
    }

    if (Context->hMixerPin)
    {
        ZwClose(Context->hMixerPin);
    }

    FreeItem(Context);

    Irp->IoStatus.Status = STATUS_SUCCESS;
    Irp->IoStatus.Information = 0;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    return STATUS_SUCCESS;
}
Esempio n. 12
0
/*
*****************************************************************************
**
** FUNCTION NAME: GetFirstTaskItemFromDB
**
** FUNCTION INPUTS:
**         ptrEncodeItem: the  encode information struct.
**
** FUNCTION DESCRIPTION
**        get the first record from the zriptask.db, and receive the total record of the db.
**
** FUNCTION OUTPUTS:
**       return: the count of the enc_pending record in the zriptask.db.
** HISTORY:
**
**           2008-7-2       HChen  Created.
**
*****************************************************************************
*/
int GetFirstTaskItemFromDB(PENC_PENDING ptrEncodeItem)
{ 
    int nRetVal = 0;
    char **result;
    int nRow, nCol; 

    if(QueryPendingTask(ENCPENDING,&result,&nRow,&nCol) == ZAPP_SUCCESS)
    {
        if((nRow >= 1)
            &&(result)
            &&(result[1*nCol+0])
            &&(result[1*nCol+1])
            &&(result[1*nCol+2]))
         {
            ZFREE(gObjID);
            gObjID = strdup(result[1*nCol+0]);    /*get the first record's objid of the db*/
            if((ConvertTask.eThreadStatus == THREAD_FINISHED) /*if the  ConvertTask is finished, the set value to the global struct*/
                &&(ConvertTask.eItemStatus == ITEM_ENCODED))
              {
                ConvertTask.nAccTrackNum++;
                ConvertTask.eItemStatus = ITEM_INIT;
                FreeItem(ptrEncodeItem);
                ptrEncodeItem->objID = strdup(result[1*nCol+0]);
                ptrEncodeItem->ptrAudioFormat = strdup(result[1*nCol+1]);
                ptrEncodeItem->ptrFormatCfg = strdup(result[1*nCol+2]);
              }
         }
        nRetVal = nRow;
    }
   if(result)
   {
      ZripTaskFreeResult(result);	
   }
    return nRetVal;
}
Esempio n. 13
0
VOID
CALLBACK
PwrCompletionFunction(
    IN PDEVICE_OBJECT DeviceObject,
    IN UCHAR MinorFunction,
    IN POWER_STATE PowerState,
    IN PVOID Context,
    IN PIO_STATUS_BLOCK IoStatus)
{
    NTSTATUS Status;
    PQUERY_POWER_CONTEXT PwrContext = (PQUERY_POWER_CONTEXT)Context;

    if (NT_SUCCESS(IoStatus->Status))
    {
        // forward request to lower device object
        Status = PcForwardIrpSynchronous(PwrContext->DeviceObject, PwrContext->Irp);
    }
    else
    {
        // failed
        Status = IoStatus->Status;
    }

    // start next power irp
    PoStartNextPowerIrp(PwrContext->Irp);

    // complete request
    PwrContext->Irp->IoStatus.Status = Status;
    IoCompleteRequest(PwrContext->Irp, IO_NO_INCREMENT);

    // free context
    FreeItem(PwrContext, TAG_PORTCLASS);
}
Esempio n. 14
0
ULONG
NTAPI
IKsFilterFactory_fnRelease(
    IKsFilterFactory * iface)
{
    IKsFilterFactoryImpl * This = (IKsFilterFactoryImpl*)CONTAINING_RECORD(iface, IKsFilterFactoryImpl, Header.OuterUnknown);

    InterlockedDecrement(&This->ref);

    if (This->ref == 0)
    {
        if (!IsListEmpty(&This->SymbolicLinkList))
        {
            /* disable device interfaces */
            KspSetDeviceInterfacesState(&This->SymbolicLinkList, FALSE);
            /* free device interface strings */
            KspFreeDeviceInterfaces(&This->SymbolicLinkList);
        }

        FreeItem(This);
        return 0;
    }
    /* Return new reference count */
    return This->ref;
}
Esempio n. 15
0
/*
    @implemented
*/
KSDDKAPI
NTSTATUS
NTAPI
KsCreateDefaultClock(
    IN  PIRP Irp,
    IN  PKSDEFAULTCLOCK DefaultClock)
{
    NTSTATUS Status;
    PKSCLOCK_CREATE ClockCreate;
    PKSICLOCK Clock;

    Status = KsValidateClockCreateRequest(Irp, &ClockCreate);
    if (!NT_SUCCESS(Status))
        return Status;

    /* let's allocate the clock struct */
    Clock = AllocateItem(NonPagedPool, sizeof(KSICLOCK));
    if (!Clock)
    {
        FreeItem(ClockCreate);
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* now allocate the object header */
    Status = KsAllocateObjectHeader((PVOID*)&Clock->ObjectHeader, 0, NULL, Irp, &DispatchTable);

    /* did it work */
    if (!NT_SUCCESS(Status))
    {
        /* failed */
        FreeItem(ClockCreate);
        FreeItem(Clock);
        return Status;
    }

    /* initialize clock */
    /* FIXME IKsClock */
    Clock->ObjectHeader->ObjectType = (PVOID)Clock;
    Clock->ref = 1;
    Clock->ClockCreate = ClockCreate;
    Clock->DefaultClock = (PKSIDEFAULTCLOCK)DefaultClock;

    /* increment reference count */
    InterlockedIncrement(&Clock->DefaultClock->ReferenceCount);

    return Status;
}
Esempio n. 16
0
MIXER_STATUS
Enum(
    IN  PVOID EnumContext,
    IN  ULONG DeviceIndex,
    OUT LPWSTR * DeviceName,
    OUT PHANDLE OutHandle,
    OUT PHANDLE OutKey)
{
    PDEVICE_OBJECT DeviceObject;
    ULONG DeviceCount;
    NTSTATUS Status;
    UNICODE_STRING KeyName;

    /* get enumeration context */
    DeviceObject = (PDEVICE_OBJECT)EnumContext;

    /* get device count */
    DeviceCount = GetSysAudioDeviceCount(DeviceObject);

    if (DeviceIndex >= DeviceCount)
    {
        /* no more devices */
        return MM_STATUS_NO_MORE_DEVICES;
    }

    /* get device name */
    Status = GetSysAudioDevicePnpName(DeviceObject, DeviceIndex, DeviceName);

    if (!NT_SUCCESS(Status))
    {
        /* failed to retrieve device name */
        return MM_STATUS_UNSUCCESSFUL;
    }

    /* intialize key name */
    RtlInitUnicodeString(&KeyName, *DeviceName);

    /* open device interface key */
    Status = IoOpenDeviceInterfaceRegistryKey(&KeyName, GENERIC_READ | GENERIC_WRITE, OutKey);
#if 0
    if (!NT_SUCCESS(Status))
    {
        /* failed to open key */
        DPRINT("IoOpenDeviceInterfaceRegistryKey failed with %lx\n", Status);
        FreeItem(*DeviceName);
        return MM_STATUS_UNSUCCESSFUL;
    }
#endif

    /* open device handle */
    Status = OpenDevice(*DeviceName, OutHandle, NULL);
    if (!NT_SUCCESS(Status))
    {
        /* failed to open device */
        return MM_STATUS_UNSUCCESSFUL;
    }

    return MM_STATUS_SUCCESS;
}
Esempio n. 17
0
NTSTATUS
NTAPI
IoCompletion (
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp,
    PVOID Ctx)
{
    PKSSTREAM_HEADER Header;
    ULONG Length = 0;
    PMDL Mdl, NextMdl;
    PWDMAUD_COMPLETION_CONTEXT Context = (PWDMAUD_COMPLETION_CONTEXT)Ctx;

    /* get stream header */
    Header = (PKSSTREAM_HEADER)Irp->AssociatedIrp.SystemBuffer;

    /* sanity check */
    ASSERT(Header);

    /* time to free all allocated mdls */
    Mdl = Irp->MdlAddress;

    while(Mdl)
    {
        /* get next mdl */
        NextMdl = Mdl->Next;

        /* unlock pages */
        MmUnlockPages(Mdl);

        /* grab next mdl */
        Mdl = NextMdl;
    }

    /* clear mdl list */
    Irp->MdlAddress = NULL;

   /* check if mdl is locked */
    if (Context->Mdl->MdlFlags & MDL_PAGES_LOCKED)
    {
        /* unlock pages */
        MmUnlockPages(Context->Mdl);
    }

    /* now free the mdl */
    IoFreeMdl(Context->Mdl);

    DPRINT("IoCompletion Irp %p IoStatus %lx Information %lx Length %lu\n", Irp, Irp->IoStatus.Status, Irp->IoStatus.Information, Length);

    if (!NT_SUCCESS(Irp->IoStatus.Status))
    {
        /* failed */
        Irp->IoStatus.Information = 0;
    }

    /* free context */
    FreeItem(Context);

    return STATUS_SUCCESS;
}
Esempio n. 18
0
/*
    @implemented
*/
KSDDKAPI
VOID
NTAPI
KsFreeObjectBag(
    IN KSOBJECT_BAG ObjectBag)
{
    PLIST_ENTRY Entry;
    PKSIOBJECT_BAG Bag;
    PKSIOBJECT_BAG_ENTRY BagEntry;
    ULONG TotalRefs;

    /* get real object bag */
    Bag = (PKSIOBJECT_BAG)ObjectBag;

    /* acquire bag mutex */
    KeWaitForSingleObject(Bag->BagMutex, Executive, KernelMode, FALSE, NULL);

    while(!IsListEmpty(&Bag->ObjectList))
    {
        /* get an bag entry */
        Entry = RemoveHeadList(&Bag->ObjectList);
        /* access bag entry item */
        BagEntry = (PKSIOBJECT_BAG_ENTRY)CONTAINING_RECORD(Entry, KSIOBJECT_BAG, Entry);

        /* check if the item is present in some other bag */
        TotalRefs = KspGetObjectItemReferenceCount((PKSIDEVICE_HEADER)Bag->DeviceHeader, &BagEntry->Item);

        if (TotalRefs == 0)
        {
            /* item is ready to be freed */
            BagEntry->Free(BagEntry->Item);
        }

        /* free bag entry item */
        FreeItem(BagEntry);
    }

    /* remove bag entry from device object list */
    RemoveEntryList(&Bag->Entry);

    /* release bag mutex */
    KeReleaseMutex(Bag->BagMutex, FALSE);

    /* now free object bag */
    FreeItem(Bag);
}
Esempio n. 19
0
void CCollection::AtFree(int nIndex)
{
    void * pItem;

    pItem = At(nIndex);
    if (pItem)
        FreeItem(pItem);
    AtDelete(nIndex);
}
Esempio n. 20
0
TEST
test_NewItem(){
	Node * newItem;
	newItem = NewItem();
	ASSERT(newItem);

	FreeItem(newItem);

	PASS();
}
Esempio n. 21
0
File: sup.c Progetto: GYGit/reactos
PKEY_VALUE_PARTIAL_INFORMATION
ReadKeyValue(
    IN HANDLE hSubKey,
    IN PUNICODE_STRING KeyName)
{
    NTSTATUS Status;
    ULONG Length;
    PKEY_VALUE_PARTIAL_INFORMATION PartialInformation;

    /* now query MatchingDeviceId key */
    Status = ZwQueryValueKey(hSubKey, KeyName, KeyValuePartialInformation, NULL, 0, &Length);

    /* check for success */
    if (Status != STATUS_BUFFER_TOO_SMALL)
        return NULL;

    /* allocate a buffer for key data */
    PartialInformation = AllocateItem(NonPagedPool, Length);

    if (!PartialInformation)
        return NULL;


    /* now query MatchingDeviceId key */
    Status = ZwQueryValueKey(hSubKey, KeyName, KeyValuePartialInformation, PartialInformation, Length, &Length);

    /* check for success */
    if (!NT_SUCCESS(Status))
    {
        FreeItem(PartialInformation);
        return NULL;
    }

    if (PartialInformation->Type != REG_SZ)
    {
        /* invalid key type */
        FreeItem(PartialInformation);
        return NULL;
    }

    return PartialInformation;
}
Esempio n. 22
0
NTSTATUS
NTAPI
IoCompletion (
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp,
    PVOID Ctx)
{
    PKSSTREAM_HEADER Header;
    PMDL Mdl, NextMdl;
    PWDMAUD_COMPLETION_CONTEXT Context = (PWDMAUD_COMPLETION_CONTEXT)Ctx;

    /* get stream header */
    Header = (PKSSTREAM_HEADER)Irp->AssociatedIrp.SystemBuffer;

    /* sanity check */
    ASSERT(Header);

    /* time to free all allocated mdls */
    Mdl = Irp->MdlAddress;

    while(Mdl)
    {
        /* get next mdl */
        NextMdl = Mdl->Next;

        /* unlock pages */
        MmUnlockPages(Mdl);

        /* grab next mdl */
        Mdl = NextMdl;
    }
    //IoFreeMdl(Mdl);
    /* clear mdl list */
    Irp->MdlAddress = Context->Mdl;



    DPRINT("IoCompletion Irp %p IoStatus %lx Information %lx\n", Irp, Irp->IoStatus.Status, Irp->IoStatus.Information);

    if (!NT_SUCCESS(Irp->IoStatus.Status))
    {
        /* failed */
        Irp->IoStatus.Information = 0;
    }

    /* dereference file object */
    ObDereferenceObject(Context->FileObject);

    /* free context */
    FreeItem(Context);

    return STATUS_SUCCESS;
}
Esempio n. 23
0
void FreeConvertTask(void)
{
    ZFREE(ConvertTask.PreObjID);
    freeMetaTrack(&(ConvertTask.TrackMeta));
    FreeItem(&(ConvertTask.CurEncodeItem));
    ZFREE(ConvertTask.UpdateItem.objID);   
    ZFREE(ConvertTask.UpdateItem.ptrAudioFormat);   
    ZFREE(ConvertTask.UpdateItem.ptrWavPath);   
    ZFREE(ConvertTask.UpdateItem.ptrEncPath);   
    ZFREE(ConvertTask.DiscAudioSrcPath);
    ZFREE(ConvertTask.DiscEncodePath);
}
Esempio n. 24
0
NTSTATUS
USBCCGP_SelectInterface(
    IN PDEVICE_OBJECT DeviceObject,
    IN PFDO_DEVICE_EXTENSION DeviceExtension,
    IN ULONG InterfaceIndex)
{
    NTSTATUS Status;
    PURB Urb;

    //
    // allocate urb
    //
    Urb = AllocateItem(NonPagedPool, GET_SELECT_INTERFACE_REQUEST_SIZE(DeviceExtension->InterfaceList[InterfaceIndex].InterfaceDescriptor->bNumEndpoints));
    if (!Urb)
    {
        //
        // no memory
        //
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    //
    // now prepare interface urb
    //
    UsbBuildSelectInterfaceRequest(Urb, GET_SELECT_INTERFACE_REQUEST_SIZE(DeviceExtension->InterfaceList[InterfaceIndex].InterfaceDescriptor->bNumEndpoints), DeviceExtension->ConfigurationHandle, DeviceExtension->InterfaceList[InterfaceIndex].InterfaceDescriptor->bInterfaceNumber, DeviceExtension->InterfaceList[InterfaceIndex].InterfaceDescriptor->bAlternateSetting);

    //
    // now select the interface
    //
    Status = USBCCGP_SyncUrbRequest(DeviceExtension->NextDeviceObject, Urb);

    //
    // did it succeeed
    //
    if (NT_SUCCESS(Status))
    {
        //
        // update configuration info
        //
        ASSERT(Urb->UrbSelectInterface.Interface.Length == DeviceExtension->InterfaceList[InterfaceIndex].Interface->Length);
        RtlCopyMemory(DeviceExtension->InterfaceList[InterfaceIndex].Interface, &Urb->UrbSelectInterface.Interface, Urb->UrbSelectInterface.Interface.Length);
    }

    //
    // free urb
    //
    FreeItem(Urb);

    //
    // done
    //
    return Status;
}
Esempio n. 25
0
void CCollection::FreeAll()
{
    void * pItem;
    int    i;

    for (i=0; i<m_nCount; i++)
    {
        pItem = At(i);
        if (pItem)
            FreeItem(pItem);
    }
    DeleteAll();
}
Esempio n. 26
0
void CBypassQueue::RemoveAll(void)
{
    BITEM    *pItem;

    m_Locker.Lock();
    pItem = m_List.GetHead();
    while((pItem = m_List.GetHead())) 
    {
        m_List.RemoveAt((POSITION)pItem->nPosition);
        FreeItem(pItem);
    }
    m_Locker.Unlock();
}
Esempio n. 27
0
NTSTATUS
NTAPI
WdmAudGetDeviceInterface(
    IN  PDEVICE_OBJECT DeviceObject,
    IN  PIRP Irp,
    IN  PWDMAUD_DEVICE_INFO DeviceInfo)
{
    PWDMAUD_DEVICE_EXTENSION DeviceExtension;
    NTSTATUS Status;
    LPWSTR Device;
    ULONG Size, Length;

    /* get device extension */
    DeviceExtension = (PWDMAUD_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    /* get device interface string input length */
    Size = DeviceInfo->u.Interface.DeviceInterfaceStringSize;

   /* get mixer info */
   Status = WdmAudGetPnpNameByIndexAndType(DeviceInfo->DeviceIndex, DeviceInfo->DeviceType, &Device);

   /* check for success */
   if (!NT_SUCCESS(Status))
   {
        /* invalid device id */
        return SetIrpIoStatus(Irp, Status, sizeof(WDMAUD_DEVICE_INFO));
   }

   /* calculate length */
   Length = (wcslen(Device)+1) * sizeof(WCHAR);

    if (!Size)
    {
        /* store device interface size */
        DeviceInfo->u.Interface.DeviceInterfaceStringSize = Length;
    }
    else if (Size < Length)
    {
        /* buffer too small */
        DeviceInfo->u.Interface.DeviceInterfaceStringSize = Length;
        return SetIrpIoStatus(Irp, STATUS_BUFFER_OVERFLOW, sizeof(WDMAUD_DEVICE_INFO));
    }
    else
    {
        //FIXME SEH
        RtlMoveMemory(DeviceInfo->u.Interface.DeviceInterfaceString, Device, Length);
    }

    FreeItem(Device);
    return SetIrpIoStatus(Irp, STATUS_SUCCESS, sizeof(WDMAUD_DEVICE_INFO));
}
Esempio n. 28
0
File: sup.c Progetto: GYGit/reactos
NTSTATUS
GetSysAudioDevicePnpName(
    IN  PDEVICE_OBJECT DeviceObject,
    IN  ULONG DeviceIndex,
    OUT LPWSTR * Device)
{
    ULONG BytesReturned;
    KSP_PIN Pin;
    NTSTATUS Status;
    PWDMAUD_DEVICE_EXTENSION DeviceExtension;

   /* first check if the device index is within bounds */
   if (DeviceIndex >= GetSysAudioDeviceCount(DeviceObject))
       return STATUS_INVALID_PARAMETER;

    /* setup the query request */
    Pin.Property.Set = KSPROPSETID_Sysaudio;
    Pin.Property.Id = KSPROPERTY_SYSAUDIO_DEVICE_INTERFACE_NAME;
    Pin.Property.Flags = KSPROPERTY_TYPE_GET;
    Pin.PinId = DeviceIndex;

    DeviceExtension = (PWDMAUD_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    /* query sysaudio for the device path */
    Status = KsSynchronousIoControlDevice(DeviceExtension->FileObject, KernelMode, IOCTL_KS_PROPERTY, (PVOID)&Pin, sizeof(KSPROPERTY) + sizeof(ULONG), NULL, 0, &BytesReturned);

    /* check if the request failed */
    if (Status != STATUS_BUFFER_TOO_SMALL || BytesReturned == 0)
        return STATUS_UNSUCCESSFUL;

    /* allocate buffer for the device */
    *Device = AllocateItem(NonPagedPool, BytesReturned);
    if (!Device)
        return STATUS_INSUFFICIENT_RESOURCES;

    /* query sysaudio again for the device path */
    Status = KsSynchronousIoControlDevice(DeviceExtension->FileObject, KernelMode, IOCTL_KS_PROPERTY, (PVOID)&Pin, sizeof(KSPROPERTY) + sizeof(ULONG), (PVOID)*Device, BytesReturned, &BytesReturned);

    if (!NT_SUCCESS(Status))
    {
        /* failed */
        FreeItem(*Device);
        return Status;
    }

    return Status;
}
Esempio n. 29
0
ULONG
NTAPI
IKsAllocator_fnRelease(
    IKsAllocator * iface)
{
    PALLOCATOR This = (PALLOCATOR)CONTAINING_RECORD(iface, ALLOCATOR, lpVtbl);

    InterlockedDecrement(&This->ref);

    if (This->ref == 0)
    {
        FreeItem(This);
        return 0;
    }
    /* Return new reference count */
    return This->ref;
}
Esempio n. 30
0
NTSTATUS
NTAPI
WdmAudGetMixerEvent(
    IN  PDEVICE_OBJECT DeviceObject,
    IN  PIRP Irp,
    IN  PWDMAUD_DEVICE_INFO DeviceInfo,
    IN  PWDMAUD_CLIENT ClientInfo)
{
    PLIST_ENTRY Entry;
    PEVENT_ENTRY EventEntry;

    /* enumerate event list and check if there is a new event */
    Entry = ClientInfo->MixerEventList.Flink;

    while(Entry != &ClientInfo->MixerEventList)
    {
        /* grab event entry */
        EventEntry = (PEVENT_ENTRY)CONTAINING_RECORD(Entry, EVENT_ENTRY, Entry);

        if (EventEntry->hMixer == DeviceInfo->hDevice)
        {
            /* found an entry */
            DeviceInfo->u.MixerEvent.hMixer = EventEntry->hMixer;
            DeviceInfo->u.MixerEvent.NotificationType = EventEntry->NotificationType;
            DeviceInfo->u.MixerEvent.Value = EventEntry->Value;

            /* remove entry from list */
            RemoveEntryList(&EventEntry->Entry);

            /* free event entry */
            FreeItem(EventEntry);

            /* done */
            return SetIrpIoStatus(Irp, STATUS_SUCCESS, sizeof(WDMAUD_DEVICE_INFO));
        }

        /* move to next */
        Entry = Entry->Flink;
    }

    /* no event entry available */
    return SetIrpIoStatus(Irp, STATUS_UNSUCCESSFUL, sizeof(WDMAUD_DEVICE_INFO));
}