source: trunk/src/kernel32/winexebase.cpp@ 8457

Last change on this file since 8457 was 8457, checked in by sandervl, 23 years ago

more logging

File size: 3.9 KB
Line 
1/* $Id: winexebase.cpp,v 1.20 2002-05-20 13:48:51 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 <cpuhlp.h>
30#include "exceptions.h"
31#include "exceptutil.h"
32#include "cio.h"
33
34#include "conwin.h" // Windows Header for console only
35#include "console.h"
36
37#define DBG_LOCALLOG DBG_winexebase
38#include "dbglocal.h"
39
40BOOL fExeStarted = FALSE;
41Win32ExeBase *WinExe = NULL;
42
43//******************************************************************************
44//******************************************************************************
45BOOL IsExeStarted()
46{
47 return fExeStarted;
48}
49//******************************************************************************
50//******************************************************************************
51Win32ExeBase::Win32ExeBase(HINSTANCE hInstance)
52 : Win32ImageBase(hInstance),
53 fConsoleApp(FALSE)
54{
55 WinExe = this;
56}
57//******************************************************************************
58//******************************************************************************
59Win32ExeBase::~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}
93//******************************************************************************
94//******************************************************************************
95ULONG Win32ExeBase::start()
96{
97 WINEXCEPTION_FRAME exceptFrame;
98 ULONG rc;
99
100 if(getenv("WIN32_IOPL2")) {
101 io_init1();
102 }
103#ifdef DEBUG
104 TEB *teb = GetThreadTEB();
105 dprintf(("Start executable %x\n", WinExe));
106 dprintf(("Stack top 0x%x, stack end 0x%x", teb->stack_top, teb->stack_low));
107#endif
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 USHORT sel = SetWin32TIB(isPEImage() ? TIB_SWITCH_FORCE_WIN32 : TIB_SWITCH_DEFAULT);
115
116 //Set FPU control word to 0x27F (same as in NT)
117 CONTROL87(0x27F, 0xFFF);
118 dprintf(("KERNEL32: Win32ExeBase::start exe at %08xh\n",
119 (void*)entryPoint ));
120 rc = CallEntryPoint(entryPoint, NULL);
121
122 SetFS(sel); //restore FS
123
124 OS2UnsetExceptionHandler((void *)&exceptFrame);
125
126 return rc;
127}
128//******************************************************************************
129//******************************************************************************
130BOOL Win32ExeBase::isDll()
131{
132 return FALSE;
133}
134//******************************************************************************
135//******************************************************************************
Note: See TracBrowser for help on using the repository browser.