2008-04-17 13:45:02 +00:00
|
|
|
/*
|
2010-11-02 09:37:30 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Kernel Streaming
|
|
|
|
* FILE: dll/directx/ksuser/ksuser.c
|
|
|
|
* PURPOSE: KS USER functions
|
|
|
|
* PROGRAMMER: Magnus Olsen and Dmitry Chapyshev and Johannes Anderwald
|
2008-04-17 13:45:02 +00:00
|
|
|
*/
|
|
|
|
|
2008-04-17 18:01:51 +00:00
|
|
|
#include "ksuser.h"
|
2008-11-26 19:04:55 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2008-04-17 18:01:51 +00:00
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
KsiCreateObjectType( HANDLE hHandle,
|
2010-11-02 09:37:30 +00:00
|
|
|
LPWSTR ObjectType,
|
2008-04-17 18:01:51 +00:00
|
|
|
PVOID Buffer,
|
|
|
|
ULONG BufferSize,
|
|
|
|
ACCESS_MASK DesiredAccess,
|
|
|
|
PHANDLE phHandle)
|
2008-04-17 13:45:02 +00:00
|
|
|
{
|
2009-01-19 15:55:47 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG TotalSize;
|
|
|
|
LPWSTR pStr;
|
|
|
|
UNICODE_STRING ObjectName;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
|
2010-11-02 09:37:30 +00:00
|
|
|
/* get length of object type */
|
|
|
|
Length = wcslen(ObjectType);
|
2009-01-19 15:55:47 +00:00
|
|
|
|
2010-11-02 09:37:30 +00:00
|
|
|
/* get length for request */
|
|
|
|
TotalSize = (Length * sizeof(WCHAR)) + BufferSize;
|
2009-01-19 15:55:47 +00:00
|
|
|
|
2010-11-02 09:37:30 +00:00
|
|
|
/* append space for '\\'*/
|
|
|
|
TotalSize += sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* allocate buffer */
|
2009-01-19 15:55:47 +00:00
|
|
|
pStr = HeapAlloc(GetProcessHeap(), 0, TotalSize);
|
|
|
|
if (!pStr)
|
2010-11-02 09:37:30 +00:00
|
|
|
{
|
|
|
|
/* out of memory */
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy object type */
|
|
|
|
wcscpy(pStr, ObjectType);
|
|
|
|
|
|
|
|
/* append slash */
|
|
|
|
pStr[Length] = L'\\';
|
|
|
|
|
|
|
|
/* append parameters */
|
|
|
|
memcpy(&pStr[Length+1], Buffer, BufferSize);
|
|
|
|
|
|
|
|
/* initialize object name */
|
|
|
|
ObjectName.Buffer = pStr;
|
2009-08-21 18:36:43 +00:00
|
|
|
ObjectName.Length = ObjectName.MaximumLength = TotalSize;
|
2009-01-19 15:55:47 +00:00
|
|
|
|
2010-11-02 09:37:30 +00:00
|
|
|
/* initialize object attributes */
|
2009-01-19 15:55:47 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &ObjectName, OBJ_CASE_INSENSITIVE, hHandle, NULL);
|
|
|
|
|
2010-11-02 09:37:30 +00:00
|
|
|
/* create the object */
|
2009-01-19 15:55:47 +00:00
|
|
|
Status = NtCreateFile(phHandle, DesiredAccess, &ObjectAttributes, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, 0, 1, 0, NULL, 0);
|
2010-11-02 09:37:30 +00:00
|
|
|
|
|
|
|
/* free buffer */
|
2009-01-19 15:55:47 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pStr);
|
2010-11-02 09:37:30 +00:00
|
|
|
|
|
|
|
/* check for success */
|
2009-01-19 15:55:47 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2010-11-02 09:37:30 +00:00
|
|
|
/* failed zero handle */
|
2009-01-19 15:55:47 +00:00
|
|
|
*phHandle = INVALID_HANDLE_VALUE;
|
2010-11-02 09:37:30 +00:00
|
|
|
|
|
|
|
/* convert error code */
|
2009-01-19 15:55:47 +00:00
|
|
|
Status = RtlNtStatusToDosError(Status);
|
|
|
|
}
|
2010-11-02 09:37:30 +00:00
|
|
|
|
|
|
|
/* done */
|
2009-01-19 15:55:47 +00:00
|
|
|
return Status;
|
2008-04-17 13:45:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 18:01:51 +00:00
|
|
|
/*++
|
|
|
|
* @name KsCreateAllocator
|
|
|
|
* @implemented
|
|
|
|
* The function KsCreateAllocator creates a handle to an allocator for the given sink connection handle
|
|
|
|
*
|
|
|
|
* @param HANDLE ConnectionHandle
|
|
|
|
* Handle to the sink connection on which to create the allocator
|
|
|
|
*
|
|
|
|
* @param PKSALLOCATOR_FRAMING AllocatorFraming
|
|
|
|
* the input param we using to alloc our framing
|
|
|
|
*
|
|
|
|
* @param PHANDLE AllocatorHandle
|
|
|
|
* Our new handle that we have alloc
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Return NTSTATUS error code or sussess code.
|
|
|
|
*
|
|
|
|
* @remarks.
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
KSDDKAPI
|
2010-03-13 14:15:56 +00:00
|
|
|
DWORD
|
2008-04-17 18:01:51 +00:00
|
|
|
NTAPI
|
|
|
|
KsCreateAllocator(HANDLE ConnectionHandle,
|
|
|
|
PKSALLOCATOR_FRAMING AllocatorFraming,
|
|
|
|
PHANDLE AllocatorHandle)
|
|
|
|
|
2008-04-17 13:45:02 +00:00
|
|
|
{
|
2008-04-17 18:01:51 +00:00
|
|
|
return KsiCreateObjectType( ConnectionHandle,
|
|
|
|
KSSTRING_Allocator,
|
|
|
|
(PVOID) AllocatorFraming,
|
|
|
|
sizeof(KSALLOCATOR_FRAMING),
|
|
|
|
GENERIC_READ,
|
|
|
|
AllocatorHandle);
|
2008-04-17 13:45:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 18:01:51 +00:00
|
|
|
/*++
|
|
|
|
* @name KsCreateClock
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* The function KsCreateClock creates handle to clock instance
|
|
|
|
*
|
|
|
|
* @param HANDLE ConnectionHandle
|
|
|
|
* Handle to use to create the clock
|
|
|
|
*
|
|
|
|
* @param PKSCLOCK_CREATE ClockCreate
|
|
|
|
* paramenter to use to create the clock
|
|
|
|
*
|
|
|
|
* @param PHANDLE ClockHandle
|
|
|
|
* The new handle
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Return NTSTATUS error code or sussess code.
|
|
|
|
*
|
|
|
|
* @remarks.
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
KSDDKAPI
|
2010-03-13 14:15:56 +00:00
|
|
|
DWORD
|
2008-04-17 18:01:51 +00:00
|
|
|
NTAPI
|
|
|
|
KsCreateClock(HANDLE ConnectionHandle,
|
|
|
|
PKSCLOCK_CREATE ClockCreate,
|
|
|
|
PHANDLE ClockHandle)
|
2008-04-17 13:45:02 +00:00
|
|
|
{
|
2008-04-17 18:01:51 +00:00
|
|
|
return KsiCreateObjectType( ConnectionHandle,
|
|
|
|
KSSTRING_Clock,
|
|
|
|
(PVOID) ClockCreate,
|
|
|
|
sizeof(KSCLOCK_CREATE),
|
|
|
|
GENERIC_READ,
|
|
|
|
ClockHandle);
|
2008-04-17 13:45:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 18:01:51 +00:00
|
|
|
/*++
|
|
|
|
* @name KsCreatePin
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* The function KsCreatePin passes a connection request to device and create pin instance
|
|
|
|
*
|
|
|
|
* @param HANDLE FilterHandle
|
|
|
|
* handle of the filter initiating the create request
|
|
|
|
*
|
|
|
|
* @param PKSPIN_CONNECT Connect
|
|
|
|
* Pointer to a KSPIN_CONNECT structure that contains parameters for the requested connection.
|
|
|
|
* This should be followed in memory by a KSDATAFORMAT data structure, describing the data format
|
|
|
|
* requested for the connection.
|
|
|
|
|
|
|
|
* @param ACCESS_MASK DesiredAccess
|
|
|
|
* Desrided access
|
|
|
|
*
|
|
|
|
* @param PHANDLE ConnectionHandle
|
|
|
|
* connection handle passed
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Return NTSTATUS error code or sussess code.
|
|
|
|
*
|
|
|
|
* @remarks.
|
|
|
|
* The flag in PKSDATAFORMAT is not really document,
|
|
|
|
* to find it u need api mointor allot api and figout
|
|
|
|
* how it works, only flag I have found is the
|
|
|
|
* KSDATAFORMAT_ATTRIBUTES flag, it doing a Align
|
|
|
|
* of LONLONG size, it also round up it.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
|
|
|
|
KSDDKAPI
|
2009-08-23 23:05:23 +00:00
|
|
|
DWORD
|
2008-04-17 18:01:51 +00:00
|
|
|
NTAPI
|
|
|
|
KsCreatePin(HANDLE FilterHandle,
|
|
|
|
PKSPIN_CONNECT Connect,
|
|
|
|
ACCESS_MASK DesiredAccess,
|
|
|
|
PHANDLE ConnectionHandle)
|
2008-04-17 13:45:02 +00:00
|
|
|
{
|
2008-04-17 18:01:51 +00:00
|
|
|
ULONG BufferSize = sizeof(KSPIN_CONNECT);
|
2009-10-30 15:36:55 +00:00
|
|
|
PKSDATAFORMAT DataFormat = ((PKSDATAFORMAT) ((ULONG_PTR)Connect + sizeof(KSPIN_CONNECT)));
|
2008-04-17 18:01:51 +00:00
|
|
|
|
2009-08-24 02:54:53 +00:00
|
|
|
BufferSize += DataFormat->FormatSize;
|
2008-04-17 18:01:51 +00:00
|
|
|
|
|
|
|
return KsiCreateObjectType(FilterHandle,
|
|
|
|
KSSTRING_Pin,
|
|
|
|
Connect,
|
|
|
|
BufferSize,
|
|
|
|
DesiredAccess,
|
|
|
|
ConnectionHandle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name KsCreateTopologyNode
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* The function KsCreateTopologyNode creates a handle to a topology node instance
|
|
|
|
*
|
|
|
|
* @param HANDLE ParentHandle
|
|
|
|
* Handle to parent when want to use when we created the node on
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param PKSNODE_CREATE NodeCreate
|
|
|
|
* topology node parameters to use when it is create
|
|
|
|
*
|
|
|
|
* @param ACCESS_MASK DesiredAccess
|
|
|
|
* Desrided access
|
|
|
|
*
|
|
|
|
* @param PHANDLE NodeHandle
|
|
|
|
* Location for the topology node handle
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Return NTSTATUS error code or sussess code.
|
|
|
|
*
|
|
|
|
* @remarks.
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
KSDDKAPI
|
2010-03-13 14:15:56 +00:00
|
|
|
DWORD
|
2008-04-17 18:01:51 +00:00
|
|
|
NTAPI
|
|
|
|
KsCreateTopologyNode(HANDLE ParentHandle,
|
|
|
|
PKSNODE_CREATE NodeCreate,
|
|
|
|
IN ACCESS_MASK DesiredAccess,
|
|
|
|
OUT PHANDLE NodeHandle)
|
|
|
|
{
|
|
|
|
return KsiCreateObjectType( ParentHandle,
|
|
|
|
KSSTRING_TopologyNode,
|
|
|
|
(PVOID) NodeCreate,
|
|
|
|
sizeof(KSNODE_CREATE),
|
|
|
|
DesiredAccess,
|
|
|
|
NodeHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
DllMain(HANDLE hModule, DWORD ulreason, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
switch (ulreason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2008-04-17 13:45:02 +00:00
|
|
|
}
|