rasapi32: Fix tests on platforms winme and some win98.
[wine] / dlls / winedos / module.c
index b49a790..ac35e85 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  *
  * Note: This code hasn't been completely cleaned up yet.
  */
 #include "config.h"
 #include "wine/port.h"
 
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
 #include <sys/types.h>
-#include <sys/stat.h>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
 #include "windef.h"
+#include "winbase.h"
 #include "wine/winbase16.h"
 #include "wingdi.h"
 #include "winuser.h"
 #include "winerror.h"
-#include "module.h"
-#include "task.h"
-#include "file.h"
-#include "miscemu.h"
 #include "wine/debug.h"
 #include "dosexe.h"
 #include "dosvm.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(module);
 
+static BOOL DOSVM_isdosexe;
+
+/**********************************************************************
+ *          DOSVM_IsWin16
+ * 
+ * Return TRUE if we are in Windows process.
+ */
+BOOL DOSVM_IsWin16(void)
+{
+  return DOSVM_isdosexe ? FALSE : TRUE;
+}
+
 #ifdef MZ_SUPPORTED
 
 #ifdef HAVE_SYS_MMAN_H
@@ -71,11 +82,13 @@ WINE_DEFAULT_DEBUG_CHANNEL(module);
 
 /* structures for EXEC */
 
+#include "pshpack1.h"
+
 typedef struct {
   WORD env_seg;
-  DWORD cmdline WINE_PACKED;
-  DWORD fcb1 WINE_PACKED;
-  DWORD fcb2 WINE_PACKED;
+  DWORD cmdline;
+  DWORD fcb1;
+  DWORD fcb2;
   WORD init_sp;
   WORD init_ss;
   WORD init_ip;
@@ -87,6 +100,8 @@ typedef struct {
   WORD rel_seg;
 } OverlayBlock;
 
+#include "poppack.h"
+
 /* global variables */
 
 pid_t dosvm_pid;
@@ -95,7 +110,7 @@ static WORD init_cs,init_ip,init_ss,init_sp;
 static HANDLE dosvm_thread, loop_thread;
 static DWORD dosvm_tid, loop_tid;
 
-static void MZ_Launch(void);
+static void MZ_Launch( LPCSTR cmdtail, int length );
 static BOOL MZ_InitTask(void);
 
 static void MZ_CreatePSP( LPVOID lpPSP, WORD env, WORD par )
@@ -114,65 +129,38 @@ static void MZ_CreatePSP( LPVOID lpPSP, WORD env, WORD par )
   /* FIXME: more PSP stuff */
 }
 
-static void MZ_FillPSP( LPVOID lpPSP, LPBYTE cmdline, int length )
+static void MZ_FillPSP( LPVOID lpPSP, LPCSTR cmdtail, int length )
 {
-  PDB16      *psp = lpPSP;
+    PDB16 *psp = lpPSP;
 
-  while(length > 0 && *cmdline != ' ') {
-    length--;
-    cmdline++;
-  }
+    if(length > 127) 
+    {
+        WARN( "Command tail truncated! (length %d)\n", length );
+        length = 126;
+    }
 
-  /* command.com does not skip over multiple spaces */
+    psp->cmdLine[0] = length;
 
-  if(length > 126) {
-    ERR("Command line truncated! (length %d > maximum length 126)\n",
-       length);
-    length = 126;
-  }
+    /*
+     * Length of exactly 127 bytes means that full command line is 
+     * stored in environment variable CMDLINE and PSP contains 
+     * command tail truncated to 126 bytes.
+     */
+    if(length == 127)
+        length = 126;
 
-  psp->cmdLine[0] = length;
-  if(length > 0)
-    memmove(psp->cmdLine+1, cmdline, length);
-  psp->cmdLine[length+1] = '\r';
+    if(length > 0)
+        memmove(psp->cmdLine+1, cmdtail, length);
 
-  /* FIXME: more PSP stuff */
-}
+    psp->cmdLine[length+1] = '\r';
 
