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

Last change on this file since 21999 was 21999, checked in by dmik, 13 years ago

kernel32: Make SEH work in OS/2 context.

See #82 for details.

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