SAFESEH setting

  • Thread starter Thread starter Roger Orr
  • Start date Start date
R

Roger Orr

Hi,
I'm trying to write my own 'safe' exception handler for Microsoft
Visual Studio .NET 2003.
1) It seems that you cannot mark a C++ function as a safe exception
handler.
2) I can't get the .SAFESEH directive to work with ml.

Has anyone tried and succeeded with the /safeseh option and .SAFESEH
directive with ML?
I've stripped my code to the barest minimum, and assembling
'testit.asm' like this:
ml /safeseh /c testit.asm libc.lib /link /dll
I am getting this linker error:
testit.obj : fatal error LNK1279: invalid or corrupt file: file
contains
invalid .sxdata contributions.

The code looks like this:

--------------- testit.asm ---------------
title testit - test safeseh
.586
..model FLAT

testit SEGMENT

fred PROC PUBLIC
push ebp
pop ebp
ret
fred ENDP

..SAFESEH fred

testit ENDS

END
--------------- testit.asm ---------------

Any help, anyone?

Roger Orr
 
Hello Roger,

I am not familar with it. However, I will contact other engineers and reply you as soon as possible here. Thanks very much.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: (e-mail address removed) (Roger Orr)
!Newsgroups: microsoft.public.dotnet.languages.vc
!Subject: SAFESEH setting
!Date: 16 Jul 2003 01:39:28 -0700
!Organization: http://groups.google.com/
!Lines: 44
!Message-ID: <[email protected]>
!NNTP-Posting-Host: 141.228.156.225
!Content-Type: text/plain; charset=ISO-8859-1
!Content-Transfer-Encoding: 8bit
!X-Trace: posting.google.com 1058344769 8275 127.0.0.1 (16 Jul 2003 08:39:29 GMT)
!X-Complaints-To: (e-mail address removed)
!NNTP-Posting-Date: 16 Jul 2003 08:39:29 GMT
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!
newsfeed.online.be!216.170.153.135.MISMATCH!tdsnet-transit!newspeer.tds.net!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!sn-xit-09!
supernews.com!postnews1.google.com!not-for-mail
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26219
!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!
!Hi,
!I'm trying to write my own 'safe' exception handler for Microsoft
!Visual Studio .NET 2003.
!1) It seems that you cannot mark a C++ function as a safe exception
!handler.
!2) I can't get the .SAFESEH directive to work with ml.
!
!Has anyone tried and succeeded with the /safeseh option and .SAFESEH
!directive with ML?
!I've stripped my code to the barest minimum, and assembling
!'testit.asm' like this:
! ml /safeseh /c testit.asm libc.lib /link /dll
!I am getting this linker error:
! testit.obj : fatal error LNK1279: invalid or corrupt file: file
!contains
! invalid .sxdata contributions.
!
!The code looks like this:
!
!--------------- testit.asm ---------------
! title testit - test safeseh
! .586
!.model FLAT
!
!testit SEGMENT
!
!fred PROC PUBLIC
! push ebp
! pop ebp
! ret
!fred ENDP
!
!.SAFESEH fred
!
!testit ENDS
!
! END
!--------------- testit.asm ---------------
!
!Any help, anyone?
!
!Roger Orr
!--
![Originally posted to microsoft.public.vstudio.general]
!
 
Brandon Bray said:
testit is a data section. It has to be executable. Change the
SEGMENT directive to

testit SEGMENT 'CODE'

Aha - thanks Brandon.
The joys of Intel - you can of course execute code even when it is in a data
segment - it is just .safeseh which is unhappy....
It's been too long since I used the assembler - _asm is my tool of choice
for the tiny bits I write nowadays!

However even with this help there's something elseI still can't do. I want
to mark a C++ function as a safe exception handler:
Something like this:

handler.cpp
DWORD handler( ... )
{
...
}

and then:

makesafe.asm

.386
..model FLAT

EXTRN _handler:NEAR
..SAFESEH _handler

END

but this generates the same linker error as before.
Is what I am trying to do possible, if so how. Or is there a way to mark
the function as a safeseh in C++ ?

Regards,
Roger Orr
 
C++ safeseh

Roger Orr said:
is there a way to mark
the function as a safeseh in C++ ?
Yes. However the name should be properly decorated. stdcall (which is on by default) prepends '_'.

The trick is to use SYSCALL -

; adds ntl::cxxrecord::catchguardhandler to the safeseh table
; compile with /safeseh

.386
.model flat, SYSCALL
?catchguardhandler@cxxrecord@ntl@@SA?AW4disposition@exception@nt@2@PAUrecord@452@PAUregistration@452@PAUcontext@52@PAUdispatcher_context@452@@Z PROTO proc
.safeseh ?catchguardhandler@cxxrecord@ntl@@SA?AW4disposition@exception@nt@2@PAUrecord@452@PAUregistration@452@PAUcontext@52@PAUdispatcher_context@452@@Z
end

Actual decorated name could be found in generated asm listing (use /Fa option).

WBR

P.S. I have googled the web and found no solution, though I am too late here, hope it helps someone.
 
Back
Top