Author: ion
Date: Sat Jul 23 09:58:33 2011
New Revision: 52791
URL:
http://svn.reactos.org/svn/reactos?rev=52791&view=rev
Log:
[KERNEL32]: Small fix to the macros (not functional, just for compiler's sake).
[KERNEL32]: Update Event APIs to use the new macros. Fixes bugs #14, #15: the create/open
ANSI APIs were not returning the right error in case of object names that were too large.
Modified:
trunk/reactos/dll/win32/kernel32/client/synch.c
trunk/reactos/dll/win32/kernel32/include/base_x.h
Modified: trunk/reactos/dll/win32/kernel32/client/synch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] Sat Jul 23 09:58:33 2011
@@ -1031,133 +1031,22 @@
return FALSE;
}
-HANDLE
-WINAPI
-CreateEventExA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL,
- IN LPCSTR lpName OPTIONAL,
- IN DWORD dwFlags,
- IN DWORD dwDesiredAccess)
-{
- NTSTATUS Status;
- ANSI_STRING AnsiName;
- PUNICODE_STRING UnicodeCache;
- LPCWSTR UnicodeName = NULL;
-
- /* Check for a name */
- if (lpName)
- {
- /* Use TEB Cache */
- UnicodeCache = &NtCurrentTeb()->StaticUnicodeString;
-
- /* Convert to unicode */
- RtlInitAnsiString(&AnsiName, lpName);
- Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
- if (!NT_SUCCESS(Status))
- {
- /* Conversion failed */
- SetLastErrorByStatus(Status);
- return NULL;
- }
-
- /* Otherwise, save the buffer */
- UnicodeName = (LPCWSTR)UnicodeCache->Buffer;
- }
-
- /* Call the Unicode API */
- return CreateEventExW(lpEventAttributes,
- UnicodeName,
- dwFlags,
- dwDesiredAccess);
-
-}
-
-HANDLE
-WINAPI
-CreateEventExW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL,
- IN LPCWSTR lpName OPTIONAL,
- IN DWORD dwFlags,
- IN DWORD dwDesiredAccess)
-{
- NTSTATUS Status;
- OBJECT_ATTRIBUTES LocalAttributes;
- POBJECT_ATTRIBUTES ObjectAttributes;
- HANDLE Handle;
- UNICODE_STRING ObjectName;
- BOOLEAN InitialState;
- EVENT_TYPE EventType;
-
- /* Now check if we got a name */
- if (lpName) RtlInitUnicodeString(&ObjectName, lpName);
-
- /* Check for invalid flags */
- if (dwFlags & ~(CREATE_EVENT_INITIAL_SET | CREATE_EVENT_MANUAL_RESET))
- {
- /* Fail */
- SetLastError(ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- /* Set initial state and event type */
- InitialState = (dwFlags & CREATE_EVENT_INITIAL_SET) ? TRUE : FALSE;
- EventType = (dwFlags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent :
SynchronizationEvent;
-
- /* Now convert the object attributes */
- ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes,
- lpEventAttributes,
- lpName ? &ObjectName : NULL);
-
- /* Create the event */
- Status = NtCreateEvent(&Handle,
- (ACCESS_MASK)dwDesiredAccess,
- ObjectAttributes,
- EventType,
- InitialState);
- if (NT_SUCCESS(Status))
- {
- /* Check if the object already existed */
- if (Status == STATUS_OBJECT_NAME_EXISTS)
- {
- /* Set distinguished Win32 error code */
- SetLastError(ERROR_ALREADY_EXISTS);
- }
- else
- {
- /* Otherwise, set success */
- SetLastError(ERROR_SUCCESS);
- }
-
- /* Return the handle */
- return Handle;
- }
- else
- {
- /* Convert the NT Status and fail */
- SetLastErrorByStatus(Status);
- return NULL;
- }
-
-}
-
+/*
+ * @implemented
+ */
HANDLE
WINAPI
CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL,
IN BOOL bManualReset,
IN BOOL bInitialState,
- IN LPCSTR lpName OPTIONAL)
-{
- DWORD dwFlags = 0;
-
- /* Set new flags */
- if (bManualReset) dwFlags |= CREATE_EVENT_MANUAL_RESET;
- if (bInitialState) dwFlags |= CREATE_EVENT_INITIAL_SET;
-
- /* Call the newer API */
- return CreateEventExA(lpEventAttributes,
- lpName,
- dwFlags,
- EVENT_ALL_ACCESS);
-}
-
+ IN LPCSTR lpName OPTIONAL)
+{
+ ConvertWin32AnsiObjectApiToUnicodeApi(Event, lpName, lpEventAttributes, bManualReset,
bInitialState);
+}
+
+/*
+ * @implemented
+ */
HANDLE
WINAPI
CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL,
@@ -1165,96 +1054,35 @@
IN BOOL bInitialState,
IN LPCWSTR lpName OPTIONAL)
{
- DWORD dwFlags = 0;
-
- /* Set new flags */
- if (bManualReset) dwFlags |= CREATE_EVENT_MANUAL_RESET;
- if (bInitialState) dwFlags |= CREATE_EVENT_INITIAL_SET;
-
- /* Call the newer API */
- return CreateEventExW(lpEventAttributes,
- lpName,
- dwFlags,
- EVENT_ALL_ACCESS);
-}
-
+ CreateNtObjectFromWin32Api(Event, Event, EVENT,
+ lpEventAttributes,
+ lpName,
+ bManualReset ? NotificationTimer : SynchronizationTimer,
+ bInitialState);
+}
+
+/*
+ * @implemented
+ */
HANDLE
WINAPI
OpenEventA(IN DWORD dwDesiredAccess,
IN BOOL bInheritHandle,
IN LPCSTR lpName)
{
- NTSTATUS Status;
- ANSI_STRING AnsiName;
- PUNICODE_STRING UnicodeCache;
-
- /* Check for a name */
- if (lpName)
- {
- /* Use TEB Cache */
- UnicodeCache = &NtCurrentTeb()->StaticUnicodeString;
-
- /* Convert to unicode */
- RtlInitAnsiString(&AnsiName, lpName);
- Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
- if (!NT_SUCCESS(Status))
- {
- /* Conversion failed */
- SetLastErrorByStatus(Status);
- return NULL;
- }
- }
- else
- {
- /* We need a name */
- SetLastError(ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- /* Call the Unicode API */
- return OpenEventW(dwDesiredAccess,
- bInheritHandle,
- (LPCWSTR)UnicodeCache->Buffer);
-}
-
+ ConvertOpenWin32AnsiObjectApiToUnicodeApi(Event, dwDesiredAccess, bInheritHandle,
lpName);
+}
+
+/*
+ * @implemented
+ */
HANDLE
WINAPI
OpenEventW(IN DWORD dwDesiredAccess,
IN BOOL bInheritHandle,
IN LPCWSTR lpName)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING ObjectName;
- NTSTATUS Status;
- HANDLE Handle;
-
- /* Make sure we got a name */
- if (!lpName)
- {
- /* Fail without one */
- SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
- return NULL;
- }
-
- /* Initialize the object name and attributes */
- RtlInitUnicodeString(&ObjectName, lpName);
- InitializeObjectAttributes(&ObjectAttributes,
- &ObjectName,
- bInheritHandle ? OBJ_INHERIT : 0,
- hBaseDir,
- NULL);
-
- /* Open the event */
- Status = NtOpenEvent(&Handle, dwDesiredAccess, &ObjectAttributes);
- if (!NT_SUCCESS(Status))
- {
- /* Convert the status and fail */
- SetLastErrorByStatus(Status);
- return NULL;
- }
-
- /* Return the handle */
- return Handle;
+ OpenNtObjectFromWin32Api(Event, dwDesiredAccess, bInheritHandle, lpName);
}
/*
Modified: trunk/reactos/dll/win32/kernel32/include/base_x.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/include/base_x.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/include/base_x.h [iso-8859-1] Sat Jul 23 09:58:33
2011
@@ -90,10 +90,10 @@
#define CreateNtObjectFromWin32ApiPrologue \
{ \
NTSTATUS Status; \
- POBJECT_ATTRIBUTES ObjectAttributes; \
HANDLE Handle; \
UNICODE_STRING ObjectName; \
- OBJECT_ATTRIBUTES LocalAttributes;
+ OBJECT_ATTRIBUTES LocalAttributes; \
+ POBJECT_ATTRIBUTES ObjectAttributes = &LocalAttributes;
#define CreateNtObjectFromWin32ApiBody(ntobj, sec, name, access, ...) \
if (name) RtlInitUnicodeString(&ObjectName, name); \
ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes, \
@@ -132,15 +132,14 @@
//
#define OpenNtObjectFromWin32Api(ntobj, acc, inh, name) \
CreateNtObjectFromWin32ApiPrologue \
- UNREFERENCED_PARAMETER(ObjectAttributes) \
if (!name) SetLastErrorByStatus(STATUS_INVALID_PARAMETER); return NULL; \
RtlInitUnicodeString(&ObjectName, name); \
- InitializeObjectAttributes(&LocalAttributes, \
+ InitializeObjectAttributes(ObjectAttributes, \
&ObjectName, \
inh ? OBJ_INHERIT : 0, \
hBaseDir, \
NULL); \
- Status = NtOpen##ntobj(&Handle, acc, &LocalAttributes);
\
+ Status = NtOpen##ntobj(&Handle, acc, ObjectAttributes); \
if (!NT_SUCCESS(Status)) SetLastErrorByStatus(Status); return NULL; \
return Handle; \
}