[KERNEL32]
authorPierre Schweitzer <pierre@reactos.org>
Tue, 23 Nov 2010 23:39:58 +0000 (23:39 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Tue, 23 Nov 2010 23:39:58 +0000 (23:39 +0000)
- 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=49761

reactos/dll/win32/kernel32/include/kernel32.h
reactos/dll/win32/kernel32/kernel32.def
reactos/dll/win32/kernel32/misc/env.c
reactos/dll/win32/kernel32/misc/error.c
reactos/dll/win32/kernel32/misc/ldr.c
reactos/dll/win32/kernel32/misc/utils.c
reactos/dll/win32/kernel32/process/procsup.c

index fae3e84..8229e14 100755 (executable)
@@ -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);
index f0130a9..1dd6b5e 100644 (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
 @ 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)
index b132abf..3ff452b 100644 (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
  */
 
 /* 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
  */
index 9149953..b742d82 100644 (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 */
index 9e32478..da2f582 100644 (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);
 }
 
 
index 5e2508e..9fdde35 100644 (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);
-    
+    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);
+        BaseSetLastNTError(Status);
         return NULL;
     }
-    
-    /* Return pointer to the string */
+
     return StaticString;
 }
 
index 2afb4e0..fc46488 100644 (file)
@@ -1558,7 +1558,7 @@ CreateProcessInternalA(HANDLE hToken,
             NtCurrentTeb()->StaticUnicodeString.MaximumLength)
         {
             /* Cache it in the TEB */
-            CommandLine = Basep8BitStringToCachedUnicodeString(lpCommandLine);
+            CommandLine = Basep8BitStringToStaticUnicodeString(lpCommandLine);
         }
         else
         {