1 | /* $Id: winexebase.cpp,v 1.8 2000-04-16 18:05:04 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 exe base class
|
---|
5 | *
|
---|
6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_DOSFILEMGR /* File Manager values */
|
---|
13 | #define INCL_DOSERRORS /* DOS Error values */
|
---|
14 | #define INCL_DOSPROCESS /* DOS Process values */
|
---|
15 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
---|
16 | #define INCL_WIN
|
---|
17 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
18 | #include <stdio.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <iostream.h>
|
---|
22 | #include <fstream.h>
|
---|
23 | #include <misc.h>
|
---|
24 | #include <win32type.h>
|
---|
25 | #include <winexebase.h>
|
---|
26 | #include <windllbase.h>
|
---|
27 | #include <wprocess.h>
|
---|
28 | #include <pefile.h>
|
---|
29 | #include "exceptions.h"
|
---|
30 | #include "exceptutil.h"
|
---|
31 | #include "cio.h"
|
---|
32 |
|
---|
33 | #include "conwin.h" // Windows Header for console only
|
---|
34 | #include "console.h"
|
---|
35 |
|
---|
36 | #define DBG_LOCALLOG DBG_winexebase
|
---|
37 | #include "dbglocal.h"
|
---|
38 |
|
---|
39 | BOOL fExeStarted = FALSE;
|
---|
40 | Win32ExeBase *WinExe = NULL;
|
---|
41 |
|
---|
42 | //******************************************************************************
|
---|
43 | //******************************************************************************
|
---|
44 | BOOL IsExeStarted()
|
---|
45 | {
|
---|
46 | return fExeStarted;
|
---|
47 | }
|
---|
48 | //******************************************************************************
|
---|
49 | //******************************************************************************
|
---|
50 | Win32ExeBase::Win32ExeBase(HINSTANCE hInstance)
|
---|
51 | : Win32ImageBase(hInstance),
|
---|
52 | fConsoleApp(FALSE),
|
---|
53 | cmdLineA(NULL), cmdLineW(NULL)
|
---|
54 | {
|
---|
55 | WinExe = this;
|
---|
56 | }
|
---|
57 | //******************************************************************************
|
---|
58 | //******************************************************************************
|
---|
59 | Win32ExeBase::~Win32ExeBase()
|
---|
60 | {
|
---|
61 | QueueItem *item;
|
---|
62 | Win32DllBase *dll;
|
---|
63 |
|
---|
64 | //First delete all dlls loaded by LoadLibrary
|
---|
65 | //Then delete all dlls that were loaded by the exe
|
---|
66 | //(NOTE: This is what NT does; first delete loadlib dlls in LIFO order and
|
---|
67 | // then the exe dlls)
|
---|
68 | Win32DllBase::deleteDynamicLibs();
|
---|
69 |
|
---|
70 | dprintf(("Win32ExeBase::~Win32ExeBase"));
|
---|
71 | #ifdef DEBUG_ENABLELOG_LEVEL2
|
---|
72 | item = loadedDlls.Head();
|
---|
73 | dll = (Win32DllBase *)loadedDlls.getItem(item);
|
---|
74 | dll->printListOfDlls();
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | item = loadedDlls.Head();
|
---|
78 | while(item) {
|
---|
79 | dll = (Win32DllBase *)loadedDlls.getItem(item);
|
---|
80 | if(dll == NULL) {
|
---|
81 | dprintf(("ERROR: Win32ExeBase::~Win32ExeBase: dll item == NULL!!"));
|
---|
82 | DebugInt3();
|
---|
83 | break;
|
---|
84 | }
|
---|
85 | dll->Release();
|
---|
86 | item = loadedDlls.getNext(item);
|
---|
87 | }
|
---|
88 |
|
---|
89 | Win32DllBase::deleteAll();
|
---|
90 |
|
---|
91 | WinExe = NULL;
|
---|
92 | if(cmdLineA)
|
---|
93 | free(cmdLineA);
|
---|
94 | if(cmdLineW)
|
---|
95 | free(cmdLineW);
|
---|
96 | }
|
---|
97 | //******************************************************************************
|
---|
98 | //******************************************************************************
|
---|
99 | ULONG Win32ExeBase::start()
|
---|
100 | {
|
---|
101 | WINEXCEPTION_FRAME exceptFrame;
|
---|
102 | ULONG rc;
|
---|
103 |
|
---|
104 | if(getenv("WIN32_IOPL2")) {
|
---|
105 | io_init1();
|
---|
106 | }
|
---|
107 | dprintf(("Start executable %X\n", WinExe));
|
---|
108 |
|
---|
109 | fExeStarted = TRUE;
|
---|
110 |
|
---|
111 | //Note: The Win32 exception structure references by FS:[0] is the same
|
---|
112 | // in OS/2
|
---|
113 | OS2SetExceptionHandler((void *)&exceptFrame);
|
---|
114 | SetWin32TIB();
|
---|
115 |
|
---|
116 | //Allocate TLS index for this module
|
---|
117 | tlsAlloc();
|
---|
118 | tlsAttachThread(); //setup TLS (main thread)
|
---|
119 |
|
---|
120 | //Set default FPU control word (no exceptions); same as in NT
|
---|
121 | _control87(0x27F, 0xFFF);
|
---|
122 | rc = ((WIN32EXEENTRY)entryPoint)(NULL);
|
---|
123 | RestoreOS2TIB();
|
---|
124 |
|
---|
125 | OS2UnsetExceptionHandler((void *)&exceptFrame);
|
---|
126 |
|
---|
127 | return rc;
|
---|
128 | }
|
---|
129 | //******************************************************************************
|
---|
130 | //******************************************************************************
|
---|
131 | BOOL Win32ExeBase::isDll()
|
---|
132 | {
|
---|
133 | return FALSE;
|
---|
134 | }
|
---|
135 | //******************************************************************************
|
---|
136 | //******************************************************************************
|
---|
137 | void Win32ExeBase::setCommandLine(char *cline)
|
---|
138 | {
|
---|
139 | ULONG cmdlength = strlen(cline) + 1;
|
---|
140 |
|
---|
141 | cmdLineA = (LPSTR)malloc(cmdlength);
|
---|
142 | strcpy(cmdLineA, cline);
|
---|
143 | cmdLineW = (LPWSTR)malloc(cmdlength*sizeof(WCHAR));
|
---|
144 | AsciiToUnicode(cmdLineA, cmdLineW);
|
---|
145 | }
|
---|
146 | //******************************************************************************
|
---|
147 | //******************************************************************************
|
---|