Author: ion
Date: Sat Jul 23 00:28:33 2011
New Revision: 52785
URL: http://svn.reactos.org/svn/reactos?rev=52785&view=rev
Log:
[KERNEL32]: New macro, not yet used. This one implements the CreateXxxW APIs
(or rather, will).
Modified:
trunk/reactos/dll/win32/kernel32/include/base_x.h
Modified: trunk/reactos/dll/win32/kernel32/include/base_x.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include/base_x.h?rev=52785&r1=52784&r2=52785&view=diff
==============================================================================
--- 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
00:28:33 2011
@@ -68,3 +68,51 @@
if (NT_SUCCESS(Status)) return obj##W(UnicodeCache->Buffer, args);
\
ConvertAnsiToUnicodeEpilogue
+//
+// This macro (split it up in 3 pieces to allow for intermediary code in
between)
+// wraps the usual code path required to create an NT object based on a Unicode
+// (Wide) Win32 object creation API.
+//
+// It makes use of BasepConvertObjectAttributes and allows for a custom access
+// mode to be used, and also sets the correct error codes in case of a
collision
+//
+#define CreateNtObjectFromWin32ApiPrologue(sec, name)
\
+{
\
+ NTSTATUS Status;
\
+ OBJECT_ATTRIBUTES LocalAttributes;
\
+ POBJECT_ATTRIBUTES ObjectAttributes;
\
+ HANDLE Handle;
\
+ UNICODE_STRING ObjectName;
\
+ if (name) RtlInitUnicodeString(&ObjectName, name);
\
+ ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes,
\
+ sec,
\
+ name ? &ObjectName : NULL);
+#define CreateNtObjectFromWin32ApiBody(ntobj, access, args...)
\
+ Status = NtCreate##ntobj(&Handle, access, ObjectAttributes, args);
+#define CreateNtObjectFromWin32ApiEpilogue
\
+ if (NT_SUCCESS(Status))
\
+ {
\
+ if (Status == STATUS_OBJECT_NAME_EXISTS)
\
+ SetLastError(ERROR_ALREADY_EXISTS);
\
+ else
\
+ SetLastError(ERROR_SUCCESS);
\
+ return Handle;
\
+ }
\
+ SetLastErrorByStatus(Status);
\
+ return NULL;
\
+}
+
+//
+// This macro uses the CreateNtObjectFromWin32Api macros from above to create
an
+// NT object based on the Win32 API settings.
+//
+// Note that it is hardcoded to always use XXX_ALL_ACCESS permissions, which is
+// the behavior up until Vista. When/if the target moves to Vista, the macro
can
+// be improved to support caller-specified access masks, as the underlying
macro
+// above does support this.
+//
+#define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name, args...)
\
+ CreateNtObjectFromWin32ApiPrologue(sec, name);
\
+ CreateNtObjectFromWin32ApiBody(ntobj, capsobj##_ALL_ACCESS, args);
\
+ CreateNtObjectFromWin32ApiEpilogue
+