Fixed Win16 documentation not fixed because of a bug in winapi_check.
[wine] / loader / dos / module.c
1 /*
2  * DOS (MZ) loader
3  *
4  * Copyright 1998 Ove Kåven
5  *
6  * This code hasn't been completely cleaned up yet.
7  */
8
9 #include "config.h"
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <sys/time.h>
21 #include "windef.h"
22 #include "wine/winbase16.h"
23 #include "winerror.h"
24 #include "module.h"
25 #include "task.h"
26 #include "selectors.h"
27 #include "file.h"
28 #include "ldt.h"
29 #include "process.h"
30 #include "miscemu.h"
31 #include "debugtools.h"
32 #include "dosexe.h"
33 #include "dosmod.h"
34 #include "options.h"
35 #include "vga.h"
36
37 DEFAULT_DEBUG_CHANNEL(module);
38
39 static LPDOSTASK dos_current;
40
41 #ifdef MZ_SUPPORTED
42
43 #ifdef HAVE_SYS_MMAN_H
44 # include <sys/mman.h>
45 #endif
46
47 /* define this to try mapping through /proc/pid/mem instead of a temp file,
48    but Linus doesn't like mmapping /proc/pid/mem, so it doesn't work for me */
49 #undef MZ_MAPSELF
50
51 #define BIOS_DATA_SEGMENT 0x40
52 #define PSP_SIZE 0x10
53
54 #define SEG16(ptr,seg) ((LPVOID)((BYTE*)ptr+((DWORD)(seg)<<4)))
55 #define SEGPTR16(ptr,segptr) ((LPVOID)((BYTE*)ptr+((DWORD)SELECTOROF(segptr)<<4)+OFFSETOF(segptr)))
56
57 /* structures for EXEC */
58
59 typedef struct {
60   WORD env_seg;
61   DWORD cmdline WINE_PACKED;
62   DWORD fcb1 WINE_PACKED;
63   DWORD fcb2 WINE_PACKED;
64   WORD init_sp;
65   WORD init_ss;
66   WORD init_ip;
67   WORD init_cs;
68 } ExecBlock;
69
70 typedef struct {
71   WORD load_seg;
72   WORD rel_seg;
73 } OverlayBlock;
74
75 /* global variables */
76
77 static WORD init_cs,init_ip,init_ss,init_sp;
78 static char mm_name[128];
79
80 int read_pipe, write_pipe;
81 HANDLE hReadPipe, hWritePipe;
82 pid_t dosmod_pid;
83
84 static void MZ_Launch(void);
85 static BOOL MZ_InitTask(void);
86 static void MZ_KillTask(void);
87
88 static void MZ_CreatePSP( LPVOID lpPSP, WORD env, WORD par )
89 {
90   PDB16*psp=lpPSP;
91
92   psp->int20=0x20CD; /* int 20 */
93   /* some programs use this to calculate how much memory they need */
94   psp->nextParagraph=0x9FFF; /* FIXME: use a real value */
95   /* FIXME: dispatcher */
96   psp->savedint22 = INT_GetRMHandler(0x22);
97   psp->savedint23 = INT_GetRMHandler(0x23);
98   psp->savedint24 = INT_GetRMHandler(0x24);
99   psp->parentPSP=par;
100   psp->environment=env;
101   /* FIXME: more PSP stuff */
102 }
103
104 static void MZ_FillPSP( LPVOID lpPSP, LPCSTR cmdline )
105 {
106  PDB16*psp=lpPSP;
107  const char*cmd=cmdline?strchr(cmdline,' '):NULL;
108
109  /* copy parameters */
110  if (cmd) {
111 #if 0
112   /* command.com doesn't do this */
113   while (*cmd == ' ') cmd++;
114 #endif
115   psp->cmdLine[0]=strlen(cmd);
116   strcpy(psp->cmdLine+1,cmd);
117   psp->cmdLine[psp->cmdLine[0]+1]='\r';
118  } else psp->cmdLine[1]='\r';
119  /* FIXME: more PSP stuff */
120 }
121
122 /* default INT 08 handler: increases timer tick counter but not much more */
123 static char int08[]={
124  0xCD,0x1C,           /* int $0x1c */
125  0x50,                /* pushw %ax */
126  0x1E,                /* pushw %ds */
127  0xB8,0x40,0x00,      /* movw $0x40,%ax */
128  0x8E,0xD8,           /* movw %ax,%ds */
129 #if 0
130  0x83,0x06,0x6C,0x00,0x01, /* addw $1,(0x6c) */
131  0x83,0x16,0x6E,0x00,0x00, /* adcw $0,(0x6e) */
132 #else
133  0x66,0xFF,0x06,0x6C,0x00, /* incl (0x6c) */
134 #endif
135  0xB0,0x20,           /* movb $0x20,%al */
136  0xE6,0x20,           /* outb %al,$0x20 */
137  0x1F,                /* popw %ax */
138  0x58,                /* popw %ax */
139  0xCF                 /* iret */
140 };
141
142 static void MZ_InitHandlers(void)
143 {
144  WORD seg;
145  LPBYTE start=DOSMEM_GetBlock(sizeof(int08),&seg);
146  memcpy(start,int08,sizeof(int08));
147 /* INT 08: point it at our tick-incrementing handler */
148  ((SEGPTR*)0)[0x08]=PTR_SEG_OFF_TO_SEGPTR(seg,0);
149 /* INT 1C: just point it to IRET, we don't want to handle it ourselves */
150  ((SEGPTR*)0)[0x1C]=PTR_SEG_OFF_TO_SEGPTR(seg,sizeof(int08)-1);
151 }
152
153 static WORD MZ_InitEnvironment( LPCSTR env, LPCSTR name )
154 {
155  unsigned sz=0;
156  WORD seg;
157  LPSTR envblk;
158
159  if (env) {
160   /* get size of environment block */
161   while (env[sz++]) sz+=strlen(env+sz)+1;
162  } else sz++;
163  /* allocate it */
164  envblk=DOSMEM_GetBlock(sz+sizeof(WORD)+strlen(name)+1,&seg);
165  /* fill it */
166  if (env) {
167   memcpy(envblk,env,sz);
168  } else envblk[0]=0;
169  /* DOS 3.x: the block contains 1 additional string */
170  *(WORD*)(envblk+sz)=1;
171  /* being the program name itself */
172  strcpy(envblk+sz+sizeof(WORD),name);
173  return seg;
174 }
175
176 static BOOL MZ_InitMemory(void)
177 {
178     int mm_fd;
179     void *img_base;
180
181     /* initialize the memory */
182     TRACE("Initializing DOS memory structures\n");
183     DOSMEM_Init(TRUE);
184
185     /* allocate 1MB+64K shared memory */
186     tmpnam(mm_name);
187     /* strcpy(mm_name,"/tmp/mydosimage"); */
188     mm_fd = open(mm_name,O_RDWR|O_CREAT /* |O_TRUNC */,S_IRUSR|S_IWUSR);
189     if (mm_fd < 0) ERR("file %s could not be opened\n",mm_name);
190     /* fill the file with the DOS memory */
191     if (write( mm_fd, NULL, 0x110000 ) != 0x110000) ERR("cannot write DOS mem\n");
192     /* map it in */
193     img_base = mmap(NULL,0x110000,PROT_READ|PROT_WRITE|PROT_EXEC,MAP_SHARED|MAP_FIXED,mm_fd,0);
194     close( mm_fd );
195
196     if (img_base)
197     {
198         ERR("could not map shared memory, error=%s\n",strerror(errno));
199         return FALSE;
200     }
201     MZ_InitHandlers();
202     return TRUE;
203 }
204
205 BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk )
206 {
207   LPDOSTASK lpDosTask = dos_current;
208   IMAGE_DOS_HEADER mz_header;
209   DWORD image_start,image_size,min_size,max_size,avail;
210   BYTE*psp_start,*load_start,*oldenv;
211   int x, old_com=0, alloc;
212   SEGPTR reloc;
213   WORD env_seg, load_seg, rel_seg, oldpsp_seg;
214   DWORD len;
215
216   if (lpDosTask) {
217     /* DOS process already running, inherit from it */
218     PDB16* par_psp = (PDB16*)((DWORD)lpDosTask->psp_seg << 4);
219     alloc=0;
220     oldenv = (LPBYTE)((DWORD)par_psp->environment << 4);
221     oldpsp_seg = lpDosTask->psp_seg;
222   } else {
223     /* allocate new DOS process, inheriting from Wine environment */
224     alloc=1;
225     lpDosTask = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DOSTASK));
226     dos_current = lpDosTask;
227     oldenv = GetEnvironmentStringsA();
228     oldpsp_seg = 0;
229   }
230
231  SetFilePointer(hFile,0,NULL,FILE_BEGIN);
232  if (   !ReadFile(hFile,&mz_header,sizeof(mz_header),&len,NULL)
233      || len != sizeof(mz_header) 
234      || mz_header.e_magic != IMAGE_DOS_SIGNATURE) {
235   char *p = strrchr( filename, '.' );
236   if (!p || strcasecmp( p, ".com" ))  /* check for .COM extension */
237   {
238       SetLastError(ERROR_BAD_FORMAT);
239       goto load_error;
240   }
241   old_com=1; /* assume .COM file */
242   image_start=0;
243   image_size=GetFileSize(hFile,NULL);
244   min_size=0x10000; max_size=0x100000;
245   mz_header.e_crlc=0;
246   mz_header.e_ss=0; mz_header.e_sp=0xFFFE;
247   mz_header.e_cs=0; mz_header.e_ip=0x100;
248  } else {
249   /* calculate load size */
250   image_start=mz_header.e_cparhdr<<4;
251   image_size=mz_header.e_cp<<9; /* pages are 512 bytes */
252   if ((mz_header.e_cblp!=0)&&(mz_header.e_cblp!=4)) image_size-=512-mz_header.e_cblp;
253   image_size-=image_start;
254   min_size=image_size+((DWORD)mz_header.e_minalloc<<4)+(PSP_SIZE<<4);
255   max_size=image_size+((DWORD)mz_header.e_maxalloc<<4)+(PSP_SIZE<<4);
256  }
257
258   if (alloc) MZ_InitMemory();
259
260   if (oblk) {
261     /* load overlay into preallocated memory */
262     load_seg=oblk->load_seg;
263     rel_seg=oblk->rel_seg;
264     load_start=(LPBYTE)((DWORD)load_seg<<4);
265   } else {
266     /* allocate environment block */
267     env_seg=MZ_InitEnvironment(oldenv, filename);
268
269     /* allocate memory for the executable */
270     TRACE("Allocating DOS memory (min=%ld, max=%ld)\n",min_size,max_size);
271     avail=DOSMEM_Available();
272     if (avail<min_size) {
273       ERR("insufficient DOS memory\n");
274       SetLastError(ERROR_NOT_ENOUGH_MEMORY);
275       goto load_error;
276     }
277     if (avail>max_size) avail=max_size;
278     psp_start=DOSMEM_GetBlock(avail,&lpDosTask->psp_seg);
279     if (!psp_start) {
280       ERR("error allocating DOS memory\n");
281       SetLastError(ERROR_NOT_ENOUGH_MEMORY);
282       goto load_error;
283     }
284     load_seg=lpDosTask->psp_seg+(old_com?0:PSP_SIZE);
285     rel_seg=load_seg;
286     load_start=psp_start+(PSP_SIZE<<4);
287     MZ_CreatePSP(psp_start, env_seg, oldpsp_seg);
288   }
289
290  /* load executable image */
291  TRACE("loading DOS %s image, %08lx bytes\n",old_com?"COM":"EXE",image_size);
292  SetFilePointer(hFile,image_start,NULL,FILE_BEGIN);
293  if (!ReadFile(hFile,load_start,image_size,&len,NULL) || len != image_size) {
294   SetLastError(ERROR_BAD_FORMAT);
295   goto load_error;
296  }
297
298  if (mz_header.e_crlc) {
299   /* load relocation table */
300   TRACE("loading DOS EXE relocation table, %d entries\n",mz_header.e_crlc);
301   /* FIXME: is this too slow without read buffering? */
302   SetFilePointer(hFile,mz_header.e_lfarlc,NULL,FILE_BEGIN);
303   for (x=0; x<mz_header.e_crlc; x++) {
304    if (!ReadFile(hFile,&reloc,sizeof(reloc),&len,NULL) || len != sizeof(reloc)) {
305     SetLastError(ERROR_BAD_FORMAT);
306     goto load_error;
307    }
308    *(WORD*)SEGPTR16(load_start,reloc)+=rel_seg;
309   }
310  }
311
312   if (!oblk) {
313     init_cs = load_seg+mz_header.e_cs;
314     init_ip = mz_header.e_ip;
315     init_ss = load_seg+mz_header.e_ss;
316     init_sp = mz_header.e_sp;
317
318     TRACE("entry point: %04x:%04x\n",init_cs,init_ip);
319   }
320
321   if (alloc && !MZ_InitTask()) {
322     MZ_KillTask();
323     SetLastError(ERROR_GEN_FAILURE);
324     return FALSE;
325   }
326
327   return TRUE;
328
329 load_error:
330   lpDosTask->psp_seg = oldpsp_seg;
331   if (alloc) {
332     dos_current = NULL;
333     if (mm_name[0]!=0) unlink(mm_name);
334   }
335
336   return FALSE;
337 }
338
339 BOOL MZ_LoadImage( LPCSTR cmdline )
340 {
341     HFILE hFile;
342     char *name, buffer[MAX_PATH];
343     LPCSTR p = strchr( cmdline, ' ' );
344
345     if (p)
346     {
347         if (!(name = HeapAlloc( GetProcessHeap(), 0, p - cmdline + 1 ))) return FALSE;
348         memcpy( name, cmdline, p - cmdline );
349         name[p - cmdline] = 0;
350     }
351     else name = (char *)cmdline;
352
353     if (!SearchPathA( NULL, name, ".exe", sizeof(buffer), buffer, NULL )) goto error;
354     if ((hFile = CreateFileA( buffer, GENERIC_READ, FILE_SHARE_READ,
355                               NULL, OPEN_EXISTING, 0, -1 )) == INVALID_HANDLE_VALUE)
356         goto error;
357     if (!MZ_DoLoadImage( hFile, buffer, NULL ))
358     {
359         CloseHandle( hFile );
360         goto error;
361     }
362     MZ_Launch();
363  error:
364     if (name != cmdline) HeapFree( GetProcessHeap(), 0, name );
365     return FALSE;
366 }
367
368 BOOL MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID paramblk )
369 {
370   /* this may only be called from existing DOS processes
371    * (i.e. one DOS app spawning another) */
372   /* FIXME: do we want to check binary type first, to check
373    * whether it's a NE/PE executable? */
374   LPDOSTASK lpDosTask = MZ_Current();
375   HFILE hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ,
376                              NULL, OPEN_EXISTING, 0, -1);
377   BOOL ret = FALSE;
378   if (hFile == INVALID_HANDLE_VALUE) return FALSE;
379   switch (func) {
380   case 0: /* load and execute */
381   case 1: /* load but don't execute */
382     {
383       /* save current process's return SS:SP now */
384       LPBYTE psp_start = (LPBYTE)((DWORD)lpDosTask->psp_seg << 4);
385       PDB16 *psp = (PDB16 *)psp_start;
386       psp->saveStack = (DWORD)PTR_SEG_OFF_TO_SEGPTR(context->SegSs, LOWORD(context->Esp));
387     }
388     ret = MZ_DoLoadImage( hFile, filename, NULL );
389     if (ret) {
390       /* MZ_LoadImage created a new PSP and loaded new values into lpDosTask,
391        * let's work on the new values now */
392       LPBYTE psp_start = (LPBYTE)((DWORD)lpDosTask->psp_seg << 4);
393       ExecBlock *blk = (ExecBlock *)paramblk;
394       MZ_FillPSP(psp_start, DOSMEM_MapRealToLinear(blk->cmdline));
395       /* the lame MS-DOS engineers decided that the return address should be in int22 */
396       INT_SetRMHandler(0x22, (FARPROC16)PTR_SEG_OFF_TO_SEGPTR(context->SegCs, LOWORD(context->Eip)));
397       if (func) {
398         /* don't execute, just return startup state */
399         blk->init_cs = init_cs;
400         blk->init_ip = init_ip;
401         blk->init_ss = init_ss;
402         blk->init_sp = init_sp;
403       } else {
404         /* execute by making us return to new process */
405         context->SegCs = init_cs;
406         context->Eip   = init_ip;
407         context->SegSs = init_ss;
408         context->Esp   = init_sp;
409         context->SegDs = lpDosTask->psp_seg;
410         context->SegEs = lpDosTask->psp_seg;
411         context->Eax   = 0;
412       }
413     }
414     break;
415   case 3: /* load overlay */
416     {
417       OverlayBlock *blk = (OverlayBlock *)paramblk;
418       ret = MZ_DoLoadImage( hFile, filename, blk );
419     }
420     break;
421   default:
422     FIXME("EXEC load type %d not implemented\n", func);
423     SetLastError(ERROR_INVALID_FUNCTION);
424     break;
425   }
426   CloseHandle(hFile);
427   return ret;
428 }
429
430 LPDOSTASK MZ_AllocDPMITask( void )
431 {
432   LPDOSTASK lpDosTask = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DOSTASK));
433
434   if (lpDosTask) {
435     dos_current = lpDosTask;
436     MZ_InitMemory();
437     MZ_InitTask();
438   }
439   return lpDosTask;
440 }
441
442 static void MZ_InitTimer( int ver )
443 {
444  if (ver<1) {
445   /* can't make timer ticks */
446  } else {
447   int func;
448   struct timeval tim;
449
450   /* start dosmod timer at 55ms (18.2Hz) */
451   func=DOSMOD_SET_TIMER;
452   tim.tv_sec=0; tim.tv_usec=54925;
453   write(write_pipe,&func,sizeof(func));
454   write(write_pipe,&tim,sizeof(tim));
455  }
456 }
457
458 static BOOL MZ_InitTask(void)
459 {
460   int write_fd[2],x_fd;
461   pid_t child;
462   char path[256],*fpath;
463
464   /* create pipes */
465   if (!CreatePipe(&hReadPipe,&hWritePipe,NULL,0)) return FALSE;
466   if (pipe(write_fd)<0) {
467     CloseHandle(hReadPipe);
468     CloseHandle(hWritePipe);
469     return FALSE;
470   }
471
472   read_pipe = FILE_GetUnixHandle( hReadPipe, GENERIC_READ );
473   x_fd = FILE_GetUnixHandle( hWritePipe, GENERIC_WRITE );
474
475   TRACE("win32 pipe: read=%d, write=%d, unix pipe: read=%d, write=%d\n",
476         hReadPipe,hWritePipe,read_pipe,x_fd);
477   TRACE("outbound unix pipe: read=%d, write=%d, pid=%d\n",write_fd[0],write_fd[1],getpid());
478
479   write_pipe=write_fd[1];
480
481   TRACE("Loading DOS VM support module\n");
482   if ((child=fork())<0) {
483     close(write_fd[0]);
484     close(read_pipe);
485     close(write_pipe);
486     close(x_fd);
487     CloseHandle(hReadPipe);
488     CloseHandle(hWritePipe);
489     return FALSE;
490   }
491  if (child!=0) {
492   /* parent process */
493   int ret;
494
495   close(write_fd[0]);
496   close(x_fd);
497   dosmod_pid = child;
498   /* wait for child process to signal readiness */
499   while (1) {
500     if (read(read_pipe,&ret,sizeof(ret))==sizeof(ret)) break;
501     if ((errno==EINTR)||(errno==EAGAIN)) continue;
502     /* failure */
503     ERR("dosmod has failed to initialize\n");
504     if (mm_name[0]!=0) unlink(mm_name);
505     return FALSE;
506   }
507   /* the child has now mmaped the temp file, it's now safe to unlink.
508    * do it here to avoid leaving a mess in /tmp if/when Wine crashes... */
509   if (mm_name[0]!=0) unlink(mm_name);
510   /* start simulated system timer */
511   MZ_InitTimer(ret);
512   if (ret<2) {
513     ERR("dosmod version too old! Please install newer dosmod properly\n");
514     ERR("If you don't, the new dosmod event handling system will not work\n");
515   }
516   /* all systems are now go */
517  } else {
518   /* child process */
519   close(read_pipe);
520   close(write_pipe);
521   /* put our pipes somewhere dosmod can find them */
522   dup2(write_fd[0],0); /* stdin */
523   dup2(x_fd,1);        /* stdout */
524   /* now load dosmod */
525   /* check argv[0]-derived paths first, since the newest dosmod is most likely there
526    * (at least it was once for Andreas Mohr, so I decided to make it easier for him) */
527   fpath=strrchr(strcpy(path,full_argv0),'/');
528   if (fpath) {
529    strcpy(fpath,"/dosmod");
530    execl(path,mm_name,NULL);
531    strcpy(fpath,"/loader/dos/dosmod");
532    execl(path,mm_name,NULL);
533   }
534   /* okay, it wasn't there, try in the path */
535   execlp("dosmod",mm_name,NULL);
536   /* last desperate attempts: current directory */
537   execl("dosmod",mm_name,NULL);
538   /* and, just for completeness... */
539   execl("loader/dos/dosmod",mm_name,NULL);
540   /* if failure, exit */
541   ERR("Failed to spawn dosmod, error=%s\n",strerror(errno));
542   exit(1);
543  }
544  return TRUE;
545 }
546
547 static void MZ_Launch(void)
548 {
549   LPDOSTASK lpDosTask = MZ_Current();
550   CONTEXT context;
551   TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
552   BYTE *psp_start = PTR_REAL_TO_LIN( lpDosTask->psp_seg, 0 );
553
554   MZ_FillPSP(psp_start, GetCommandLineA());
555   pTask->flags |= TDBF_WINOLDAP;
556
557   memset( &context, 0, sizeof(context) );
558   context.SegCs  = init_cs;
559   context.Eip    = init_ip;
560   context.SegSs  = init_ss;
561   context.Esp    = init_sp;
562   context.SegDs  = lpDosTask->psp_seg;
563   context.SegEs  = lpDosTask->psp_seg;
564   context.EFlags = 0x00080000;  /* virtual interrupt flag */
565   DOSVM_Enter( &context );
566 }
567
568 static void MZ_KillTask(void)
569 {
570   TRACE("killing DOS task\n");
571   VGA_Clean();
572   kill(dosmod_pid,SIGTERM);
573 }
574
575 void MZ_Exit( CONTEXT86 *context, BOOL cs_psp, WORD retval )
576 {
577   LPDOSTASK lpDosTask = MZ_Current();
578   if (lpDosTask) {
579     WORD psp_seg = cs_psp ? context->SegCs : lpDosTask->psp_seg;
580     LPBYTE psp_start = (LPBYTE)((DWORD)psp_seg << 4);
581     PDB16 *psp = (PDB16 *)psp_start;
582     WORD parpsp = psp->parentPSP; /* check for parent DOS process */
583     if (parpsp) {
584       /* retrieve parent's return address */
585       FARPROC16 retaddr = INT_GetRMHandler(0x22);
586       /* restore interrupts */
587       INT_SetRMHandler(0x22, psp->savedint22);
588       INT_SetRMHandler(0x23, psp->savedint23);
589       INT_SetRMHandler(0x24, psp->savedint24);
590       /* FIXME: deallocate file handles etc */
591       /* free process's associated memory
592        * FIXME: walk memory and deallocate all blocks owned by process */
593       DOSMEM_FreeBlock(DOSMEM_MapRealToLinear(MAKELONG(0,psp->environment)));
594       DOSMEM_FreeBlock(DOSMEM_MapRealToLinear(MAKELONG(0,lpDosTask->psp_seg)));
595       /* switch to parent's PSP */
596       lpDosTask->psp_seg = parpsp;
597       psp_start = (LPBYTE)((DWORD)parpsp << 4);
598       psp = (PDB16 *)psp_start;
599       /* now return to parent */
600       lpDosTask->retval = retval;
601       context->SegCs = SELECTOROF(retaddr);
602       context->Eip   = OFFSETOF(retaddr);
603       context->SegSs = SELECTOROF(psp->saveStack);
604       context->Esp   = OFFSETOF(psp->saveStack);
605       return;
606     } else
607       MZ_KillTask();
608   }
609   ExitThread( retval );
610 }
611
612 #else /* !MZ_SUPPORTED */
613
614 BOOL MZ_LoadImage( LPCSTR cmdline )
615 {
616   WARN("DOS executables not supported on this platform\n");
617   SetLastError(ERROR_BAD_FORMAT);
618   return FALSE;
619 }
620
621 BOOL MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID paramblk )
622 {
623   /* can't happen */
624   SetLastError(ERROR_BAD_FORMAT);
625   return FALSE;
626 }
627
628 LPDOSTASK MZ_AllocDPMITask( void )
629 {
630     ERR("Actual real-mode calls not supported on this platform!\n");
631     return NULL;
632 }
633
634 void MZ_Exit( CONTEXT86 *context, BOOL cs_psp, WORD retval )
635 {
636   ExitThread( retval );
637 }
638
639 #endif /* !MZ_SUPPORTED */
640
641 LPDOSTASK MZ_Current( void )
642 {
643   return dos_current;
644 }