Beruflich Dokumente
Kultur Dokumente
Barry Lichtenstein
IBM Poughkeepsie
BarryL@us.ibm.com
ŸTerms
ŸDLL Overview
ŸHow to Write DLL-enabled code
ŸHow to Build DLLs and DLL Applications
ŸExecuting with DLLs
ŸMore than you ever wanted to know about DLL Linkage
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 2
Terms
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 3
Compiler Support for DLLs
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 4
Static versus Dynamic Linking (or Binding)
Library of
routines Application
Application
Library of Program
Program
routines
Binder
(or Prelink/Link)
Binder
Binder Side (or Prelink/Link)
(or Prelink/Link) deck
Dll Appl
Executable Executable Executable
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 5
Building an Executable (DLL or DLL App)
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 6
A few words about Rentrancy...
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 8
What's so special about DLL-enabled code?
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 9
What's so special about DLL-enabled code?
DLL
DLL Appl
{ .... datatype X;
call dllFn(); dllFn() {return;}
.... }
Function Descriptor
dllFn Addr X
DLL's WSA Addr
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 10
High-level Structure of your Application
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 12
Writing Assembler DLL Code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 13
Writing Your COBOL/PLI DLL Code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 14
Writing Your DLL Code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 15
Writing Your C/C++
DLL Application Code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 16
Writing Your Assembler
DLL Application Code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 17
Writing Your Assembler
DLL Application Code (cont…)
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 18
Writing Your COBOL/PLI
DLL Application Code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 19
(Implicit) C Example
sigcaught = signumber;
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 20
COBOL Example
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 21
PL/I Example
DISPLAY('End of VAPLIDLA.');
END;
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 22
Assembler Example
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 23
Other Externals for DLL support
Environment variable
Specify path name(s) to search for DLLs in the HFS:
LIBPATH <:>pathname<:pathname><:>
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 24
New Single UNIX ® Specification Externals for
DLL support
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 27
Explicit High Level Assembler Example
DLL Application (ASMDLLE) (2 of 5) DLL Application (ASMDLLE) (3 of 5)
* *
* Locate a DLL variable; * Locate a DLL function;
* If successful, change value to 7 * If successful, call the function
* *
**** var_ptr = dllqueryvar **** fn_ptr = dllqueryfn(dlltoken,
* (dlltoken,var_name) * fn_name)
* *
LA R1,VAR_NAME LA R1,FN_NAME
ST R1,PARMNAME ST R1,PARMNAME
LA R1,PARMLIST LA R1,PARMLIST
L R15,DLLQUERYVAR L R15,DLLQUERYFN
BASR R14,R15 BASR R14,R15
LTR R15,R15 LTR R15,R15
ST R15,VAR_PTR ST R15,FN_PTR
JZ REPORT JZ REPORT
LA R9,7 CALL (15),(5)
ST R9,0(R15)
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 28
Explicit High Level Assembler Example
DLL Application (ASMDLLE) (4 of 5) DLL Application (ASMDLLE) (5 of 5)
* VAR_PTR DS F * address of DLL variable
FN_PTR DS F * address of DLL function
* Free the DLL * C RTL DLL functions (from dll.h)
* EXTRN @@DLLOAD * dllload()
DLLLOAD DC A(@@DLLOAD)
**** dllfree(dlltoken) EXTRN @@DLLQRV * dllqueryvar()
DLLQUERYVAR DC A(@@DLLQRV)
*
EXTRN @@DLLQRF * dllqueryfn()
XR R1,R1 DLLQUERYFN DC A(@@DLLQRF)
EXTRN @@DLLFRE * dllfree()
ST R1,PARMNAME DLLFREE DC A(@@DLLFRE)
LA R1,DLLTOKEN CNOP 2,4
DLLNAME DS 0CL7 * NULL-terminated
L R15,DLLFREE DC CL6'CDLL12' * ... DLL name
BASR R14,R15 DC X'00'
CNOP 2,4
VAR_NAME DS 0CL7 * NULL-terminated
SR R15,R15 DC CL6'dllvar' * ... variable name
DC X'00'
RETURN DS 0H CNOP 2,4
FN_NAME DS 0CL8 * NULL-terminated
CEETERM RC=(R15),MODIFIER=0
DC CL7'dllfunc' * ... function name
* DC X'00'
DS 0F
REPORT DS 0H PARMLIST DS 0CL8 * Parms to dll*() calls
* Report error here DLLTOKEN DC A(0)
PARMNAME DC A(0)
J RETURN APPLPPA CEEPPA
* LTORG
CEEDSA
* CEECAA
END ASMDLLE
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 29
Compiling Your DLL and DLL Application
ŸC
§DLL and DLL Application:
ŸCompile with options: DLL, RENT, LONGNAME, and possibly
EXPORTALL for DLLs
ŸC++
§No special options (always DLL-enabled code), except possibly
EXPORTALL for DLLs
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 30
Compiling Your DLL and DLL Application
ŸCOBOL
§DLL:
ŸCompile with options: DLL, RENT, EXPORTALL
§DLL Application:
ŸCompile with options: DLL, RENT, NOEXPORTALL
ŸPL/I
§DLL:
ŸCompile with options: DLLINIT, RENT (Enterprise PL/I only)
§DLL Application:
ŸRENT (Enterprise PL/I only)
ŸHigh Level Assembler
§Assemble with GOFF option
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 31
Assembler DLL macro summary
Export/Call requires:
• GOFF
• >=PM3/4
non-XPLink XPLink AMODE 64
CEETERM
Function Eplilog EDCEPLG EDCXEPLG CELQEPLG
CEEDSA CEEDSA
DSA mapping EDCDSAD DSASZ includes DSASZ includes
arguments arguments
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 32
Definition Side Deck
ŸA side deck is a flat file created for a DLL to represent its exported
variables and functions
ŸContents of side deck are Binder IMPORT control statements
ŸVariable and function names are produced in alphabetic order
ŸSide deck(s) for DLLs used by an applicaion must be specified at link-
edit time
§Beginning z/OS R6 Binder will use remembered IMPORTs (available
with PO4 and later formats)
ŸSide decks are not used for explicit loading
ŸSide decks may be edited if desired to remove unneeded external
references
§Be careful!! Side decks are FB 80, with NO newline chars!!
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 33
Sample Definition Side Deck
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 34
Binding Your Code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 35
Characteristics of DLLs
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 36
When are DLLs loaded?
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 37
Where are DLLs loaded from?
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 38
Where are DLLs loaded from?
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 40
LE DLL Load Mechanism
DLL Appl A DLL Appl A calls dllfunc1, which DLL Appl B
main() { resides in DLL X (resolved at Bind applB() {
... time via side deck). ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 41
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Call LE "trigger DLL load on Call" applB() {
... routine. ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 42
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Determine if the DLL is already applB() {
... loaded in this enclave. ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 43
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Has DLL been loaded into this applB() {
... enclave before? ...
dllfunc1(); No -- Obtain and Init WSA dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 44
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Resolve all descriptors (and variable applB() {
... references) to DLL X (only) ...
dllfunc1(); dllfunc2();
in DLL Appl A's WSA
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 45
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Complete call to dllfunc1(). applB() {
... ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 46
LE DLL Load Mechanism
DLL Appl A dllfunc1() returns directly to DLL Appl B
main() { DLL Appl A. applB() {
... ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 47
LE DLL Load Mechanism
DLL Appl A Subsequent calls and references to DLL Appl B
main() { this DLL are direct. applB() {
... ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 48
LE DLL Load Mechanism
DLL Appl A Subsequent calls and references to DLL Appl B
main() { this DLL are direct. applB() {
... ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 49
LE DLL Load Mechanism
DLL Appl A Subsequent calls and references to DLL Appl B
main() { this DLL are direct. applB() {
... ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 50
LE DLL Load Mechanism
DLL Appl A DLL Appl B (separate program object DLL Appl B
main() { with its own WSA)gets control and applB() {
... calls dllfunc2(), also resolved at Bind ...
dllfunc1(); dllfunc2();
time via side deck.
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 51
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Call LE "trigger DLL load on Call" applB() {
... routine. ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 52
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Determine if the DLL is already applB() {
... loaded in this enclave. ...
dllfunc1(); dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 53
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Has DLL been loaded into this applB() {
... enclave before?? ...
dllfunc1(); Yes -- use previously-obtained WSA. dllfunc2();
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 54
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Resolve all descriptors (and variable applB() {
... references) to DLL X (only) ...
dllfunc1(); dllfunc2();
in DLL Appl B's WSA
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 55
LE DLL Load Mechanism
DLL Appl A What is LE doing? DLL Appl B
main() { Complete call to dllfunc2() applB() {
... and then return directly to ...
dllfunc1(); dllfunc2();
DLL Appl B.
... ...
dllfunc2(); }
}
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 56
Restrictions on DLLs
ŸLimited support for mixing DLLs and COBOL Dynamic Call (see
COBOL Programming Ref)
Ÿ"Physical" loading of DLLs is not supported while C++
destructors are running ("Logical" load ok)
ŸDLLs must be linkedited as REENTRANT!!
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 57
Performance Considerations
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 58
Shared Libraries (in OS/390 V2R9 and up)
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 59
System Shared Libraries
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 60
User Shared Libraries
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 61
More on Shared Libraries
ŸVirtual address chosen for the executable on its first load will be
used on all subsequent loads from all other address spaces, if
possible
ŸIf the load cannot be mapped at shareable address, then it will be
treated as a non-shared private area load module, loaded into user
private storage
§Chance of address conflict much lower with System Shared
Libraries
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 62
DLL considerations for XPLINK-compiled code
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 63
Non-DLL function linkage
caller()
"NODLL"
function pointer foo()
L r15,=V(foo) V(foo)
BALR r14,r15
Note that:
Ÿcaller() and foo() must be statically linked, or
Ÿfoo is entry point of LOADed module
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 64
DLL function linkage
caller()
DLL function
descriptor foo()
LM r15,r0,fd+8 +0 NODLL glue
ST r0,CAACRENT +8
BALR r14,r15 V(foo)
A(foo's WSA)
+16
DLL load
info
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 65
XPLINK function linkage
caller() XPLINK
"compatibility"
descriptor
foo() (compiled XPLINK)
LM r5,r6,xd+16 +0 NODLL glue
BASR r7,r6 +8
NOP ... A(this xd)
A(RunOnDown)
+16
R(XPL env)
V(foo)
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 66
AMODE 64 function linkage
caller() AMODE 64
descriptor
foo() (compiled LP64)
LMG r5,r6,d64+0 +0 RD(XPL env)
BASR r7,r6
NOPR ... +8 VD(foo)
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 67
Compatibility Issues -- Calls By Pointer
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 68
Compatibility Issues -- Function Pointer
Comparison
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 69
Compatibility Issues --
Calling non-XPLINK from XPLINK
XPLINK
caller() "compatibility"
descriptor
foo() (compiled NOXPLINK)
LM r5,r6,xd+16 +0 NODLL glue
BASR r7,r6 +8
NOP ... V(foo)
A(foo's WSA)
+16
A(this xd)
V(RunOnUp)
ŸPrelinker ŸBinder
AS INITIALIZED AS INITIALIZED
+0 0 +0 0
+4 DLL index +4 A(DLL entry in IEWBCIE)
+8 A(C sig CSECT) +8 A(CEESTART)
+C A(DLL appl's WSA) +C A(DLL appl's WSA)
ŸXPLINK
§no descriptor
§fullword w/real addr
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 71
DLL-compiled Function Descriptors
ŸPrelinker ŸBinder
AS INITIALIZED AS INITIALIZED
+0 LR R0,R15 +0 LR R0,R15
L R15,16(R15) L R15,16(R15)
BR R15 BR R15
+8 A(@@TRGLOC) +8 A(CEETLOC)
+C A(descriptor) +C A(descriptor)
+10 A(@@GETFN) +10 A(CEETGTFN)
+14 DLL index +14 A(IEWBCIE entry)
+18 A(C sig CSECT) +18 A(CEESTART)
+1C A(DLL appl's WSA) +1C A(DLL appl's WSA)
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 72
XPLINK-compiled Function Descriptors
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 73
XPLINK-compiled "By Name"
Function Descriptors
AS INITIALIZED
Note: XPLINK Call-by-name
+0 A(IEWBCIE entry)
+4 A(CEETHLOC)
function linkage is slightly
different than the call-by-ptr
AFTER DLL LOAD linkage shown earlier:
+0 A(environment)
LM r5,r6,xd
+4 V(DLL function) BASR r7,r6
NOP ...
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 74
XPLINK-compiled "By Pointer"
Function Descriptors
ŸRepresenting ŸRepresenting
XPLINK-compiled NOXPLINK-compiled
function function
+0 LR R0,R15 +0 LR R0,R15
L R15,12(,R15) L R15,900(,R12)
BR R15 BR R15
+8 A(unique fd) (Note 1) +8 A(nonXPL fn entry point)
+C A(RunOnDown) +C A(nonXPL fn WSA)
+10 A(XPL fn environment) +10 A(this fd)
+14 A(XPL fn entry point) +14 A(RunOnUp) glue
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 75
Function Descriptor
Glue Code "Signature" Summary
SHARE in Anaheim, CA, Feb-Mar 2005 - Session 8121/8271 - Copyright IBM Corp. 2001, 2005 76