-/* default INT 08 handler: increases timer tick counter but not much more */
-static char int08[]={
- 0xCD,0x1C,           /* int $0x1c */
- 0x50,                /* pushw %ax */
- 0x1E,                /* pushw %ds */
- 0xB8,0x40,0x00,      /* movw $0x40,%ax */
- 0x8E,0xD8,           /* movw %ax,%ds */
-#if 0
- 0x83,0x06,0x6C,0x00,0x01, /* addw $1,(0x6c) */
- 0x83,0x16,0x6E,0x00,0x00, /* adcw $0,(0x6e) */
-#else
- 0x66,0xFF,0x06,0x6C,0x00, /* incl (0x6c) */
-#endif
- 0xB0,0x20,           /* movb $0x20,%al */
- 0xE6,0x20,           /* outb %al,$0x20 */
- 0x1F,                /* popw %ax */
- 0x58,                /* popw %ax */
- 0xCF                 /* iret */
-};
-
-static void MZ_InitHandlers(void)
-{
- WORD seg;
- LPBYTE start=DOSMEM_GetBlock(sizeof(int08),&seg);
- memcpy(start,int08,sizeof(int08));
-/* INT 08: point it at our tick-incrementing handler */
- ((SEGPTR*)0)[0x08]=MAKESEGPTR(seg,0);
-/* INT 1C: just point it to IRET, we don't want to handle it ourselves */
- ((SEGPTR*)0)[0x1C]=MAKESEGPTR(seg,sizeof(int08)-1);
+    /* FIXME: more PSP stuff */
 }
 
 static WORD MZ_InitEnvironment( LPCSTR env, LPCSTR name )
 {
  unsigned sz=0;
+ unsigned i=0;
  WORD seg;
  LPSTR envblk;
 
@@ -181,11 +169,21 @@ static WORD MZ_InitEnvironment( LPCSTR env, LPCSTR name )
   while (env[sz++]) sz+=strlen(env+sz)+1;
  } else sz++;
  /* allocate it */
- envblk=DOSMEM_GetBlock(sz+sizeof(WORD)+strlen(name)+1,&seg);
+ envblk=DOSMEM_AllocBlock(sz+sizeof(WORD)+strlen(name)+1,&seg);
  /* fill it */
  if (env) {
   memcpy(envblk,env,sz);
  } else envblk[0]=0;
+ /* DOS environment variables are uppercase */
+ while (envblk[i]){
+  while (envblk[i] != '='){
+   if (envblk[i]>='a' && envblk[i] <= 'z'){
+    envblk[i] -= 32;
+   }
+   i++;
+  }
+  i += strlen(envblk+i) + 1;
+ }
  /* DOS 3.x: the block contains 1 additional string */
  *(WORD*)(envblk+sz)=1;
  /* being the program name itself */
@@ -197,17 +195,19 @@ static BOOL MZ_InitMemory(void)
 {
     /* initialize the memory */
     TRACE("Initializing DOS memory structures\n");
-    DOSMEM_Init(TRUE);
+    DOSMEM_MapDosLayout();
+    DOSDEV_InstallDOSDevices();
+    MSCDEX_InstallCDROM();
 
-    MZ_InitHandlers();
     return TRUE;
 }
 
