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

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

Don't allocate selectors anymore. Allocate tiled memory and call Dos32FlatToSel; Get default stack size from PE header; Thread handles not closed properly

File size: 4.1 KB
Line 
1/* $Id: winexebase.cpp,v 1.22 2003-01-13 16:51:40 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
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
39BOOL fExeStarted = FALSE;
40Win32ExeBase *WinExe = NULL;
41
42//******************************************************************************
43//******************************************************************************
44BOOL IsExeStarted()
45{
46 return fExeStarted;
47}
48//******************************************************************************
49//******************************************************************************
50Win32ExeBase::Win32ExeBase(HINSTANCE hInstance)
51 : Win32ImageBase(hInstance),
52 fConsoleApp(FALSE)
53{
54 WinExe = this;
55}
56//******************************************************************************
57//******************************************************************************
58Win32ExeBase::~Win32ExeBase()
59{
60 QueueItem *item;
61 Win32DllBase *dll;
62
63 //First delete all dlls loaded by LoadLibrary
64 //Then delete all dlls that were loaded by the exe
65 //(NOTE: This is what NT does; first delete loadlib dlls in LIFO order and
66 // then the exe dlls)
67 Win32DllBase::deleteDynamicLibs();
68
69 dprintf(("Win32ExeBase::~Win32ExeBase"));
70#ifdef DEBUG_ENABLELOG_LEVEL2
71 item = loadedDlls.Head();
72 dll = (Win32DllBase *)loadedDlls.getItem(item);
73 dll->printListOfDlls();
74#endif
75
76 item = loadedDlls.Head();
77 while(item) {
78 dll = (Win32DllBase *)loadedDlls.getItem(item);
79 if(dll == NULL) {
80 dprintf(("ERROR: Win32ExeBase::~Win32ExeBase: dll item == NULL!!"));
81 DebugInt3();
82 break;
83 }
84 dll->Release();
85 item = loadedDlls.getNext(item);
86 }
87
88 Win32DllBase::deleteAll();
89
90 WinExe = NULL;
91}
92//******************************************************************************
93//******************************************************************************
94ULONG Win32ExeBase::start()
95{
96 WINEXCEPTION_FRAME exceptFrame;
97 ULONG rc;
98
99#ifdef DEBUG
100 TEB *teb = GetThreadTEB();
101 dprintf(("Start executable %x\n", WinExe));
102 dprintf(("Stack top 0x%x, stack end 0x%x", teb->stack_top, teb->stack_low));
103#endif
104
105 fExeStarted = TRUE;
106
107 //Note: The Win32 exception structure references by FS:[0] is the same
108 // in OS/2
109 OS2SetExceptionHandler((void *)&exceptFrame);
110 USHORT sel = SetWin32TIB(isPEImage() ? TIB_SWITCH_FORCE_WIN32 : TIB_SWITCH_DEFAULT);
111
112 //Set FPU control word to 0x27F (same as in NT)
113 CONTROL87(0x27F, 0xFFF);
114 dprintf(("KERNEL32: Win32ExeBase::start exe at %08xh\n",
115 (void*)entryPoint ));
116 rc = CallEntryPoint(entryPoint, NULL);
117
118 SetFS(sel); //restore FS
119
120 OS2UnsetExceptionHandler((void *)&exceptFrame);
121
122 return rc;
123}
124//******************************************************************************
125//Default stack size is 1MB; the PE loader reads it from the executable header
126//******************************************************************************
127ULONG Win32ExeBase::getDefaultStackSize()
128{
129 return 0x100000;
130}
131//******************************************************************************
132//******************************************************************************
133BOOL Win32ExeBase::isDll()
134{
135 return FALSE;
136}
137//******************************************************************************
138//******************************************************************************
Note: See TracBrowser for help on using the repository browser.