4 * This procedure provides a version of the TclLoadFile that works
5 * under OSF/1 1.0/1.1/1.2 and related systems, utilizing the old OSF/1
6 * /sbin/loader and /usr/include/loader.h. OSF/1 versions from 1.3 and
7 * on use ELF, rtld, and dlopen()[/usr/include/ldfcn.h].
10 * OSF/1 1.0, 1.1, 1.2 (from OSF)
11 * includes: MK4 and AD1 (from OSF RI)
12 * OSF/1 1.3 (from OSF) using ROSE
13 * HP OSF/1 1.0 ("Acorn") using COFF
15 * This is likely to be useful for:
16 * Paragon OSF/1 (from Intel)
17 * HI-OSF/1 (from Hitachi)
19 * This is NOT to be used on:
20 * Digitial Alpha OSF/1 systems
21 * OSF/1 1.3 or later (from OSF) using ELF
22 * includes: MK6, MK7, AD2, AD3 (from OSF RI)
24 * This approach to things was utter @&^#; thankfully,
25 * OSF/1 eventually supported dlopen().
27 * John Robert LoVerso <loverso@freebsd.osf.org>
29 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
31 * See the file "license.terms" for information on usage and redistribution
32 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
38 #include <sys/types.h>
42 *----------------------------------------------------------------------
46 * Dynamically loads a binary code file into memory and returns
47 * the addresses of two procedures within that file, if they
51 * A standard Tcl completion code. If an error occurs, an error
52 * message is left in the interp's result. *proc1Ptr and *proc2Ptr
53 * are filled in with the addresses of the symbols given by
54 * *sym1 and *sym2, or NULL if those symbols can't be found.
57 * New code suddenly appears in memory.
59 *----------------------------------------------------------------------
63 TclpLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr, clientDataPtr)
64 Tcl_Interp *interp; /* Used for error reporting. */
65 char *fileName; /* Name of the file containing the desired
67 char *sym1, *sym2; /* Names of two procedures to look up in
68 * the file's symbol table. */
69 Tcl_PackageInitProc **proc1Ptr, **proc2Ptr;
70 /* Where to return the addresses corresponding
71 * to sym1 and sym2. */
72 ClientData *clientDataPtr; /* Filled with token for dynamically loaded
73 * file which will be passed back to
74 * TclpUnloadFile() to unload the file. */
79 lm = (Tcl_PackageInitProc *) load(fileName, LDR_NOFLAGS);
80 if (lm == LDR_NULL_MODULE) {
81 Tcl_AppendResult(interp, "couldn't load file \"", fileName,
82 "\": ", Tcl_PosixError (interp), (char *) NULL);
86 *clientDataPtr = NULL;
89 * My convention is to use a [OSF loader] package name the same as shlib,
90 * since the idiots never implemented ldr_lookup() and it is otherwise
91 * impossible to get a package name given a module.
93 * I build loadable modules with a makefile rule like
94 * ld ... -export $@: -o $@ $(OBJS)
96 if ((pkg = strrchr(fileName, '/')) == NULL)
100 *proc1Ptr = ldr_lookup_package(pkg, sym1);
101 *proc2Ptr = ldr_lookup_package(pkg, sym2);
106 *----------------------------------------------------------------------
110 * Unloads a dynamically loaded binary code file from memory.
111 * Code pointers in the formerly loaded file are no longer valid
112 * after calling this function.
118 * Does nothing. Can anything be done?
120 *----------------------------------------------------------------------
124 TclpUnloadFile(clientData)
125 ClientData clientData; /* ClientData returned by a previous call
126 * to TclpLoadFile(). The clientData is
127 * a token that represents the loaded
133 *----------------------------------------------------------------------
135 * TclGuessPackageName --
137 * If the "load" command is invoked without providing a package
138 * name, this procedure is invoked to try to figure it out.
141 * Always returns 0 to indicate that we couldn't figure out a
142 * package name; generic code will then try to guess the package
143 * from the file name. A return value of 1 would have meant that
144 * we figured out the package name and put it in bufPtr.
149 *----------------------------------------------------------------------
153 TclGuessPackageName(fileName, bufPtr)
154 char *fileName; /* Name of file containing package (already
155 * translated to local form if needed). */
156 Tcl_DString *bufPtr; /* Initialized empty dstring. Append
157 * package name to this if possible. */