- Revert 49767 on Pierre's request, which reverted this:

- Added real implementation of SetLastError() (instead of forwarding to NTDLL)
- Implemented BaseSetLastNTError()
- Renamed Basep8BitStringToCachedUnicodeString() to Basep8BitStringToStaticUnicodeString() and sightly changed its implementation
- Fixed implementation of LoadLibraryExA() & DisableThreadLibraryCalls() using those changes
This is matching w2k3 implementation. This is of course a WIP.

svn path=/trunk/; revision=50819
This commit is contained in:
Johannes Anderwald 2011-02-19 17:00:08 +00:00
parent 4638bf943c
commit 634966f644
7 changed files with 144 additions and 117 deletions

View file

@ -69,7 +69,6 @@
#define SetLastErrorByStatus(x) RtlSetLastWin32ErrorAndNtStatusFromNtStatus((x))
#define GetLastError() NtCurrentTeb()->LastErrorValue
#define SetLastError(x) NtCurrentTeb()->LastErrorValue = (x)
typedef struct _CODEPAGE_ENTRY
{
@ -192,7 +191,7 @@ BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString,
PUNICODE_STRING
WINAPI
Basep8BitStringToCachedUnicodeString(IN LPCSTR String);
Basep8BitStringToStaticUnicodeString(IN LPCSTR AnsiString);
NTSTATUS
WINAPI
@ -225,3 +224,7 @@ GetDllLoadPath(LPCWSTR lpModule);
VOID
WINAPI
InitCommandLines(VOID);
VOID
WINAPI
BaseSetLastNTError(IN NTSTATUS Status);

View file

@ -46,7 +46,7 @@
@ stdcall BaseProcessInitPostImport() ; missing in Win 7
@ stdcall BaseQueryModuleData(str str ptr ptr ptr) ;check
;@ stdcall BaseThreadInitThunk ; Win 7
;@ stdcall BaseSetLastNTError ; Win 7, not 64 bit
;@ stdcall BaseSetLastNTError ; Win 7, not 64 bit (present on w2k3 but not exported)
@ stdcall BaseUpdateAppcompatCache(long long long)
;@ stdcall BaseVerifyUnicodeString ; Win 7
;@ stdcall Basep8BitStringToDynamicUnicodeString ; Win 7
@ -1211,7 +1211,7 @@
@ stdcall SetHandleInformation(long long long)
@ stdcall SetInformationJobObject(long long ptr long)
@ stub SetLastConsoleEventActive ; missing in XP SP3
@ stdcall SetLastError(long) ntdll.RtlSetLastWin32Error
@ stdcall SetLastError(long)
@ stub SetLocalPrimaryComputerNameA ; missing in XP SP3
@ stub SetLocalPrimaryComputerNameW ; missing in XP SP3
@ stdcall SetLocalTime(ptr)

View file

@ -5,6 +5,8 @@
* FILE: lib/kernel32/misc/env.c
* PURPOSE: Environment functions
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
* Emanuele Aliberti
* Thomas Weidenmueller
* UPDATE HISTORY:
* Created 01/11/98
*/
@ -17,6 +19,85 @@
/* FUNCTIONS ******************************************************************/
/*
* @implemented
*/
BOOL
WINAPI
Beep (DWORD dwFreq, DWORD dwDuration)
{
HANDLE hBeep;
UNICODE_STRING BeepDevice;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
BEEP_SET_PARAMETERS BeepSetParameters;
NTSTATUS Status;
/* check the parameters */
if ((dwFreq >= 0x25 && dwFreq <= 0x7FFF) ||
(dwFreq == 0x0 && dwDuration == 0x0))
{
/* open the device */
RtlInitUnicodeString(&BeepDevice,
L"\\Device\\Beep");
InitializeObjectAttributes(&ObjectAttributes,
&BeepDevice,
0,
NULL,
NULL);
Status = NtCreateFile(&hBeep,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatusBlock,
NULL,
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN_IF,
0,
NULL,
0);
if (NT_SUCCESS(Status))
{
/* Set beep data */
BeepSetParameters.Frequency = dwFreq;
BeepSetParameters.Duration = dwDuration;
Status = NtDeviceIoControlFile(hBeep,
NULL,
NULL,
NULL,
&IoStatusBlock,
IOCTL_BEEP_SET,
&BeepSetParameters,
sizeof(BEEP_SET_PARAMETERS),
NULL,
0);
/* do an alertable wait if necessary */
if (NT_SUCCESS(Status) &&
(dwFreq != 0x0 || dwDuration != 0x0) && dwDuration != MAXDWORD)
{
SleepEx(dwDuration,
TRUE);
}
NtClose(hBeep);
}
}
else
Status = STATUS_INVALID_PARAMETER;
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return FALSE;
}
return TRUE;
}
/*
* @implemented
*/

View file

