[kernel32]
[reactos.git] / reactos / dll / win32 / kernel32 / misc / utils.c
index dc663f0..cebd500 100644 (file)
@@ -11,8 +11,6 @@
 #include <k32.h>
 #ifdef _M_IX86
 #include "i386/ketypes.h"
-#elif defined _M_AMD64
-#include "amd64/ketypes.h"
 #endif
 
 #define NDEBUG
@@ -28,7 +26,7 @@ PRTL_CONVERT_STRING Basep8BitStringToUnicodeString;
  * Converts an ANSI or OEM String to the specified Unicode String
  */
 NTSTATUS
-STDCALL
+WINAPI
 Basep8BitStringToLiveUnicodeString(OUT PUNICODE_STRING UnicodeString,
                                    IN LPCSTR String)
 {
@@ -56,7 +54,7 @@ Basep8BitStringToLiveUnicodeString(OUT PUNICODE_STRING UnicodeString,
  * Converts an ANSI or OEM String to the TEB StaticUnicodeString
  */
 PUNICODE_STRING
-STDCALL
+WINAPI
 Basep8BitStringToCachedUnicodeString(IN LPCSTR String)
 {
     PUNICODE_STRING StaticString = &NtCurrentTeb()->StaticUnicodeString;
@@ -83,7 +81,7 @@ Basep8BitStringToCachedUnicodeString(IN LPCSTR String)
 }
 
 NTSTATUS
-STDCALL
+WINAPI
 Basep8BitStringToHeapUnicodeString(OUT PUNICODE_STRING UnicodeString,
                                    IN LPCSTR String)
 {
@@ -111,7 +109,7 @@ Basep8BitStringToHeapUnicodeString(OUT PUNICODE_STRING UnicodeString,
  * Allocates space from the Heap and converts an Ansi String into it
  */
 VOID
-STDCALL
+WINAPI
 BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString,
                                    OUT LPWSTR* UnicodeString)
 {
@@ -139,7 +137,7 @@ BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString,
  * Converts lpSecurityAttributes + Object Name into ObjectAttributes.
  */
 POBJECT_ATTRIBUTES
-STDCALL
+WINAPI
 BasepConvertObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes,
                              IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL,
                              IN PUNICODE_STRING ObjectName)
@@ -189,7 +187,7 @@ BasepConvertObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes,
  * Creates a stack for a thread or fiber
  */
 NTSTATUS
-STDCALL
+WINAPI
 BasepCreateStack(HANDLE hProcess,
                  ULONG StackReserve,
                  ULONG StackCommit,
@@ -259,6 +257,8 @@ BasepCreateStack(HANDLE hProcess,
     /* Now set up some basic Initial TEB Parameters */
     InitialTeb->AllocatedStackBase = (PVOID)Stack;
     InitialTeb->StackBase = (PVOID)(Stack + StackReserve);
+    InitialTeb->PreviousStackBase = NULL;
+    InitialTeb->PreviousStackLimit = NULL;
     
     /* Update the Stack Position */
     Stack += StackReserve - StackCommit;
@@ -314,7 +314,7 @@ BasepCreateStack(HANDLE hProcess,
 }
 
 VOID
-STDCALL
+WINAPI
 BasepFreeStack(HANDLE hProcess,
                PINITIAL_TEB InitialTeb)
 {
@@ -331,14 +331,14 @@ BasepFreeStack(HANDLE hProcess,
  * Creates the Initial Context for a Thread or Fiber
  */
 VOID
-STDCALL
+WINAPI
 BasepInitializeContext(IN PCONTEXT Context,
                        IN PVOID Parameter,
                        IN PVOID StartAddress,
                        IN PVOID StackAddress,
                        IN ULONG ContextType)
 {
-#ifdef __i386__
+#ifdef _M_IX86
     DPRINT("BasepInitializeContext: %p\n", Context);
     
     /* Setup the Initial Win32 Thread Context */
@@ -364,7 +364,7 @@ BasepInitializeContext(IN PCONTEXT Context,
     }
     else if (ContextType == 2) /* For Fibers */
     {
-        Context->Eip = (ULONG)BaseFiberStartup;
+        //Context->Eip = (ULONG)BaseFiberStartup;
     }
     else                       /* For first thread in a Process */
     {
@@ -376,44 +376,6 @@ BasepInitializeContext(IN PCONTEXT Context,
     
     /* Give it some room for the Parameter */
     Context->Esp -= sizeof(PVOID);
-#elif defined(__x86_64__)
-    DPRINT("BasepInitializeContext: %p\n", Context);
-    
-    /* Setup the Initial Win32 Thread Context */
-    Context->Rax = (ULONG_PTR)StartAddress;
-    Context->Rbx = (ULONG_PTR)Parameter;
-    Context->Rsp = (ULONG_PTR)StackAddress;
-    /* The other registers are undefined */
-
-    /* Setup the Segments */
-    Context->SegFs = KGDT_R3_TEB | RPL_MASK;
-    Context->SegEs = KGDT_R3_DATA | RPL_MASK;
-    Context->SegDs = KGDT_R3_DATA | RPL_MASK;
-    Context->SegCs = KGDT_R3_CODE | RPL_MASK;
-    Context->SegSs = KGDT_R3_DATA | RPL_MASK;
-    Context->SegGs = 0;
-
-    /* Set the EFLAGS */
-    Context->EFlags = 0x3000; /* IOPL 3 */
-
-    if (ContextType == 1)      /* For Threads */
-    {
-        Context->Rip = (ULONG_PTR)BaseThreadStartupThunk;
-    }
-    else if (ContextType == 2) /* For Fibers */
-    {
-        Context->Rip = (ULONG_PTR)BaseFiberStartup;
-    }
-    else                       /* For first thread in a Process */
-    {
-        Context->Rip = (ULONG_PTR)BaseProcessStartThunk;
-    }
-    
-    /* Set the Context Flags */
-    Context->ContextFlags = CONTEXT_FULL;
-    
-    /* Give it some room for the Parameter */
-    Context->Rsp -= sizeof(PVOID);
 #else
 #warning Unknown architecture
     UNIMPLEMENTED;
@@ -425,7 +387,7 @@ BasepInitializeContext(IN PCONTEXT Context,
  * Checks if the privilege for Real-Time Priority is there
  */
 BOOLEAN
-STDCALL
+WINAPI
 BasepCheckRealTimePrivilege(VOID)
 {
     return TRUE;
@@ -435,7 +397,7 @@ BasepCheckRealTimePrivilege(VOID)
  * Maps an image file into a section
  */
 NTSTATUS
-STDCALL
+WINAPI
 BasepMapFile(IN LPCWSTR lpApplicationName,
              OUT PHANDLE hSection,
              IN PUNICODE_STRING ApplicationName)
@@ -452,10 +414,14 @@ BasepMapFile(IN LPCWSTR lpApplicationName,
     RelativeName.Handle = NULL;
 
     /* Find the application name */
-    RtlDosPathNameToNtPathName_U(lpApplicationName,
-                                 ApplicationName,
-                                 NULL,
-                                 &RelativeName);
+    if (!RtlDosPathNameToNtPathName_U(lpApplicationName,
+                                      ApplicationName,
+                                      NULL,
+                                      &RelativeName))
+    {
+        return STATUS_OBJECT_PATH_NOT_FOUND;
+    }
+
     DPRINT("ApplicationName %wZ\n", ApplicationName);
     DPRINT("RelativeName %wZ\n", &RelativeName.DosPath);
     
@@ -482,7 +448,7 @@ BasepMapFile(IN LPCWSTR lpApplicationName,
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to open file\n");
-        SetLastErrorByStatus (Status);
+        SetLastErrorByStatus(Status);
         return Status;
     }