home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / misc / m2_part1.lha / modula / dice / dice.LHA / dynamic / dynamic.lha / dynamic.doc < prev    next >
Encoding:
Text File  |  1991-04-29  |  14.8 KB  |  455 lines

  1.  
  2.                 DYNAMIC.DOC
  3.  
  4. dynamic.library/overview.dynamic
  5. dynamic.library/GetHyperSymbol
  6. dynamic.library/RelsHyperSymbol
  7. dynamic.library/FlushHyperLib
  8. dynamic.library/LockHyperLib
  9. dynamic.library/UnLockHyperLib
  10. dynamic.library/ScanHyperLib
  11. dynamic.library/DumpHyperLibStatus
  12. dynamic.library/SetHyperDebug
  13.  
  14. dynamic.library/overview.dynamic        dynamic.library/overview.dynamic
  15.  
  16.     DYNAMIC.LIBRARY is a shared library which provides dynamic object
  17.     linking and loading.  When a program requests a variable or procedural
  18.     symbol the library will dynamically load the appropriate object module
  19.     into memory.  Furthermore, the library will load any additional
  20.     object modules required for the requested one to function, thereby
  21.     providing a linking capability.
  22.  
  23.     The library fully tracks all object modules, the FlushHyperLib()
  24.     call will not flush currently active modules.  The library will
  25.     automatically link and load any object module or JOIN type library in
  26.     the DO: directory. DO: is usually an assignment.  This capability will
  27.     be expanded to a general path in future versions of the library.
  28.  
  29.     Object modules and libraries in the DO: directory MUST be compiled with
  30.     the large code and large data models.  They MUST be reentrant, which
  31.     means handling any global variables in a non-destructive manner when
  32.     called simultaniously from different programs.  This generally means
  33.     semaphores.
  34.  
  35.     Any given object module may define two special routines:
  36.  
  37.     long
  38.     _auto_start()
  39.     {
  40.         ...
  41.     }
  42.  
  43.     void
  44.     _auto_exit()
  45.     {
  46.         ...
  47.     }
  48.  
  49.     These are both optional.  When a module is completely linked and loaded
  50.     the _auto_start() vector will automatically be called by dynamic.library
  51.     in an atomic fashion (i.e. while it holds a semaphore).  This code is
  52.     meant to initialize various aspects of the object module.  For example,
  53.     an object module whos sole purpose is to open "dos.library" would
  54.     declare DOSBase and it's _auto_start() code would then open the library
  55.     and initialize the base variable.  _auto_start() returns 1 on success,
  56.     0 on failure.
  57.  
  58.     A failure code causes the object module to be unloaded and modules that
  59.     rely on it to fail as well, eventually propogating back to the library
  60.     call that started it all.
  61.  
  62.     The _auto_exit() procedure, if it exists, is called just before an
  63.     object module is unloaded.    Using the same example, this procedure
  64.     would close the "dos.library".
  65.  
  66.     NOTE: THE _auto_exit() PROCEDURE, IF IT EXISTS, IS CALLED EVEN IF
  67.     _auto_start() FAILS.  This is actually a feature if you think about
  68.     it, _auto_start() need not back-out of its initialization if an error
  69.     occurs, instead letting _auto_exit() deal with it.  However, you some
  70.     precautions must be taken.    Here is the full example:
  71.  
  72. /*
  73.  *  DOS.C   dos.library support
  74.  */
  75.  
  76. #include <exec/types.h>
  77. #include <exec/libraries.h>
  78. #include <clib/exec_protos.h>
  79.  
  80. typedef struct Library Library;
  81.  
  82. Library *hyper_DOSBase;
  83.  
  84. long
  85. _auto_start()
  86. {
  87.     if (hyper_DOSBase = OpenLibrary("dos.library", 0))
  88.     return(1);
  89.     return(0);
  90. }
  91.  
  92. void
  93. _auto_exit()
  94. {
  95.     if (hyper_DOSBase) {
  96.     CloseLibrary(hyper_DOSBase);
  97.     hyper_DOSBase = NULL;
  98.     }
  99. }
  100.  
  101.     Any symbol in the object module that is to be exported (made available
  102.     to other object modules) must be declared 'hyper_<symbol>'.  The
  103.     modules that reference this symbol reference it normally.  In the
  104.     example above you will note that while DOSBase is declared
  105.     hyper_DOSBase, the startup code still calls 'OpenLibrary' to open the
  106.     library, NOT hyper_OpenLibrary().
  107.  
  108.     This ensures that only the symbols the programmer wants to be exported
  109.     will be exported.
  110.  
  111.     _auto_start() and _auto_exit() are special cases as they are dealt with
  112.     by the library directly.
  113.  
  114.     Since a reference count is kept for each object module's dependancy on
  115.     other object modules, unloading is guarenteed to occur in reverse
  116.     dependancy order, meaning that a module like the above would be unloaded
  117.     last .. almost last, OpenLibrary() and CloseLibrary() would be unloaded
  118.     after the above example, with the module associated with SysBase
  119.     unloaded at the very last.
  120.  
  121.                   DICE SUPPORT
  122.  
  123.     As of the next release of DICE, direct compiler support of this
  124.     library will exist.  DICE is not required, but if the idea catches
  125.     on other compilers might follow suite.  The DICE support consists of
  126.     a new storage qualifier called __dynamic.  Declaring a variable
  127.     __dynamic basically tells DICE that this variable exists externally
  128.     (i.e. doesn't exist at link time).  DICE will actually declare storage
  129.     for a pointer and the dynamically determine the pointer to the
  130.     storage/procedure at program run time.  A failure causes an error
  131.     message to be output and the program to exit before _main is called.
  132.  
  133.     DICE silently generates an indirection for all references to the
  134.     variable thus making operation almost entirely transparent.  An
  135.     example program follows:
  136.  
  137.  
  138. /*
  139.  *  DOS.C
  140.  */
  141.  
  142. __dynamic void DosTest(void);
  143.  
  144. main()
  145. {
  146.     printf("DosTest is loaded as: %08lx\n", DosTest);
  147.     DosTest();
  148.     puts("That's it!");
  149.     return(0);
  150. }
  151.  
  152.     Pretty easy eh?  Variables may be declared in the same manner to
  153.     reference shared globals loaded via the library.  This is an excellent
  154.     way to program a shared global semaphore, for example, without the
  155.     hassel.  The _auto_start() code in the object module declaring the
  156.     semaphore would initialize it, thus nothing need be done by the
  157.     calling program except Obtain and Release it.
  158.  
  159.     The only cavet is that in terms of the DICE support, you must declare
  160.     the procedure/variable as non-extern __dynamic just once.  All other
  161.     declarations MUST have the extern storage qualifier.  You may not
  162.     reference a dynamic variable/procedure unless it is prototyped as
  163.     a dyamic variable/procedure.  Not too much of a cavet.
  164.  
  165.     Note that you can load / release dynamic symbols via the dynamic.library
  166.     calls at any time.    The __dynamic storage qualifier will do all loading
  167.     at startup and unloading at exit but you are not limited to this type
  168.     of operation run-time, simply make the library calls yourself if you
  169.     need truely dynamic loading.
  170.  
  171.                   CURRENT LIMITATIONS
  172.  
  173.     * object modules must be compiled large-data + large-code.
  174.       This may stick around for a long while.  It actually isn't
  175.       much of a problem since object modules are expected to have
  176.       library-style reentrancy (so their code can be shared).
  177.  
  178.       Since object modules are not loaded into the same memory block
  179.       supporting small-code is pretty useless since it would require
  180.       a jump table anyway, and small-data would require a separate A4
  181.       pointer for each object module and tag code to load it, slowing
  182.       down interface calls to a great degree (at this point interface
  183.       calls basically direct calls to the loaded module)
  184.  
  185.     NEWLY IMPLEMENTED
  186.  
  187.       full support for CHIP hunks and JOIN style libraries exists.
  188.  
  189.     FUTURE TRENDS
  190.  
  191.     The tags are definitely going to be used.  For one, there is no
  192.     current way to specify *which* procedure you want to use when
  193.     several object modules contain the same procedure (i.e. in terms
  194.     of one overriding the other).  (see below)
  195.  
  196.     more as I think of it ..  comments are welcome!
  197.  
  198.     UTILITIES
  199.  
  200.     A new FDTOLIB (a DICE utility) is included and now has the capability
  201.     to generate hyper_* library tags from .FD files.  You also need the
  202.     DICE DAS (also included) to run FDTOLIB.
  203.  
  204.  
  205.  
  206. dynamic.library/GetHyperSymbol            dynamic.library/GetHyperSymbol
  207.  
  208.     NAME
  209.     GetHyperSymbol - get pointer to external object module symbol
  210.  
  211.     SYNOPSIS
  212.     #include <dynamic.h>
  213.  
  214.     void *ptr = GetHyperSymbol(symName, tagPtr);
  215.     void *ptr = GetHyperSymbolTags(symName, Tag tag1, ...);
  216.  
  217.     const char *symName;
  218.     TagItem *tagPtr;
  219.  
  220.     FUNCTION
  221.     GetHyperSymbol() searches for the specified symbol amount object
  222.     files in the DO: directory.  When found, the object module in
  223.     question will be loaded (or may already be loaded).  An object
  224.     module that references other object modules will cause the
  225.     others to be brought in as well, and so on until all external
  226.     references are resolved.
  227.  
  228.     NOTE that the object module is NOT linked to the caller's code in
  229.     any way (i.e. no dynamic linking to the caller's code via the
  230.     caller's symbol table).  The two main reasons this is not done
  231.     are:  (1) caller may not have a symbol table or may be resident,
  232.     (2) object modules cannot be reentrant / tracking becomes impossible.
  233.  
  234.     GetHyperSymbol() may be used to retrieve a pointer to a procedure
  235.     or variable.
  236.  
  237.     When you GetHyperSymbol() some symbol name, such as "_fubar", the
  238.     actual exported symbol in the object module must be '_hyper_fubar'.
  239.     Remember that C generally sticks the first underscore on itself,
  240.     please refer to the example code for appropriate usage.
  241.  
  242.     If an object module in DO: references a symbol _xx defined in some
  243.     other object module, the definition in the other object module
  244.     must be _hyper_xx.  Again, see the examples.
  245.  
  246.     You can use SetHyperDebug() or the HDEBUG utility program to
  247.     enable library debugging to determine why a complex symbol request
  248.     has failed (i.e. brings up many object modules)
  249.  
  250.     INPUTS
  251.     const char *symName;        pointer to the full symbol name,
  252.                     (including any underscores)
  253.  
  254.     TagItem *tagPtr;        pointer to a tag list, must currently
  255.                     be set to NULL.  If using the var-args
  256.                     call you must terminate the list
  257.                     with TAG_END.
  258.  
  259.  
  260.     RESULTS
  261.     void *ptr;            pointer to the procedure / variable
  262.                     requested or NULL
  263.  
  264. dynamic.library/RelsHyperSymbol         dynamic.library/RelsHyperSymbol
  265.  
  266.     NAME
  267.     RelsHyperSymbol - release pointer to external object module symbol
  268.  
  269.     SYNOPSIS
  270.     #include <dynamic.h>
  271.  
  272.     (void) RelsHyperSymbol(ptr, tagPtr);
  273.     (void) RelsHyperSymbolTags(ptr, Tag tag1, ...);
  274.  
  275.     void *ptr;
  276.     TagItem *tagPtr;
  277.  
  278.     FUNCTION
  279.  
  280.     releases the procedure or variable reference obtained by
  281.     GetHyperSymbol*().  You must call RelsHyperSymbol*() to release
  282.     a loaded object module by the pointer returned by Get*().
  283.     If you have called GetHyperSymbol*() multiple times for the
  284.     same symbol you must call RelsHyperSymbol*() an equivalent
  285.     number of times to release it.
  286.  
  287.     DICE's __dynamic keyword support automatically calls Get*() and
  288.     Rels*() routines for you, making operation nearly transparent.
  289.  
  290.     INPUTS
  291.     void *ptr;        Pointer previously obtained by
  292.                 GetHyperSymbol*().  NULL may be safely
  293.                 passed and results in a no-operation.
  294.  
  295.     TagItem *tagPtr;    Currently not used, tagPtr must be set to
  296.     (or taglist)            NULL.  If the var-args routine is used it
  297.                 must be immediately terminated with TAG_END.
  298.  
  299.     RESULTS
  300.     none
  301.  
  302.  
  303. dynamic.library/FlushHyperLib            dynamic.library/FlushHyperLib
  304.  
  305.     void FlushHyperLib(void);
  306.  
  307.     FUNCTION
  308.  
  309.     Flushes any loaded object modules that are not currently being
  310.     referenced.  Also sets a rescan flag for the DO: directory.  This
  311.     function is normally called when the user installs or changes
  312.     object files in the DO: directory.
  313.  
  314.     Currently the library will not deinstall loaded modules not in
  315.     use automatically, you have to make this call to free up unused
  316.     loaded modules.
  317.  
  318. dynamic.library/LockHyperLib            dynamic.library/LockHyperLib
  319.  
  320.     NAME
  321.     LockHyperLib - obtain the library's master semaphore
  322.  
  323.     SYNOPSIS
  324.     #include <dynamic.h>
  325.  
  326.     void LockHyperLib(void)
  327.  
  328.     FUNCTION
  329.     This function obtains the exclusive semaphore used by the library
  330.     to ensure non-simultanious access.  It effectively blocks all
  331.     library calls except those made by the task that has obtained
  332.     the semaphore through this call.
  333.  
  334.     You may obtain this semaphore multiple times, and must release
  335.     the semaphore the same number of times.
  336.  
  337. dynamic.library/UnLockHyperLib            dynamic.library/UnLockHyperLib
  338.  
  339.     NAME
  340.     UnLockHyperLib - release semapohre obtained with LockHyperLib
  341.  
  342.     SYNOPSIS
  343.     #include <dynamic.h>
  344.  
  345.     void UnLockHyperLib(void)
  346.  
  347.     FUNCTION
  348.     This function releases the library's semaphore.  You must have
  349.     previously obtained the semaphore.
  350.  
  351.  
  352. dynamic.library/DumpHyperLibStatus      dynamic.library/DumpHyperLibStatus
  353.  
  354.     NAME
  355.     DumpDynamicLibStatus - make an ascii dump of the library's status
  356.  
  357.     SYNOPSIS
  358.     #include <dynamic.h>
  359.  
  360.     void DumpDynamicLibStatus(fh, verbose)
  361.     BPTR fh;
  362.     long verbose;
  363.  
  364.     FUNCTION
  365.     This function generates an ascii dump of the library's current
  366.     status.  The verbosity level determines how much to dump.
  367.  
  368.     verbose = 0    dump only the library headers and active object
  369.             module information
  370.  
  371.     verbose = 1    additionally, dump all library symbols whether
  372.             they are active or not.  However, libraries with
  373.             more than 50 symbols are not dumped.
  374.  
  375.     verbose = 2    dump all library symbols, period.
  376.  
  377.     Note that specifying a verbosity of 2 may take upwards of minutes
  378.     to run if you have a large library installed in DO:, such as
  379.     amiga.lib.  This is due to the fact that to display actual symbol
  380.     names the system must go to disk.  It is not desireable for the
  381.     library to load all symbols into memory due to the number of
  382.     symbols that could be involved.  Instead, the library loads a
  383.     much smaller hash table of hash values, bring symbol names in
  384.     only on a cache basis.
  385.  
  386.     INPUTS
  387.     BPTR fh;        file handle to dump to.  You may specify NULL
  388.                 to dump to Output().
  389.  
  390.     long verbose        verbosity level, 0, 1, or 2 currently.
  391.  
  392.  
  393.     RESULTS
  394.     void *ptr;            pointer to the procedure / variable
  395.                     requested or NULL
  396.  
  397.  
  398. dynamic.library/SetHyperDebug            dynamic.library/SetHyperDebug
  399.  
  400.     NAME
  401.     SetHyperDebug - set debugging mode to find load errors
  402.  
  403.     SYNOPSIS
  404.     #include <dynamic.h>
  405.  
  406.     void SetHyperDebug(fh, level)
  407.     BPTR fh;
  408.     long level;
  409.  
  410.     FUNCTION
  411.     This function enables printing of error messages to the file
  412.     handle specified.  Specifying a file handle of NULL *disables*
  413.     printing.  You also specify a debug level, you must specify a
  414.     debug level of 1 to enable error messaging printing as well.
  415.  
  416.     Normally you call SetHyperDebug(Output(), 1); to generate error
  417.     messages to the CLI.  The CLI must not be closed while
  418.     dynamic.library has it's file handle installed!
  419.  
  420.     Currently the library will generate an error message for any
  421.     symbol it cannot find, making debugging a bit easier.  If
  422.     the library reports being unable to reference a symbol and the
  423.     _hyper_<symbol> does exist, then the object module in question
  424.     most likely attempts to do relocations that the library cannot
  425.     handle.  Currently only large-data, large-code, and absolute
  426.     symbol relocation (e.g. LVO symbols) is supported.
  427.  
  428.     INPUTS
  429.     BPTR fh;        file handle to dump to, NULL to uninstall.
  430.  
  431.     long verbose        debug level, 0 or 1 currently.
  432.  
  433. dynamic.library/ScanHyperLib          dynamic.library/ScanHyperLib
  434.  
  435.     NAME
  436.     ScanHyperLib - causes the library to rescan DO:
  437.  
  438.     SYNOPSIS
  439.     #include <dynamic.h>
  440.  
  441.     void ScanHyperLib(void)
  442.  
  443.     FUNCTION
  444.     This function causes the library to rescan DO:    Any new or modified
  445.     object modules that are not currently referenced will be rescanned.
  446.  
  447.     BUGS
  448.     Currently this function doesn't delete it's symbol list for object
  449.     modules you have deleted or renamed.  The workaround is to call
  450.     FlushHyperLib().
  451.  
  452.  
  453.  
  454.  
  455.