/*
- * KSUSER.DLL - ReactOS
- *
- * Copyright 2008 Magnus Olsen and Dmitry Chapyshev
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ * 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
*/
-
#include "ksuser.h"
#define NDEBUG
#include <debug.h>
-NTSTATUS NTAPI KsiCreateObjectType( HANDLE hHandle, PVOID guidstr, PVOID Buffer, ULONG BufferSize, ACCESS_MASK DesiredAccess, PHANDLE phHandle);
-
NTSTATUS
NTAPI
KsiCreateObjectType( HANDLE hHandle,
- PVOID IID,
+ LPWSTR ObjectType,
PVOID Buffer,
ULONG BufferSize,
ACCESS_MASK DesiredAccess,
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
- Length = wcslen(IID);
+ /* get length of object type */
+ Length = wcslen(ObjectType);
+
+ /* get length for request */
+ TotalSize = (Length * sizeof(WCHAR)) + BufferSize;
- TotalSize = (Length * sizeof(WCHAR)) + BufferSize + 4 * sizeof(WCHAR);
+ /* append space for '\\'*/
+ TotalSize += sizeof(WCHAR);
+ /* allocate buffer */
pStr = HeapAlloc(GetProcessHeap(), 0, TotalSize);
if (!pStr)
- return STATUS_INSUFFICIENT_RESOURCES;
- pStr[0] = L'\\';
- wcscpy(&pStr[1], (LPWSTR)IID);
- pStr[Length+1] = L'\\';
- memcpy(&pStr[Length+2], Buffer, BufferSize);
- pStr[Length+3+(BufferSize/sizeof(WCHAR))] = L'\0';
+ {
+ /* out of memory */
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
+
+ /* copy object type */
+ wcscpy(pStr, ObjectType);
- RtlInitUnicodeString(&ObjectName, pStr);
+ /* append slash */
+ pStr[Length] = L'\\';
+
+ /* append parameters */
+ memcpy(&pStr[Length+1], Buffer, BufferSize);
+
+ /* initialize object name */
+ ObjectName.Buffer = pStr;
ObjectName.Length = ObjectName.MaximumLength = TotalSize;
+ /* initialize object attributes */
InitializeObjectAttributes(&ObjectAttributes, &ObjectName, OBJ_CASE_INSENSITIVE, hHandle, NULL);
+ /* create the object */
Status = NtCreateFile(phHandle, DesiredAccess, &ObjectAttributes, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, 0, 1, 0, NULL, 0);
+
+ /* free buffer */
HeapFree(GetProcessHeap(), 0, pStr);
+
+ /* check for success */
if (!NT_SUCCESS(Status))
{
+ /* failed zero handle */
*phHandle = INVALID_HANDLE_VALUE;
+
+ /* convert error code */
Status = RtlNtStatusToDosError(Status);
}
+
+ /* done */
return Status;
}
PLIST_ENTRY Entry;
PCREATE_ITEM_ENTRY CreateItemEntry;
UNICODE_STRING RefString;
+ LPWSTR pStr;
+ /* get terminator */
+ pStr = wcschr(Buffer, L'\\');
-#ifndef MS_KSUSER
- /* remove '\' slash */
- Buffer++;
- BufferSize -= sizeof(WCHAR);
-#endif
+ /* sanity check */
+ ASSERT(pStr != NULL);
- if (!wcschr(Buffer, L'\\'))
+ if (pStr == Buffer)
{
- RtlInitUnicodeString(&RefString, Buffer);
+ // skip slash
+ RtlInitUnicodeString(&RefString, ++pStr);
}
else
{
+ // request is for pin / node / allocator
RefString.Buffer = Buffer;
- RefString.Length = RefString.MaximumLength = ((ULONG_PTR)wcschr(Buffer, L'\\') - (ULONG_PTR)Buffer);
+ RefString.Length = BufferSize = RefString.MaximumLength = ((ULONG_PTR)pStr - (ULONG_PTR)Buffer);
}
/* point to first entry */
/* calculate request length */
Name.Length = 0;
- Name.MaximumLength = wcslen(ObjectType) * sizeof(WCHAR) + CreateParametersSize + 2 * sizeof(WCHAR);
+ Name.MaximumLength = wcslen(ObjectType) * sizeof(WCHAR) + CreateParametersSize + 1 * sizeof(WCHAR);
Name.MaximumLength += sizeof(WCHAR);
/* acquire request buffer */
Name.Buffer = AllocateItem(NonPagedPool, Name.MaximumLength);
* For pins the parent is the reference string used in registration
* For clocks it is full path for pin\{ClockGuid}\ClockCreateParams
*/
- RtlAppendUnicodeToString(&Name, L"\\");
RtlAppendUnicodeToString(&Name, ObjectType);
RtlAppendUnicodeToString(&Name, L"\\");
/* append create parameters */