[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.

svn path=/trunk/; revision=52776
This commit is contained in:
Alex Ionescu
2011-07-22 08:59:27 +00:00
parent cb26a7762f
commit d19dfaa93c
4 changed files with 66 additions and 35 deletions
@@ -27,38 +27,14 @@ CreateFileMappingA(IN HANDLE hFile,
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);
}
/*
@@ -0,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 ([email protected])
*/
#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
@@ -21,6 +21,10 @@
#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
#define wine_dbgstr_w
+2 -3
View File
@@ -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