source: trunk/src/kernel32/winexelx.cpp@ 9800

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

Added ODIN_SetTIBSwitch function to override TIB selector switching

File size: 3.6 KB
Line 
1/* $Id: winexelx.cpp,v 1.12 2003-02-13 15:30:53 sandervl Exp $ */
2
3/*
4 * Win32 LX Exe class (compiled in OS/2 using Odin32 api)
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 <winexelx.h>
26#include <winconst.h>
27#include <win32api.h>
28#include <wprocess.h>
29#include <odinlx.h>
30
31#include "exceptions.h"
32#include "exceptutil.h"
33
34#define DBG_LOCALLOG DBG_winexelx
35#include "dbglocal.h"
36
37//******************************************************************************
38//Create LX Exe object and call entrypoint
39//System dlls set EntryPoint to 0
40//******************************************************************************
41BOOL WIN32API RegisterLxExe(WINMAIN EntryPoint, PVOID pResData)
42{
43 APIRET rc;
44 PPIB ppib;
45 PTIB ptib;
46
47 //Signal to TEB management that we're a real OS/2 app and don't
48 //require setting FS to our special win32 selector
49 fSwitchTIBSel = FALSE;
50
51 //We're an OS/2 app
52 fIsOS2Image = TRUE;
53
54 if(WinExe != NULL) //should never happen
55 delete(WinExe);
56
57 rc = DosGetInfoBlocks(&ptib, &ppib);
58 if(rc) {
59 return FALSE;
60 }
61
62 Win32LxExe *winexe;
63
64 winexe = new Win32LxExe(ppib->pib_hmte, pResData);
65
66 if(winexe) {
67 InitCommandLine(FALSE);
68 winexe->setEntryPoint((ULONG)EntryPoint);
69 winexe->start();
70 }
71 else {
72 eprintf(("Win32LxExe creation failed!\n"));
73 DebugInt3();
74 return FALSE;
75 }
76 return TRUE;
77}
78//******************************************************************************
79//******************************************************************************
80Win32LxExe::Win32LxExe(HINSTANCE hInstance, PVOID pResData)
81 : Win32ImageBase(hInstance),
82 Win32LxImage(hInstance, pResData),
83 Win32ExeBase(hInstance)
84{
85 dprintf(("Win32LxExe ctor: %s", szModule));
86 hinstance = (HINSTANCE)buildHeader(1, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI);
87}
88//******************************************************************************
89//******************************************************************************
90//******************************************************************************
91//******************************************************************************
92Win32LxExe::~Win32LxExe()
93{
94}
95//******************************************************************************
96//******************************************************************************
97ULONG Win32LxExe::start()
98{
99 WINEXCEPTION_FRAME exceptFrame;
100 ULONG rc;
101
102 dprintf(("Start executable %X\n", WinExe));
103
104 fExeStarted = TRUE;
105
106 //Allocate TLS index for this module
107 tlsAlloc();
108 tlsAttachThread(); //setup TLS (main thread)
109
110 //Note: The Win32 exception structure references by FS:[0] is the same
111 // in OS/2
112 OS2SetExceptionHandler((void *)&exceptFrame);
113
114 SetWin32TIB();
115 rc = ((WINMAIN)entryPoint)(hinstance, 0, (LPSTR)GetCommandLineA(), SW_SHOWNORMAL_W);
116 RestoreOS2TIB();
117
118 OS2UnsetExceptionHandler((void *)&exceptFrame);
119
120 ExitProcess(rc);
121 return rc;
122}
123//******************************************************************************
124//******************************************************************************
Note: See TracBrowser for help on using the repository browser.