-static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
+static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk, WORD par_env_seg )
 {
   IMAGE_DOS_HEADER mz_header;
   DWORD image_start,image_size,min_size,max_size,avail;
-  BYTE*psp_start,*load_start,*oldenv;
+  BYTE*psp_start,*load_start;
+  LPSTR oldenv = 0;
   int x, old_com=0, alloc;
   SEGPTR reloc;
   WORD env_seg, load_seg, rel_seg, oldpsp_seg;
@@ -215,15 +215,19 @@ static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
 
   if (DOSVM_psp) {
     /* DOS process already running, inherit from it */
-    PDB16* par_psp = (PDB16*)((DWORD)DOSVM_psp << 4);
+    PDB16* par_psp;
     alloc=0;
-    oldenv = (LPBYTE)((DWORD)par_psp->environment << 4);
     oldpsp_seg = DOSVM_psp;
+    if( !par_env_seg) {  
+        par_psp = (PDB16*)((DWORD)DOSVM_psp << 4);
+        oldenv = (LPSTR)((DWORD)par_psp->environment << 4);
+    }
   } else {
     /* allocate new DOS process, inheriting from Wine environment */
     alloc=1;
-    oldenv = GetEnvironmentStringsA();
     oldpsp_seg = 0;
+    if( !par_env_seg)
+        oldenv = GetEnvironmentStringsA();
   }
 
  SetFilePointer(hFile,0,NULL,FILE_BEGIN);
@@ -247,6 +251,9 @@ static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
   /* calculate load size */
   image_start=mz_header.e_cparhdr<<4;
   image_size=mz_header.e_cp<<9; /* pages are 512 bytes */
+  /* From Ralf Brown Interrupt List: If the word at offset 02h is 4, it should
+   * be treated as 00h, since pre-1.10 versions of the MS linker set it that
+   * way. */
   if ((mz_header.e_cblp!=0)&&(mz_header.e_cblp!=4)) image_size-=512-mz_header.e_cblp;
   image_size-=image_start;
   min_size=image_size+((DWORD)mz_header.e_minalloc<<4)+(PSP_SIZE<<4);
@@ -262,10 +269,15 @@ static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
     load_start=(LPBYTE)((DWORD)load_seg<<4);
   } else {
     /* allocate environment block */
-    env_seg=MZ_InitEnvironment(oldenv, filename);
+    if( par_env_seg)
+        env_seg = par_env_seg;
+    else
+        env_seg=MZ_InitEnvironment(oldenv, filename);
+    if (alloc)
+        FreeEnvironmentStringsA( oldenv);
 
     /* allocate memory for the executable */
-    TRACE("Allocating DOS memory (min=%ld, max=%ld)\n",min_size,max_size);
+    TRACE("Allocating DOS memory (min=%d, max=%d)\n",min_size,max_size);
     avail=DOSMEM_Available();
     if (avail<min_size) {
       ERR("insufficient DOS memory\n");
@@ -273,7 +285,7 @@ static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
       goto load_error;
     }
     if (avail>max_size) avail=max_size;
-    psp_start=DOSMEM_GetBlock(avail,&DOSVM_psp);
+    psp_start=DOSMEM_AllocBlock(avail,&DOSVM_psp);
     if (!psp_start) {
       ERR("error allocating DOS memory\n");
       SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@@ -286,11 +298,15 @@ static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
   }
 
  /* load executable image */
- TRACE("loading DOS %s image, %08lx bytes\n",old_com?"COM":"EXE",image_size);
+ TRACE("loading DOS %s image, %08x bytes\n",old_com?"COM":"EXE",image_size);
  SetFilePointer(hFile,image_start,NULL,FILE_BEGIN);
  if (!ReadFile(hFile,load_start,image_size,&len,NULL) || len != image_size) {
-  SetLastError(ERROR_BAD_FORMAT);
-  goto load_error;
+  /* check if this is due to the workaround for the pre-1.10 MS linker and we
+     really had only 4 bytes on the last page */
+  if (mz_header.e_cblp != 4 || image_size - len != 512 - 4) {
+    SetLastError(ERROR_BAD_FORMAT);
+    goto load_error;
+  }
  }
 
  if (mz_header.e_crlc) {
@@ -312,6 +328,11 @@ static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
     init_ip = mz_header.e_ip;
     init_ss = load_seg+mz_header.e_ss;
     init_sp = mz_header.e_sp;
+    if (old_com){
+      /* .COM files exit with ret. Make sure they jump to psp start (=int 20) */
+      WORD* stack = PTR_REAL_TO_LIN(init_ss, init_sp);
+      *stack = 0;
+    }
 
     TRACE("entry point: %04x:%04x\n",init_cs,init_ip);
   }
@@ -330,26 +351,171 @@ load_error:
 }
 
 /***********************************************************************
- *             LoadDosExe (WINEDOS.@)
+ *             wine_load_dos_exe (WINEDOS.@)
+ *
+ * Called from WineVDM when a new real-mode DOS process is started.
+ * Loads DOS program into memory and executes the program.
  */
