Operating System - OpenVMS
1828218 Members
1850 Online
109975 Solutions
New Discussion

Re: SYS$GOTO_UNWIND access violation

 
Sethunath K.O
Occasional Advisor

SYS$GOTO_UNWIND access violation

Hi All

I would like to get your help to the following (Open VMS/C++)
This is regarding SYS$GOTO_UNWIND access violation.
I am calling Pascal functions (ufl_facility_00) which further few other Pascal functions. These Pascal functions in turn calls back a C++ function that has the SYS$GOTO_UNWIND command, depending on certain conditions. I wanted to unwind to the statement after the first Pascal function (ufl_facility_00) was called. This works fine (as expected) in debug but a normal image causes an access violation in the call SYS$GOTO_UNWIND.
Further, more strangely, the unwind call works fine in non-debug image, when a "cout... â Statement is introduced just above the call.
Can you please throw some idea on why a "cout" statement prevents the crash?
Is there any better approach for this?
Code

// Get the invocation handle so that we can subsequently execute a
// SYS$GOTO_UNWIND to get back to this point.
#ifdef _PLATFORM_ALPHA
cout << " before unwindhandle routines...." << endl;
retStatus = lib$get_curr_invo_context (&unwindIcb);
unwindHandle = lib$get_invo_handle (&unwindIcb);
#endif
⠦⠦.

cout << " now just before ufl_facility_00 " << endl;
retStatus = ufl_facility_00(number, eNo);
⠦⠦⠦⠦
Now UFL_FACILITY_00 will call some Pascal routines for display and get values from the fields. And once the field values are input, depending upon the value, this calls UFC_FACILITY_EXIT() - which calls FACILITY_EXIT().It is in this FACILITY_EXIT(), SYS$GOTO_UNWIND() statement is present as

⠦⠦.
curFrame = ourFrameMgr.getFrame(newFid);
#ifdef _PLATFORM_ALPHA
cout << "About to execute sys$goto_unwind" << endl; //If this statement is removed, and image if normal, then the below call will access violates.
// however, debug image seems to work fine without this statement.
rc = sys$goto_unwind(&unwindHandle, 0, 0, 0);
#endif
// There will not be a return to this point unless the sys$goto_unwind call
// fails.
FILE_LOG (logERROR) << "Sess: " << number << " Invalid status " << rc << "from sys$goto_unwind";
exit (EXIT_FAILURE);
}

Thanks and Regards
Sethu
4 REPLIES 4
John Reagan
Respected Contributor

Re: SYS$GOTO_UNWIND access violation

Why do you think SYS$GOTO_UNWIND is what you want? From your description, SYS$UNWIND seems like the better choice. Also look at ESTABLISH'ing LIB$SIG_TO_RET in the first level Pascal routine as well.
John Gillings
Honored Contributor

Re: SYS$GOTO_UNWIND access violation

Sethu,

GOTO_UNWIND is a big, very ugly hammer to solve a fairly trivial problem. Fundamentally your code calling GOTO_UNWIND has to make numerous assumptions about where it's called from in order to unwind the right number of frames and not break stuff. My guess about why it behaves differently with or without debug or a cout, is the possible presence of additional call frames and/or condition handlers in the region of stack you're trying to unwind across. There are very few circumstances where GOTO_UNWIND is the best tool for the job, and even fewer (if any) where it's the only solution.

As I understand your problem description, you want to be able to call ufl_facility_00 and be somewhere in a call chain below that routine, when you want to just fold up and unwind, returning the the caller of ufl_facility_00. Yes? If that's the case then the simple and robust solution is to declare a condition handler in ufl_facility_00. You can then LIB$SIGNAL from anywhere below. The condition handler can then do anything you want, inuding unwinding to the caller. As John R has suggested, the off-the-shelf handler LIB$SIG_TO_RET. Here's an example of how you'd use it:

TYPE
Sigarr = ARRAY[0..9] OF INTEGER;
Mecharr = ARRAY[0..(SIZE(CHF2$TYPE)-4) DIV 4] OF INTEGER;

[EXTERNAL,ASYNCHRONOUS] FUNCTION LIB$SIG_TO_RET
(VAR Sigargs : Sigarr;
VAR Mechargs : Mecharr) : INTEGER;
EXTERN;
.
.
.
ESTABLISH (LIB$SIG_TO_RET);

etc...
A crucible of informative mistakes
Sethunath K.O
Occasional Advisor

Re: SYS$GOTO_UNWIND access violation

Hi John Reagan & John Gillings

Thanks very much for the response.
I did a code walk through and established LIB$SIG_TO_RET in the function and replaced SYS$GOTO_UNWIND by SYS$ UNWIND. It seems, this is working fine.

Thanks and Regards
Sethu

Sethunath K.O
Occasional Advisor

Re: SYS$GOTO_UNWIND access violation

I did a code walk through and established LIB$SIG_TO_RET in the function and replaced SYS$GOTO_UNWIND by SYS$ UNWIND. It seems, this is working fine.

Thanks to John Reagan and John Gillings for their help.