Author: ion
Date: Fri Jul 22 08:59:27 2011
New Revision: 52776
URL:
http://svn.reactos.org/svn/reactos?rev=52776&view=rev
Log:
[KERNEL32]: Add a macro function that automatically takes care of A->W conversion for
Win32->NT Object Create APIs, and does AllTheRightStuff.
[KERNEL32]: Fix bug #1: CreateFileMappingA was not returning the right error if the file
mapping name was too long. By making it use the new ConvertWin32AnsiObjectApiToUnicodeApi
macro, it now does.
Added:
trunk/reactos/dll/win32/kernel32/include/base_x.h (with props)
Modified:
trunk/reactos/dll/win32/kernel32/client/file/filemap.c
trunk/reactos/dll/win32/kernel32/include/kernel32.h
trunk/reactos/dll/win32/kernel32/k32.h
Modified: trunk/reactos/dll/win32/kernel32/client/file/filemap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/file/filemap.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/file/filemap.c [iso-8859-1] Fri Jul 22
08:59:27 2011
@@ -27,38 +27,14 @@
IN DWORD dwMaximumSizeLow,
IN LPCSTR lpName)
{
- 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 version */
- return CreateFileMappingW(hFile,
- lpFileMappingAttributes,
- flProtect,
- dwMaximumSizeHigh,
- dwMaximumSizeLow,
- UnicodeName);
+ /* Call the W(ide) function */
+ ConvertWin32AnsiObjectApiToUnicodeApi(FileMapping,
+ lpName,
+ hFile,
+ lpFileMappingAttributes,
+ flProtect,
+ dwMaximumSizeHigh,
+ dwMaximumSizeLow);
}
/*
Added: 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 (added)
+++ trunk/reactos/dll/win32/kernel32/include/base_x.h [iso-8859-1] Fri Jul 22 08:59:27
2011
@@ -1,0 +1,52 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS System Libraries
+ * FILE: dll/win32/kernel32/include/base_x.h
+ * PURPOSE: Base API Client Macros
+ * PROGRAMMER: Alex Ionescu (alex(a)relsoft.net)
+ */
+
+#pragma once
+
+/* INCLUDES *******************************************************************/
+
+//
+// This macro (split it up in 3 pieces to allow for intermediary code in between)
+// converts a NULL-terminated ASCII string, usually associated with an object
+// name, into its NT-native UNICODE_STRING structure, by using the TEB's Static
+// Unicode String.
+//
+// It should only be used when the name is supposed to be less than MAX_PATH
+// (260 characters).
+//
+// It returns the correct ERROR_FILENAME_EXCED_RANGE Win32 error when the path
+// is too long.
+//
+#define ConvertAnsiToUnicodePrologue \
+{ \
+ NTSTATUS Status; \
+ PUNICODE_STRING UnicodeCache; \
+ ANSI_STRING AnsiName;
+#define ConvertAnsiToUnicodeBody(name) \
+ UnicodeCache = &NtCurrentTeb()->StaticUnicodeString; \
+ RtlInitAnsiString(&AnsiName, name); \
+ Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
+#define ConvertAnsiToUnicodeEpilogue \
+ if (Status == STATUS_BUFFER_OVERFLOW) \
+ SetLastError(ERROR_FILENAME_EXCED_RANGE); \
+ else \
+ SetLastErrorByStatus(Status); \
+ return FALSE; \
+}
+
+//
+// This macro uses the ConvertAnsiToUnicode macros above to convert a CreateXxxA
+// Win32 API into its equivalent CreateXxxW API.
+//
+#define ConvertWin32AnsiObjectApiToUnicodeApi(obj, name, args...) \
+ ConvertAnsiToUnicodePrologue \
+ if (!name) return Create##obj##W(args, NULL); \
+ ConvertAnsiToUnicodeBody(name) \
+ if (NT_SUCCESS(Status)) return Create##obj##W(args, UnicodeCache->Buffer); \
+ ConvertAnsiToUnicodeEpilogue
+
Propchange: trunk/reactos/dll/win32/kernel32/include/base_x.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/dll/win32/kernel32/include/kernel32.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] Fri Jul 22 08:59:27
2011
@@ -20,6 +20,10 @@
#define WARN(fmt, ...) WARN__(gDebugChannel, fmt, ##__VA_ARGS__)
#define FIXME(fmt, ...) WARN__(gDebugChannel, fmt,## __VA_ARGS__)
#define ERR(fmt, ...) ERR__(gDebugChannel, fmt, ##__VA_ARGS__)
+
+#define STUB \
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED); \
+ DPRINT1("%s() is UNIMPLEMENTED!\n", __FUNCTION__)
#define debugstr_a
#define debugstr_w
Modified: trunk/reactos/dll/win32/kernel32/k32.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/k32.h?r…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/k32.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/k32.h [iso-8859-1] Fri Jul 22 08:59:27 2011
@@ -42,8 +42,7 @@
/* PSEH for SEH Support */
#include <pseh/pseh2.h>
-#define STUB \
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED); \
- DPRINT1("%s() is UNIMPLEMENTED!\n", __FUNCTION__)
+/* Base Macros */
+#include "include/base_x.h"
#endif