source: trunk/doc/Porting.txt@ 22012

Last change on this file since 22012 was 21384, checked in by dmik, 15 years ago

SEH: Added some info to Porting.txt and examples to Odin32API.

File size: 9.0 KB
Line 
1/* $Id: Porting.txt,v 1.2 2000-08-11 10:54:06 sandervl Exp $ */
2
3 Porting Win32 applications to OS/2 using Odin - 991212
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
61.0 Introduction
7----------------
8
9Although Odin's primary goal is to run win32 applications in OS/2 without
10requiring a recompile, it is possible to port Win95/98/NT apps to OS/2
11with minimal effort.
12This is the first draft of this porting guide. If anything is unclear or
13not mentioned, please contact the author (sandervl@xs4all.nl)
14
151.1 Odin32
16-----------
17
18Odin32 is the win32 compatible API provided with the Odin alpha (or daily builds).
19It's consists of hundreds of win32 APIs in several dlls (kernel32, user32, gdi32 etc).
20Keep in mind that Odin is still alpha software, so don't expect all apis to
21work exactly like those in Windows NT.
22If you find bugs, please contact the developers or send an email to the
23Odin programmers mailinglist (win32os2-wai@egroups.com).
24
251.2 Required tools for porting win32 apps to OS/2
26-------------------------------------------------
27- IBM VisualAge C++ 3.08
28- OS/2 Warp 4 Toolkit (project apparently doesn't compile with
29 VAC's OS/2 headers)
30 Might also work with EMX headers. (haven't tried this)
31- ALP 4.0 (IBM Assembly Language Processor)
32 Download the tools zipfile from http://service.boulder.ibm.com/ddk/
33 (you need to register, but it's free)
34
35It should also be possible to use Watcom or EMX to do the job, but you might
36need to make some changes to our headers to make this work.
37
382.0 Porting Win32 applications to OS/2
39--------------------------------------
40In order to port win32 apps a few things have to be done:
41- Change all the makefiles for VAC (or any other OS/2 compiler)
42- Use Wine RC (wrc.exe) to compile the resources
43- Add the Odin executable and/or dll wrapper files to the project
44- Change the source code in case of compile problems
45
462.1 Changing the makefile(s)
47----------------------------
48This will probably be the most time consuming (and boring) part of the port.
49You have to make sure all compiler options are correct for the project and
50make some changes for compiling the resource script. (see 2.2)
51
52To build the ported application, you must link with the necessary Odin libraries
53in your makefile. These libraries (i.e. kernel32.lib, user32.lib etc) are
54built when compiling Odin itself.
55
56Paragraph 2.6 contains a skeleton makefile.
57
582.2 Wine's resource compiler (wrc)
59----------------------------------
60Wrc must be used to compile the resources of the win32 project.
61Unfortunately wrc isn't completely compatible with Microsoft's rc.exe.
62You might need to make some changes to the resource script in order to
63make wrc happy.
64
65Wrc produces an assembly file with the a resource tree and binary resources.
66This resembles the resource section in win32 (PE) executables/dlls.
67This assembly file should be added to the list of objects files in the makefile.
68
692.3 Odin's entrypoint wrappers
70------------------------------
71Kernel32 keeps track of all loaded executables and dlls. The PE loader makes
72sure image objects are created when loading a win32 executable.
73A ported win32 app must do this manually by calling certain kernel32 exports.
74
75In the src\Odin32API directory of the Odin CVS tree, you'll find two wrappers:
76- odinexe.cpp: Executable entrypoint (main)
77- odindll.cpp: Dll entrypoint (_DLL_InitTerm)
78
79The executable wrapper calls RegisterLXExe (exported api in kernel32) to create
80an executable object and tell kernel32 where to find it's win32 entrypoint
81(usually WinMain) and resources.
82The dll version does the same thing. It calls RegisterLXDll to create the dll
83object during a dll load and UnregisterLXDll when the dll is unloaded.
84It's parameters are the dll module handle, the win32 dll entrypoint (LibMain)
85and, again, a pointer to the resource object. (as produced by wrc)
86The resource pointer can be NULL.
87The handle returned by RegisterLxDll must be used when calling UnregisterLxDll.
88
89In the skeleton dll entrypoint we also call ctordtorInit/Term to create/destroy
90and static C++ objects.
91If you don't link with odincrt.lib for the runtime C/C++ functions, you must
92also call CRT_init/CRT_term (before _ctordtorInit, after ctordtorTerm).
93
94After RegisterLXExe/Dll has finished it's job in kernel32, it will
95call the exe/dll entrypoint.
96
972.4 Win32 source code changes
98-----------------------------
99Usually you shouldn't have to make many changes to the existing win32
100source code.
101However, there might be a few differences between the MS SDK and Odin
102headers. If you find such problems, please correct them and notify
103the Odin developers.
104
105Complex applications might be hard to port to OS/2 for several reasons:
106- Compiler differences (i.e. VAC 3.08 doesn't support unnamed unions)
107 VAC 3.6.5 should be a better choice for compiling win32 sources, but
108 it has it's own share of problems (bugs).
109- TLS (thread local storage) data; VAC has no facilities to support this,
110 so this could require a major rewrite.
111 Other compilers (Watcom) may have better support for this.
112 You can recognize this type of data by the __declspec(thread) keyword.
113 Using the TLS apis (i.e. TlsAlloc) is no problem.
114- OLE/COM objects. Wine headers aren't exactly built with C++ in mind,
115 so you'll most likely run into a lot of problems if the app uses
116 these win32 features.
117
1182.5 Exception handling
119----------------------
120
121RegisterLXExe/RegisterLXDll in kernel32 registers an exception handler
122for Odin. This handler is used to support file mappings.
123You must make sure that your code doesn't remove this handler from
124the chain of exception handlers.
125To create a thread, use CreateThread; not _beginthread or DosCreateThread.
126CreateThread takes care of setting up an exception handler, creates TLS
127structures and calls dll entrypoints.
128
129Starting with r21382, Odin also implements the compiler-level support for SEH
130(structured exception handling) performed using the __try/__except statement in
131MSVC. Note that this is not a real compiler statement, it is just an emulation
132of the corresponding MSVC behavior and it has the following limitations:
133- You should not use goto or longjmp() to jump into or out of the __try or
134 __except block -- this will most likely screw up the stack.
135- __try/__finally/__leave functionality is not yet supported.
136- Only the GCC compiler is supported ATM.
137
138In order to enable proper handling of the __try/__except statement, you must
139call EnableSEH() right before a call to RegisterLXDll() or RegisterLXExe() (as
140described above). A failure to do so will break the filter expression
141functionality.
142
143Note that you normally don't need to chage the Windows sources that the
144__try/__except statement themselves (except for the limitations mentioned above)
145as they should already include <excpt.h> (which is normally provided by a
146compiler for the windows platform) and the one included in Odin SDK provides
147the source-level compatible definitions.
148
1492.6 Sample makefile
150-------------------
151This makefile is used to compile the MS SDK generic sample in OS/2:
152
153PDWIN32_INCLUDE = k:\source\odin32\include
154PDWIN32_LIB = k:\source\odin32\lib
155PDWIN32_BIN = k:\source\odin32\bin
156
157!include $(PDWIN32_INCLUDE)/pdwin32.mk
158
159PROJ = GENERIC
160
161all: $(PROJ).exe
162
163RC = wrc
164RCFLAGS = -s -I. -I$(CPPMAIN)\include -I$(PDWIN32_INCLUDE) -I$(PDWIN32_INCLUDE)\win
165
166# Define project specific macros
167PROJ_OBJS = generic.obj
168BASE_OBJS = resource.obj odinexe.obj
169EXTRA_LIBS = $(PDWIN32_LIB)\version.lib
170GLOBAL_DEP = generic.h resource.h
171RC_DEP = resource.h
172
173
174CFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
175CXXFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
176
177CFLAGS = $(CFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
178CXXFLAGS = $(CXXFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
179LDFLAGSEXE = $(LDFLAGS) /Ge+ /B"/pmtype:pm /stack:0x30000 /NOBASE /Map" \
180 $(EXTRA_LIBS) $(PDWIN32_LIB)\kernel32.lib $(PDWIN32_LIB)\user32.lib \
181 $(PDWIN32_LIB)\gdi32.lib os2386.lib $(PDWIN32_LIB)\odincrt.lib $(RTLLIB_O)
182
183resource.obj: resource.asm
184
185# Build rule for resource file
186resource.asm: $(PROJ).rc $(RC_DEP)
187 $(RC) $(RCFLAGS) -o resource.asm $(PROJ).rc
188
189# Build rule for EXE
190$(PROJ).EXE: $(BASE_OBJS) $(PROJ_OBJS) resource.asm
191 $(LD) $(LDFLAGSEXE) -Fe$@ $(PROJ_OBJS) $(BASE_OBJS)
192
193# Build rule for help file
194#$(PROJ).hlp: $(PROJ).rtf $(PROJ).hpj
195# $(hc) generic.hpj
196
197
198# Rules for cleaning out those old files
199clean:
200 del *.bak *.pdb *.obj *.res *.exp *.map *.sbr *.bsc
201
202
2033.0 Project participation
204-------------------------
205
206As ODIN became an open source project, everybody is kindly invited to
207contribute his/her share to the progress of the project. May it be
208active coding, fixing bugs or just providing detailed information about
209examined problems.
210
211We suggest you subscribe to win32os2-wai and the corresponsing mailing lists
212on http://www.egroups.com.
213In case you are interested in participating, every member of the project will
214be happy to give you direction to the right places and to give a personal
215introduction to further development of the particular modules.
216
Note: See TracBrowser for help on using the repository browser.