@ -1,99 +1,45 @@
/* $Id$
*
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: dll/win32/kernel32/misc/error.c
* PURPOSE: Environment functions
* PROGRAMMER: Emanuele Aliberti
* Thomas Weidenmueller
* UPDATE HISTORY:
* Created 05/10/98
* PURPOSE: Error functions
* PROGRAMMER: Pierre Schweitzer (pierre.schweitzer@reactos.org)
*/
#include <k32.h>
#define NDEBUG
#include <debug.h>
/*
* @implemented
*/
BOOL
DWORD g_dwLastErrorToBreakOn;
/* FUNCTIONS ******************************************************************/
VOID
WINAPI
Beep (DWORD dwFreq, DWORD dwDuration)
SetLastError(
IN DWORD dwErrCode)
{
HANDLE hBeep;
UNICODE_STRING BeepDevice;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
BEEP_SET_PARAMETERS BeepSetParameters;
NTSTATUS Status;
/* check the parameters */
if ((dwFreq >= 0x25 && dwFreq <= 0x7FFF) ||
(dwFreq == 0x0 && dwDuration == 0x0))
if (g_dwLastErrorToBreakOn)
{
/* open the device */
RtlInitUnicodeString(&BeepDevice,
L"\\Device\\Beep");
InitializeObjectAttributes(&ObjectAttributes,
&BeepDevice,
0,
NULL,
NULL);
Status = NtCreateFile(&hBeep,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatusBlock,
NULL,
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN_IF,
0,
NULL,
0);
if (NT_SUCCESS(Status))
/* If we have error to break on and if current matches, break */
if (g_dwLastErrorToBreakOn == dwErrCode)
{
/* Set beep data */
BeepSetParameters.Frequency = dwFreq;
BeepSetParameters.Duration = dwDuration;
Status = NtDeviceIoControlFile(hBeep,
NULL,
NULL,
NULL,
&IoStatusBlock,
IOCTL_BEEP_SET,
&BeepSetParameters,
sizeof(BEEP_SET_PARAMETERS),
NULL,
0);
/* do an alertable wait if necessary */
if (NT_SUCCESS(Status) &&
(dwFreq != 0x0 || dwDuration != 0x0) && dwDuration != MAXDWORD)
{
SleepEx(dwDuration,
TRUE);
}
NtClose(hBeep);
DbgBreakPoint();
}
}
else
Status = STATUS_INVALID_PARAMETER;
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return FALSE;
}
/* Set last error */
NtCurrentTeb()->LastErrorValue = dwErrCode;
}
return TRUE;
VOID
WINAPI
BaseSetLastNTError(
IN NTSTATUS Status)
{
SetLastError(RtlNtStatusToDosError(Status));
}
/* EOF */

View file

@ -102,19 +102,18 @@ GetDllLoadPath(LPCWSTR lpModule)
*/
BOOL
WINAPI
DisableThreadLibraryCalls (
HMODULE hLibModule
)
DisableThreadLibraryCalls(
IN HMODULE hLibModule)
{
NTSTATUS Status;
NTSTATUS Status;
Status = LdrDisableThreadCalloutsForDll ((PVOID)hLibModule);
if (!NT_SUCCESS (Status))
{
SetLastErrorByStatus (Status);
return FALSE;
}
return TRUE;
Status = LdrDisableThreadCalloutsForDll((PVOID)hLibModule);
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return FALSE;
}
return TRUE;
}
@ -136,18 +135,17 @@ LoadLibraryA (
*/
HINSTANCE
WINAPI
LoadLibraryExA (
LPCSTR lpLibFileName,
HANDLE hFile,
DWORD dwFlags
)
LoadLibraryExA(
LPCSTR lpLibFileName,
HANDLE hFile,
DWORD dwFlags)
{
PWCHAR FileNameW;
PUNICODE_STRING FileNameW;
if (!(FileNameW = FilenameA2W(lpLibFileName, FALSE)))
return FALSE;
if (!(FileNameW = Basep8BitStringToStaticUnicodeString(lpLibFileName)))
return NULL;
return LoadLibraryExW(FileNameW, hFile, dwFlags);
return LoadLibraryExW(FileNameW->Buffer, hFile, dwFlags);
}

View file

@ -57,28 +57,27 @@ Basep8BitStringToLiveUnicodeString(OUT PUNICODE_STRING UnicodeString,
*/
PUNICODE_STRING
WINAPI
Basep8BitStringToCachedUnicodeString(IN LPCSTR String)
Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
{
PUNICODE_STRING StaticString = &NtCurrentTeb()->StaticUnicodeString;
PUNICODE_STRING StaticString = &(NtCurrentTeb()->StaticUnicodeString);
ANSI_STRING AnsiString;
NTSTATUS Status;
DPRINT("Basep8BitStringToCachedUnicodeString\n");
/* Initialize an ANSI String */
RtlInitAnsiString(&AnsiString, String);
/* Convert it */
Status = Basep8BitStringToUnicodeString(StaticString, &AnsiString, FALSE);
/* Handle failure */
if (!NT_SUCCESS(Status))
if (!NT_SUCCESS(RtlInitAnsiStringEx(&AnsiString, String)))
{
SetLastErrorByStatus(Status);
SetLastError(ERROR_FILENAME_EXCED_RANGE);
return NULL;
}
/* Return pointer to the string */
/* Convert it */
Status = Basep8BitStringToUnicodeString(StaticString, &AnsiString, FALSE);
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return NULL;
}
return StaticString;
}

View file

@ -1558,7 +1558,7 @@ CreateProcessInternalA(HANDLE hToken,
NtCurrentTeb()->StaticUnicodeString.MaximumLength)
{
/* Cache it in the TEB */
CommandLine = Basep8BitStringToCachedUnicodeString(lpCommandLine);
CommandLine = Basep8BitStringToStaticUnicodeString(lpCommandLine);
}
else
{