-void WINAPI MZ_LoadImage( LPCSTR filename, HANDLE hFile )
+void WINAPI wine_load_dos_exe( LPCSTR filename, LPCSTR cmdline )
 {
-  if (MZ_DoLoadImage( hFile, filename, NULL )) MZ_Launch();
+    char dos_cmdtail[126];
+    int  dos_length = 0;
+
+    HANDLE hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, 
+                                NULL, OPEN_EXISTING, 0, 0 );
+    if (hFile == INVALID_HANDLE_VALUE) return;
+    DOSVM_isdosexe = TRUE;
+
+    if(cmdline && *cmdline)
+    {
+        dos_length = strlen(cmdline);
+        memmove( dos_cmdtail + 1, cmdline, 
+                 (dos_length < 125) ? dos_length : 125 );
+
+        /* Non-empty command tail always starts with at least one space. */
+        dos_cmdtail[0] = ' ';
+        dos_length++;
+
+        /*
+         * If command tail is longer than 126 characters,
+         * set tail length to 127 and fill CMDLINE environment variable 
+         * with full command line (this includes filename).
+         */
+        if (dos_length > 126)
+        {
+            char *cmd = HeapAlloc( GetProcessHeap(), 0, 
+                                   dos_length + strlen(filename) + 4 );
+            char *ptr = cmd;
+
+            if (!cmd)
+                return;
+
+            /*
+             * Append filename. If path includes spaces, quote the path.
+             */
+            if (strchr(filename, ' '))
+            {
+                *ptr++ = '\"';
+                strcpy( ptr, filename );
+                ptr += strlen(filename);                   
+                *ptr++ = '\"';
+            }
+            else
+            {
+                strcpy( ptr, filename );
+                ptr += strlen(filename);  
+            }
+
+            /*
+             * Append command tail.
+             */
+            if (cmdline[0] != ' ')
+                *ptr++ = ' ';
+            strcpy( ptr, cmdline );
+
+            /*
+             * Set environment variable. This will be passed to
+             * new DOS process.
+             */
+            if (!SetEnvironmentVariableA( "CMDLINE", cmd ))
+            {
+                HeapFree(GetProcessHeap(), 0, cmd );
+                return;
+            }
+
+            HeapFree(GetProcessHeap(), 0, cmd );
+            dos_length = 127;
+        }
+    }
+
+    if (MZ_DoLoadImage( hFile, filename, NULL, 0 )) 
+        MZ_Launch( dos_cmdtail, dos_length );
 }
 
 /***********************************************************************
  *             MZ_Exec
+ *
+ * this may only be called from existing DOS processes
  */
 BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID paramblk )
 {
-  /* this may only be called from existing DOS processes
-   * (i.e. one DOS app spawning another) */
-  /* FIXME: do we want to check binary type first, to check
-   * whether it's a NE/PE executable? */
-  HANDLE hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ,
-                            NULL, OPEN_EXISTING, 0, 0);
+  DWORD binType;
+  STARTUPINFOA st;
+  PROCESS_INFORMATION pe;
+  HANDLE hFile;
+
   BOOL ret = FALSE;
+
+  if(!GetBinaryTypeA(filename, &binType))   /* determine what kind of binary this is */
+  {
+    return FALSE; /* binary is not an executable */
+  }
+
+  /* handle non-dos executables */
+  if(binType != SCS_DOS_BINARY)
+  {
+    if(func == 0) /* load and execute */
+    {
+      LPSTR fullCmdLine;
+      WORD fullCmdLength;
+      LPBYTE psp_start = (LPBYTE)((DWORD)DOSVM_psp << 4);
+      PDB16 *psp = (PDB16 *)psp_start;
+      ExecBlock *blk = (ExecBlock *)paramblk;
+      LPBYTE cmdline = PTR_REAL_TO_LIN(SELECTOROF(blk->cmdline),OFFSETOF(blk->cmdline));
+      LPBYTE envblock = PTR_REAL_TO_LIN(psp->environment, 0);
+      int    cmdLength = cmdline[0];
+
+      /*
+       * If cmdLength is 127, command tail is truncated and environment 
+       * variable CMDLINE should contain full command line 
+       * (this includes filename).
+       */
+      if (cmdLength == 127)
+      {
+          FIXME( "CMDLINE argument passing is unimplemented.\n" );
+          cmdLength = 126; /* FIXME */
+      }
+
+      fullCmdLength = (strlen(filename) + 1) + cmdLength + 1; /* filename + space + cmdline + terminating null character */
+
+      fullCmdLine = HeapAlloc(GetProcessHeap(), 0, fullCmdLength);
+      if(!fullCmdLine) return FALSE; /* return false on memory alloc failure */
+
+      /* build the full command line from the executable file and the command line being passed in */
+      snprintf(fullCmdLine, fullCmdLength, "%s ", filename); /* start off with the executable filename and a space */
+      memcpy(fullCmdLine + strlen(fullCmdLine), cmdline + 1, cmdLength); /* append cmdline onto the end */
+      fullCmdLine[fullCmdLength - 1] = 0; /* null terminate string */
+
+      ZeroMemory (&st, sizeof(STARTUPINFOA));
+      st.cb = sizeof(STARTUPINFOA);
+      ret = CreateProcessA (NULL, fullCmdLine, NULL, NULL, TRUE, 0, envblock, NULL, &st, &pe);
+
+      /* wait for the app to finish and clean up PROCESS_INFORMATION handles */
+      if(ret)
+      {
+        WaitForSingleObject(pe.hProcess, INFINITE);  /* wait here until the child process is complete */
+        CloseHandle(pe.hProcess);
+        CloseHandle(pe.hThread);
+      }
+
+      HeapFree(GetProcessHeap(), 0, fullCmdLine);  /* free the memory we allocated */
+    }
+    else
+    {
+      FIXME("EXEC type of %d not implemented for non-dos executables\n", func);
+      ret = FALSE;
+    }
+
+    return ret;
+  } /* if(binType != SCS_DOS_BINARY) */
+
+
+  /* handle dos executables */
+
+  hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ,
+                            NULL, OPEN_EXISTING, 0, 0);
   if (hFile == INVALID_HANDLE_VALUE) return FALSE;
