| 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 |
|
|---|
| 6 | 1.0 Introduction
|
|---|
| 7 | ----------------
|
|---|
| 8 |
|
|---|
| 9 | Although Odin's primary goal is to run win32 applications in OS/2 without
|
|---|
| 10 | requiring a recompile, it is possible to port Win95/98/NT apps to OS/2
|
|---|
| 11 | with minimal effort.
|
|---|
| 12 | This is the first draft of this porting guide. If anything is unclear or
|
|---|
| 13 | not mentioned, please contact the author (sandervl@xs4all.nl)
|
|---|
| 14 |
|
|---|
| 15 | 1.1 Odin32
|
|---|
| 16 | -----------
|
|---|
| 17 |
|
|---|
| 18 | Odin32 is the win32 compatible API provided with the Odin alpha (or daily builds).
|
|---|
| 19 | It's consists of hundreds of win32 APIs in several dlls (kernel32, user32, gdi32 etc).
|
|---|
| 20 | Keep in mind that Odin is still alpha software, so don't expect all apis to
|
|---|
| 21 | work exactly like those in Windows NT.
|
|---|
| 22 | If you find bugs, please contact the developers or send an email to the
|
|---|
| 23 | Odin programmers mailinglist (win32os2-wai@egroups.com).
|
|---|
| 24 |
|
|---|
| 25 | 1.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 |
|
|---|
| 35 | It should also be possible to use Watcom or EMX to do the job, but you might
|
|---|
| 36 | need to make some changes to our headers to make this work.
|
|---|
| 37 |
|
|---|
| 38 | 2.0 Porting Win32 applications to OS/2
|
|---|
| 39 | --------------------------------------
|
|---|
| 40 | In 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 |
|
|---|
| 46 | 2.1 Changing the makefile(s)
|
|---|
| 47 | ----------------------------
|
|---|
| 48 | This will probably be the most time consuming (and boring) part of the port.
|
|---|
| 49 | You have to make sure all compiler options are correct for the project and
|
|---|
| 50 | make some changes for compiling the resource script. (see 2.2)
|
|---|
| 51 |
|
|---|
| 52 | To build the ported application, you must link with the necessary Odin libraries
|
|---|
| 53 | in your makefile. These libraries (i.e. kernel32.lib, user32.lib etc) are
|
|---|
| 54 | built when compiling Odin itself.
|
|---|
| 55 |
|
|---|
| 56 | Paragraph 2.6 contains a skeleton makefile.
|
|---|
| 57 |
|
|---|
| 58 | 2.2 Wine's resource compiler (wrc)
|
|---|
| 59 | ----------------------------------
|
|---|
| 60 | Wrc must be used to compile the resources of the win32 project.
|
|---|
| 61 | Unfortunately wrc isn't completely compatible with Microsoft's rc.exe.
|
|---|
| 62 | You might need to make some changes to the resource script in order to
|
|---|
| 63 | make wrc happy.
|
|---|
| 64 |
|
|---|
| 65 | Wrc produces an assembly file with the a resource tree and binary resources.
|
|---|
| 66 | This resembles the resource section in win32 (PE) executables/dlls.
|
|---|
| 67 | This assembly file should be added to the list of objects files in the makefile.
|
|---|
| 68 |
|
|---|
| 69 | 2.3 Odin's entrypoint wrappers
|
|---|
| 70 | ------------------------------
|
|---|
| 71 | Kernel32 keeps track of all loaded executables and dlls. The PE loader makes
|
|---|
| 72 | sure image objects are created when loading a win32 executable.
|
|---|
| 73 | A ported win32 app must do this manually by calling certain kernel32 exports.
|
|---|
| 74 |
|
|---|
| 75 | In 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 |
|
|---|
| 79 | The executable wrapper calls RegisterLXExe (exported api in kernel32) to create
|
|---|
| 80 | an executable object and tell kernel32 where to find it's win32 entrypoint
|
|---|
| 81 | (usually WinMain) and resources.
|
|---|
| 82 | The dll version does the same thing. It calls RegisterLXDll to create the dll
|
|---|
| 83 | object during a dll load and UnregisterLXDll when the dll is unloaded.
|
|---|
| 84 | It's parameters are the dll module handle, the win32 dll entrypoint (LibMain)
|
|---|
| 85 | and, again, a pointer to the resource object. (as produced by wrc)
|
|---|
| 86 | The resource pointer can be NULL.
|
|---|
| 87 | The handle returned by RegisterLxDll must be used when calling UnregisterLxDll.
|
|---|
| 88 |
|
|---|
| 89 | In the skeleton dll entrypoint we also call ctordtorInit/Term to create/destroy
|
|---|
| 90 | and static C++ objects.
|
|---|
| 91 | If you don't link with odincrt.lib for the runtime C/C++ functions, you must
|
|---|
| 92 | also call CRT_init/CRT_term (before _ctordtorInit, after ctordtorTerm).
|
|---|
| 93 |
|
|---|
| 94 | After RegisterLXExe/Dll has finished it's job in kernel32, it will
|
|---|
| 95 | call the exe/dll entrypoint.
|
|---|
| 96 |
|
|---|
| 97 | 2.4 Win32 source code changes
|
|---|
| 98 | -----------------------------
|
|---|
| 99 | Usually you shouldn't have to make many changes to the existing win32
|
|---|
| 100 | source code.
|
|---|
| 101 | However, there might be a few differences between the MS SDK and Odin
|
|---|
| 102 | headers. If you find such problems, please correct them and notify
|
|---|
| 103 | the Odin developers.
|
|---|
| 104 |
|
|---|
| 105 | Complex 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 |
|
|---|
| 118 | 2.5 Exception handling
|
|---|
| 119 | ----------------------
|
|---|
| 120 |
|
|---|
| 121 | RegisterLXExe/RegisterLXDll in kernel32 registers an exception handler
|
|---|
| 122 | for Odin. This handler is used to support file mappings.
|
|---|
| 123 | You must make sure that your code doesn't remove this handler from
|
|---|
| 124 | the chain of exception handlers.
|
|---|
| 125 | To create a thread, use CreateThread; not _beginthread or DosCreateThread.
|
|---|
| 126 | CreateThread takes care of setting up an exception handler, creates TLS
|
|---|
| 127 | structures and calls dll entrypoints.
|
|---|
| 128 |
|
|---|
| 129 | Starting with r21382, Odin also implements the compiler-level support for SEH
|
|---|
| 130 | (structured exception handling) performed using the __try/__except statement in
|
|---|
| 131 | MSVC. Note that this is not a real compiler statement, it is just an emulation
|
|---|
| 132 | of 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 |
|
|---|
| 138 | In order to enable proper handling of the __try/__except statement, you must
|
|---|
| 139 | call EnableSEH() right before a call to RegisterLXDll() or RegisterLXExe() (as
|
|---|
| 140 | described above). A failure to do so will break the filter expression
|
|---|
| 141 | functionality.
|
|---|
| 142 |
|
|---|
| 143 | Note that you normally don't need to chage the Windows sources that the
|
|---|
| 144 | __try/__except statement themselves (except for the limitations mentioned above)
|
|---|
| 145 | as they should already include <excpt.h> (which is normally provided by a
|
|---|
| 146 | compiler for the windows platform) and the one included in Odin SDK provides
|
|---|
| 147 | the source-level compatible definitions.
|
|---|
| 148 |
|
|---|
| 149 | 2.6 Sample makefile
|
|---|
| 150 | -------------------
|
|---|
| 151 | This makefile is used to compile the MS SDK generic sample in OS/2:
|
|---|
| 152 |
|
|---|
| 153 | PDWIN32_INCLUDE = k:\source\odin32\include
|
|---|
| 154 | PDWIN32_LIB = k:\source\odin32\lib
|
|---|
| 155 | PDWIN32_BIN = k:\source\odin32\bin
|
|---|
| 156 |
|
|---|
| 157 | !include $(PDWIN32_INCLUDE)/pdwin32.mk
|
|---|
| 158 |
|
|---|
| 159 | PROJ = GENERIC
|
|---|
| 160 |
|
|---|
| 161 | all: $(PROJ).exe
|
|---|
| 162 |
|
|---|
| 163 | RC = wrc
|
|---|
| 164 | RCFLAGS = -s -I. -I$(CPPMAIN)\include -I$(PDWIN32_INCLUDE) -I$(PDWIN32_INCLUDE)\win
|
|---|
| 165 |
|
|---|
| 166 | # Define project specific macros
|
|---|
| 167 | PROJ_OBJS = generic.obj
|
|---|
| 168 | BASE_OBJS = resource.obj odinexe.obj
|
|---|
| 169 | EXTRA_LIBS = $(PDWIN32_LIB)\version.lib
|
|---|
| 170 | GLOBAL_DEP = generic.h resource.h
|
|---|
| 171 | RC_DEP = resource.h
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | CFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
|
|---|
| 175 | CXXFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
|
|---|
| 176 |
|
|---|
| 177 | CFLAGS = $(CFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
|
|---|
| 178 | CXXFLAGS = $(CXXFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
|
|---|
| 179 | LDFLAGSEXE = $(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 |
|
|---|
| 183 | resource.obj: resource.asm
|
|---|
| 184 |
|
|---|
| 185 | # Build rule for resource file
|
|---|
| 186 | resource.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
|
|---|
| 199 | clean:
|
|---|
| 200 | del *.bak *.pdb *.obj *.res *.exp *.map *.sbr *.bsc
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 | 3.0 Project participation
|
|---|
| 204 | -------------------------
|
|---|
| 205 |
|
|---|
| 206 | As ODIN became an open source project, everybody is kindly invited to
|
|---|
| 207 | contribute his/her share to the progress of the project. May it be
|
|---|
| 208 | active coding, fixing bugs or just providing detailed information about
|
|---|
| 209 | examined problems.
|
|---|
| 210 |
|
|---|
| 211 | We suggest you subscribe to win32os2-wai and the corresponsing mailing lists
|
|---|
| 212 | on http://www.egroups.com.
|
|---|
| 213 | In case you are interested in participating, every member of the project will
|
|---|
| 214 | be happy to give you direction to the right places and to give a personal
|
|---|
| 215 | introduction to further development of the particular modules.
|
|---|
| 216 |
|
|---|