JCC - Dynamically loading objects into running programs.

With reentrant programs generated by JCC, new code objects can be loaded at run-time and executed as if the object had been prelinked and linked like the rest of the program. To load a dynamic object, a standard rent object from the JCC compiler should be placed into a partitioned or sequential dataset which can be accessed at run-time.

_jcc_load accepts the filename of the object to load and returns a pointer to a handle, that can be used only to '_jcc_unload' that object. To access new functions and variables which are stored within the new object, the _jcc_deref function will return the addresses of loaded symbols within the object. To make your own additional externals available (library routines are automatically made available) use the _jcc_adref function to register new name/addresses.

Loading objects will fail (gracefully) if any external reference cannot be resolved, or any number of other factors cause the object to 'look' corrupt. NULL is returned by _jcc_load in these cases.

From the <jccload.h> header file:

void * _jcc_load   (char * file);
// Returns: a handle to a loaded object
//
// file is the pathname & optionally a membername of the object to read
// - Once loaded, new symbols will be available with _jcc_deref.
//
// Errors:
// -------
// ENOENT        - File not found / couldn't be opened.
// ENOSPC        - The internal limit (1024) has been reached.
// EINVAL        - The Object was corrupt.
// EADDRNOTAVAIL - A missing reference prevents loading.
//
// char * _jcc_load_reference [256]; contains thread-specific missing
// references for when errno has been set to EADDRNOTAVAIL but the
// following #define _jcc_load_myref will also access this pointer.

extern char * _jcc_load_reference [256];
#define _jcc_load_myref _jcc_load_reference [athreadid()]

int    _jcc_unload (void * handle);
// Returns: Boolean 0-OK 1-Error
//
// WARNING:
// It would be a good assumption to make unloads order specific since any
// new object may refer to previously loaded ext.identifiers...
// - The library will delete code for which pointers are still held elsewhere.

void * _jcc_deref  (char * identifier);
// Returns: The identifier address or NULL if unknown.

int    _jcc_adref  (char * name, void * entry);
// Returns: Boolean 0-OK
//
// Adds a user-address to the run-time symbol table, and may replace
// existing identifiers or remove them (using entry = NULL.)
// - user-addresses are not deleted when an object is unloaded.