Author: janderwald
Date: Sat Feb 19 17:00:08 2011
New Revision: 50819
URL:
http://svn.reactos.org/svn/reactos?rev=50819&view=rev
Log:
- 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.
Modified:
trunk/reactos/dll/win32/kernel32/include/kernel32.h
trunk/reactos/dll/win32/kernel32/kernel32.def
trunk/reactos/dll/win32/kernel32/misc/env.c
trunk/reactos/dll/win32/kernel32/misc/error.c
trunk/reactos/dll/win32/kernel32/misc/ldr.c
trunk/reactos/dll/win32/kernel32/misc/utils.c
trunk/reactos/dll/win32/kernel32/process/procsup.c
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] Sat Feb 19 17:00:08
2011
@@ -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 @@
PUNICODE_STRING
WINAPI
-Basep8BitStringToCachedUnicodeString(IN LPCSTR String);
+Basep8BitStringToStaticUnicodeString(IN LPCSTR AnsiString);
NTSTATUS
WINAPI
@@ -225,3 +224,7 @@
VOID
WINAPI
InitCommandLines(VOID);
+
+VOID
+WINAPI
+BaseSetLastNTError(IN NTSTATUS Status);
Modified: trunk/reactos/dll/win32/kernel32/kernel32.def
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/kernel3…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/kernel32.def [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/kernel32.def [iso-8859-1] Sat Feb 19 17:00:08 2011
@@ -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)
Modified: trunk/reactos/dll/win32/kernel32/misc/env.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/en…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/env.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/env.c [iso-8859-1] Sat Feb 19 17:00:08 2011
@@ -5,6 +5,8 @@
* FILE: lib/kernel32/misc/env.c
* PURPOSE: Environment functions
* PROGRAMMER: Ariadne ( ariadne(a)xs4all.nl)
+ * Emanuele Aliberti
+ * Thomas Weidenmueller
* UPDATE HISTORY:
* Created 01/11/98
*/
@@ -16,6 +18,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
Modified: trunk/reactos/dll/win32/kernel32/misc/error.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/er…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/error.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/error.c [iso-8859-1] Sat Feb 19 17:00:08 2011
@@ -1,15 +1,10 @@
-/* $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(a)reactos.org)
*/
-
#include <k32.h>
@@ -17,83 +12,34 @@
#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 */
Modified: trunk/reactos/dll/win32/kernel32/misc/ldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/ld…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] Sat Feb 19 17:00:08 2011
@@ -102,19 +102,18 @@
*/
BOOL
WINAPI
-DisableThreadLibraryCalls (
- HMODULE hLibModule
- )
-{
- NTSTATUS Status;
-
- Status = LdrDisableThreadCalloutsForDll ((PVOID)hLibModule);
- if (!NT_SUCCESS (Status))
- {
- SetLastErrorByStatus (Status);
- return FALSE;
- }
- return TRUE;
+DisableThreadLibraryCalls(
+ IN HMODULE hLibModule)
+{
+ NTSTATUS Status;
+
+ Status = LdrDisableThreadCalloutsForDll((PVOID)hLibModule);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ return FALSE;
+ }
+ return TRUE;
}
@@ -136,18 +135,17 @@
*/
HINSTANCE
WINAPI
-LoadLibraryExA (
- LPCSTR lpLibFileName,
- HANDLE hFile,
- DWORD dwFlags
- )
-{
- PWCHAR FileNameW;
-
- if (!(FileNameW = FilenameA2W(lpLibFileName, FALSE)))
- return FALSE;
-
- return LoadLibraryExW(FileNameW, hFile, dwFlags);
+LoadLibraryExA(
+ LPCSTR lpLibFileName,
+ HANDLE hFile,
+ DWORD dwFlags)
+{
+ PUNICODE_STRING FileNameW;
+
+ if (!(FileNameW = Basep8BitStringToStaticUnicodeString(lpLibFileName)))
+ return NULL;
+
+ return LoadLibraryExW(FileNameW->Buffer, hFile, dwFlags);
}
Modified: trunk/reactos/dll/win32/kernel32/misc/utils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/ut…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/utils.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/utils.c [iso-8859-1] Sat Feb 19 17:00:08 2011
@@ -57,28 +57,27 @@
*/
PUNICODE_STRING
WINAPI
-Basep8BitStringToCachedUnicodeString(IN LPCSTR String)
-{
- PUNICODE_STRING StaticString = &NtCurrentTeb()->StaticUnicodeString;
+Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
+{
+ PUNICODE_STRING StaticString = &(NtCurrentTeb()->StaticUnicodeString);
ANSI_STRING AnsiString;
NTSTATUS Status;
-
- DPRINT("Basep8BitStringToCachedUnicodeString\n");
-
+
/* Initialize an ANSI String */
- RtlInitAnsiString(&AnsiString, String);
-
+ if (!NT_SUCCESS(RtlInitAnsiStringEx(&AnsiString, String)))
+ {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return NULL;
+ }
+
/* Convert it */
Status = Basep8BitStringToUnicodeString(StaticString, &AnsiString, FALSE);
-
- /* Handle failure */
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
return NULL;
}
-
- /* Return pointer to the string */
+
return StaticString;
}
Modified: trunk/reactos/dll/win32/kernel32/process/procsup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/process…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/process/procsup.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/process/procsup.c [iso-8859-1] Sat Feb 19 17:00:08
2011
@@ -1558,7 +1558,7 @@
NtCurrentTeb()->StaticUnicodeString.MaximumLength)
{
/* Cache it in the TEB */
- CommandLine = Basep8BitStringToCachedUnicodeString(lpCommandLine);
+ CommandLine = Basep8BitStringToStaticUnicodeString(lpCommandLine);
}
else
{