+
   switch (func) {
   case 0: /* load and execute */
   case 1: /* load but don't execute */
@@ -359,7 +525,7 @@ BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID para
       PDB16 *psp = (PDB16 *)psp_start;
       psp->saveStack = (DWORD)MAKESEGPTR(context->SegSs, LOWORD(context->Esp));
     }
-    ret = MZ_DoLoadImage( hFile, filename, NULL );
+    ret = MZ_DoLoadImage( hFile, filename, NULL, ((ExecBlock *)paramblk)->env_seg );
     if (ret) {
       /* MZ_LoadImage created a new PSP and loaded new values into it,
        * let's work on the new values now */
@@ -368,12 +534,24 @@ BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID para
       LPBYTE cmdline = PTR_REAL_TO_LIN(SELECTOROF(blk->cmdline),OFFSETOF(blk->cmdline));
 
       /* First character contains the length of the command line. */
-      MZ_FillPSP(psp_start, cmdline + 1, cmdline[0]);
+      MZ_FillPSP(psp_start, (LPSTR)cmdline + 1, cmdline[0]);
 
       /* the lame MS-DOS engineers decided that the return address should be in int22 */
       DOSVM_SetRMHandler(0x22, (FARPROC16)MAKESEGPTR(context->SegCs, LOWORD(context->Eip)));
       if (func) {
        /* don't execute, just return startup state */
+        /*
+         * From Ralph Brown:
+         *  For function 01h, the AX value to be passed to the child program 
+         *  is put on top of the child's stack
+         */
+        LPBYTE stack;
+        init_sp -= 2;
+        stack = (LPBYTE) CTX_SEG_OFF_TO_LIN(context, init_ss, init_sp);
+        /* FIXME: push AX correctly */
+        stack[0] = 0x00;    /* push AL */
+        stack[1] = 0x00;    /* push AH */
+       
        blk->init_cs = init_cs;
        blk->init_ip = init_ip;
        blk->init_ss = init_ss;
@@ -393,7 +571,7 @@ BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID para
   case 3: /* load overlay */
     {
       OverlayBlock *blk = (OverlayBlock *)paramblk;
-      ret = MZ_DoLoadImage( hFile, filename, blk );
+      ret = MZ_DoLoadImage( hFile, filename, blk, 0);
     }
     break;
   default:
@@ -425,8 +603,8 @@ void WINAPI MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg )
 
     spc.proc = proc;
     spc.arg = arg;
-    event = CreateEventA(NULL, TRUE, FALSE, NULL);
-    PostThreadMessageA(loop_tid, WM_USER, event, (LPARAM)&spc);
+    event = CreateEventW(NULL, TRUE, FALSE, NULL);
+    PostThreadMessageA(loop_tid, WM_USER, (WPARAM)event, (LPARAM)&spc);
     WaitForSingleObject(event, INFINITE);
     CloseHandle(event);
   } else
