Opened 14 years ago

Closed 14 years ago

#7 closed enhancement (fixed)

Add support for __try/__except

Reported by: dmik Owned by:
Priority: blocker Milestone:
Component: kernel Version:
Severity: Keywords:
Cc:

Description

The windows code often uses try/except (this is a MSVC compiler extension to support structured exception handling). We need to support this extension to simplify porting Windows applications.

Change History (5)

comment:1 Changed 14 years ago by dmik

What the __try/__except block does is basically installs a system exception handler and then passes control over to the code in the __except clause if an exception happens, and removes the exception handler at the end of the block.

What we need to do is install the OS/2 system exception handler in __try and if the exception happens, translate it to the Win32 exception using the OSLibDispatchException() call from the kernel32 library.

There are several implementations of __try/__except for non-MSVC compilers out there. I found these two:

I will use them as a base and integrate to kernel32.

comment:2 Changed 14 years ago by dmik

Apparently, Odin doesn't maintain the Win32 TIB and doesn't expect Win32 exception handlers when it is used in SDK mode (i.e. when the application is compiled from sources rather than converted on the fly).

We should either enable the Win32 TIB or forget about the idea of supporting structured Win32 exceptions in SDK mode. From what I see enabling this is a matter of making sure the !fIsOS2Image blocks related to exception handling are executed in fIsOS2Image mode too and setting fSwitchTIBSel to TRUE for this mode as well.

comment:3 Changed 14 years ago by Silvan Scherrer

as it might be other SDK build need them also i would vote for the enablement

comment:4 Changed 14 years ago by dmik

__try/__except support is added in r21381. Note that although I didn't try all possible test cases, this implementation is better than both ones mentioned above because it gives 100% (*) source level compatibility with MSVC (no source change is necessary at all, you may only need to inlclude <excpt.h> sometimes) ant it's also more compact.

Note that in order to enable proper __try/__except support, one needs to call EnableSEH() right before the normal RegisterLxExe?()/RegisterLxDll?() call. Otherwise, surprise! -- SEH will still work (yes, SEH in Win32 is almost identical to OS/2) but GetExceptionCode?()/GetExceptionInformation?() will return incorrect information (in particular, some exception codes differ) and the recognized return values of the filtering expression differ too.

__try/__finally/__leave is not yet done; we will implement it later if really needed.

(*) - Keep in mind that things like doing a goto/longjmp() outside the __try/__except blocks are not supported ATM (and probably won't ever be since I guess that it requires "low-level" support from the compiler).

An, and note that we only support SEH for the GCC compiler so far.

comment:5 Changed 14 years ago by dmik

Resolution: fixed
Status: newclosed

I fixed a couple of problems in further revisions. I think it's enough for now.

Note: See TracTickets for help on using tickets.