Discussion:
Accessing native DLLs from TNS programs
(too old to reply)
Dave
2020-04-21 21:34:35 UTC
Permalink
Hello,

I've been experimenting with accessing native DLLs from TNS programs, as documented in the "Guardian Programmer's Guide" section "Accessing User-provided DLLs from TNS Programs" [1]. It seems to work as advertised, unless the native DLL tries to link with the C runtime. When the loader tries to resolve the runtime DLL, and the other DLLs it references, it fails. I've tried a lot of different things, including explicitly opening the runtime DLLs with dlopen(). Error examples are below. It won't get past failing to load xcrtldll if I don't add define _RLD_FIRST_LIB_PATH. With that define set, it terminates with "corrupted environment".

Has anyone had any success with linking TNS with native DLLs that use the C runtime? I can provide sample code if interested.

Thanks,
Dave


[1] https://support.hpe.com/hpesc/public/docDisplay?docLocale=en_US&docId=emr_na-a00045528en_us


== The TNS program is CLIENT in written in TAL.
== The DLL is LIBDLL written in C.

== Error with =_RLD_FIRST_LIB_PATH not set

tacl> info define =_RLD*
Define Name =_RLDVERBOSE
CLASS MAP
FILE $VOL.#8
tacl> run client
0001:Searching for load file '$VOL.SUBVOL.libdll'.

0002:Opened Library '$VOL.SUBVOL.libdll'

0003:Loaded Library '$VOL.SUBVOL.libdll',
Segment base address = 0x0000000078000000
Rebase amount = 0x0000000000000000

0004:Searching for load file 'xcrtldll' in Public library location.

*** RLD ERROR ***: Internal Error 717 Context#:-1 Context1:NSKKeyBasicCall_ Context2:NSKPubLibsOpenPublicLib
T0893L01 XTNSDLL - OCI/OCA version 25, 2017/08/01
*** TNS Error 4: User-provided DLL $VOL.SUBVOL.libdll could not be dlopen'd
dlopen (6CA005F0->$VOL.SUBVOL.libdll, 1): Internal Error 717
Context#:-1 Context1:NSKKeyBasicCall_ Context2:NSKPubLibsOpenPublicLib
TNS object file: $VOL.SUBVOL.CLIENT
Warning - 2,110 replied error 201 to the OPEN message - continuing
ABENDED: 2,110
CPU time: 0:00:00.000


== Error with =_RLD_FIRST_LIB_PATH not set

tacl> info define =_RLD*
Define Name =_RLDVERBOSE
CLASS MAP
FILE $VOL.#8

Define Name =_RLD_FIRST_LIB_PATH
CLASS SEARCH
SUBVOL0 $SYSTEM.ZDLL002F
tacl> run client
0001:Searching for load file '$VOL.SUBVOL.libdll'.

0002:Opened Library '$VOL.SUBVOL.libdll'

0003:Loaded Library '$VOL.SUBVOL.libdll',
Segment base address = 0x0000000078000000
Rebase amount = 0x0000000000000000

0004:Searching for load file 'xcrtldll' in location '$SYSTEM.ZDLL002F'.

0005:Opened Library '$SYSTEM.ZDLL002F.xcrtldll'

0006:Searching for load file 'xcredll' in location '$SYSTEM.ZDLL002F'.

0007:Opened Library '$SYSTEM.ZDLL002F.xcredll'

0008:Loaded Library '$SYSTEM.ZDLL002F.xcrtldll',
Segment base address = 0x00000000F27D0000
Rebase amount = 0x0000000000000000

0009:Opened Duplicate of Library '$SYSTEM.ZDLL002F.xcredll'

0010:Searching for load file 'XI18NDLL' in location '$SYSTEM.ZDLL002F'.

0011:Opened Library '$SYSTEM.ZDLL002F.XI18NDLL'

0012:Searching for load file 'XICNVDLL' in location '$SYSTEM.ZDLL002F'.

0013:Opened Library '$SYSTEM.ZDLL002F.XICNVDLL'

0014:Searching for load file 'XOSSKDLL' in location '$SYSTEM.ZDLL002F'.

0015:Opened Library '$SYSTEM.ZDLL002F.XOSSKDLL'

0016:Loaded Library '$SYSTEM.ZDLL002F.xcredll',
Segment base address = 0x00000000F2590000
Rebase amount = 0x0000000000000000

0017:Loaded Library '$SYSTEM.ZDLL002F.XI18NDLL',
Segment base address = 0x00000000F3420000
Rebase amount = 0x0000000000000000

0018:Opened Duplicate of Library '$SYSTEM.ZDLL002F.xcredll'

0019:Opened Duplicate of Library '$SYSTEM.ZDLL002F.xcrtldll'

0020:Opened Duplicate of Library '$SYSTEM.ZDLL002F.XICNVDLL'

0021:Loaded Library '$SYSTEM.ZDLL002F.XICNVDLL',
Segment base address = 0x00000000F34A0000
Rebase amount = 0x0000000000000000

0022:Opened Duplicate of Library '$SYSTEM.ZDLL002F.xcredll'

0023:Opened Duplicate of Library '$SYSTEM.ZDLL002F.xcrtldll'

0024:Opened Duplicate of Library '$SYSTEM.ZDLL002F.XI18NDLL'

0025:Loaded Library '$SYSTEM.ZDLL002F.XOSSKDLL',
Segment base address = 0x00000000F29F0000
Rebase amount = 0x0000000000000000

0026:Opened Duplicate of Library '$SYSTEM.ZDLL002F.xcredll'

0027:Opened Duplicate of Library '$SYSTEM.ZDLL002F.xcrtldll'

Warning - 2,136 replied error 201 to the OPEN message - continuing
ABENDED: 2,136
CPU time: 0:00:00.001
Corrupted environment
tacl>
R***@sbcglobal.net
2020-04-22 19:20:09 UTC
Permalink
I’m wondering just how the native C/CRE runtime finds the MCB/FCB information that is placed in the TNS object file for use by the TNS C/CRE runtime (at the very beginning of the upper 32KB of the stack). In native mode, they are placed in a different location. Also, even if the runtime data structures were found, it is likely that those data structures are different due to different alignment rules.

I remember seeing “Corrupted Environment” when the MCB didn’t have the proper id at the beginning.

I’m surprised that the documentation doesn’t say anything about this, but it may be that their focus was simply on the program linking problem and not the runtime data structure compatibility problems.
R***@sbcglobal.net
2020-04-22 22:42:07 UTC
Permalink
The C/C++ Programmer's Guide has this to say:

CRE Service Function Messages
The CRE writes the messages in this subsection if an error occurs during its own processing or if it receives a request from a run-time library to report a specific message.
11
Corrupted environment
Message Explanation
Cause
CRE or run-time library data is invalid.
Effect
The CRE invokes PROCESS_STOP_, specifying the ABEND variant and the text “Corrupted environment.”
Recovery
In the TNS environment, the program might have written data in the upper 32K words of the user data segment. The upper 32K words are reserved for TNS CRE and run-time library data.
In the native environment, the run-time environment has been corrupted. You may have written data over run-time data structures.
Check the program’s logic. Use a symbolic debugger to help isolate the problem or consult your system administrator.
Dave
2020-04-29 16:22:33 UTC
Permalink
Rich,

Belated thanks for your reply. I've found that simply linking in XCRTLDLL causes the "corrupted environment" error. You can link in XCREDLL and the program runs but not all of the CRE functions work. The heap functions don't, which might be due to lack of CRE initialization or CRE corruption. Who knows.
Loading...