@@ -436,7 +614,7 @@ void WINAPI MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg )
 static DWORD WINAPI MZ_DOSVM( LPVOID lpExtra )
 {
   CONTEXT context;
-  DWORD ret;
+  INT ret;
 
   dosvm_pid = getpid();
 
@@ -447,12 +625,26 @@ static DWORD WINAPI MZ_DOSVM( LPVOID lpExtra )
   context.Esp    = init_sp;
   context.SegDs  = DOSVM_psp;
   context.SegEs  = DOSVM_psp;
-  context.EFlags = 0x00080000;  /* virtual interrupt flag */
+  context.EFlags = V86_FLAG | VIF_MASK;
   DOSVM_SetTimer(0x10000);
   ret = DOSVM_Enter( &context );
-
+  if (ret == -1)
+  {
+      /* fetch the app name from the environment */
+      PDB16 *psp = PTR_REAL_TO_LIN( DOSVM_psp, 0 );
+      char *env = PTR_REAL_TO_LIN( psp->environment, 0 );
+      while (*env) env += strlen(env) + 1;
+      env += 1 + sizeof(WORD);
+
+      if (GetLastError() == ERROR_NOT_SUPPORTED)
+          MESSAGE( "wine: Cannot start DOS application %s\n"
+                   "      because vm86 mode is not supported on this platform.\n",
+                   debugstr_a(env) );
+      else
+          FIXME( "vm86 mode failed error %u\n", GetLastError() );
+  }
   dosvm_pid = 0;
-  return ret;
+  return ret != 0;
 }
 
 static BOOL MZ_InitTask(void)
@@ -471,20 +663,26 @@ static BOOL MZ_InitTask(void)
   return TRUE;
 }
 
-static void MZ_Launch(void)
+static void MZ_Launch( LPCSTR cmdtail, int length )
 {
-  TDB *pTask = TASK_GetPtr( GetCurrentTask() );
+  TDB *pTask = GlobalLock16( GetCurrentTask() );
   BYTE *psp_start = PTR_REAL_TO_LIN( DOSVM_psp, 0 );
-  LPSTR cmdline = GetCommandLineA();
   DWORD rv;
   SYSLEVEL *lock;
+  MSG msg;
 
-  MZ_FillPSP(psp_start, cmdline, cmdline ? strlen(cmdline) : 0);
+  MZ_FillPSP(psp_start, cmdtail, length);
   pTask->flags |= TDBF_WINOLDAP;
 
+  /* DTA is set to PSP:0080h when a program is started. */
+  pTask->dta = MAKESEGPTR( DOSVM_psp, 0x80 );
+
   GetpWin16Lock( &lock );
   _LeaveSysLevel( lock );
 
+  /* force the message queue to be created */
+  PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
+
   ResumeThread(dosvm_thread);
   rv = DOSVM_Loop(dosvm_thread);
 
@@ -494,7 +692,7 @@ static void MZ_Launch(void)
   loop_thread = 0; loop_tid = 0;
 
   VGA_Clean();
-  ExitThread(rv);
+  ExitProcess(rv);
 }
 
 /***********************************************************************
@@ -548,12 +746,12 @@ BOOL WINAPI MZ_Current( void )
 #else /* !MZ_SUPPORTED */
 
 /***********************************************************************
- *             LoadDosExe (WINEDOS.@)
+ *             wine_load_dos_exe (WINEDOS.@)
  */
-void WINAPI MZ_LoadImage( LPCSTR filename, HANDLE hFile )
+void WINAPI wine_load_dos_exe( LPCSTR filename, LPCSTR cmdline )
 {
-  WARN("DOS executables not supported on this platform\n");
-  SetLastError(ERROR_BAD_FORMAT);
+    FIXME("DOS executables not supported on this platform\n");
+    SetLastError(ERROR_BAD_FORMAT);
 }
 
 /***********************************************************************
@@ -571,7 +769,15 @@ BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID para
  */
 void WINAPI MZ_AllocDPMITask( void )
 {
-    ERR("Actual real-mode calls not supported on this platform!\n");
+    FIXME("Actual real-mode calls not supported on this platform!\n");
+}
+
+/***********************************************************************
+ *             MZ_RunInThread
+ */
+void WINAPI MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg )
+{
+    proc(arg);
 }
 
 /***********************************************************************