os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclLoadOSF.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclLoadOSF.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,202 @@
     1.4 +/* 
     1.5 + * tclLoadOSF.c --
     1.6 + *
     1.7 + *	This procedure provides a version of the TclLoadFile that works
     1.8 + *	under OSF/1 1.0/1.1/1.2 and related systems, utilizing the old OSF/1
     1.9 + *	/sbin/loader and /usr/include/loader.h.  OSF/1 versions from 1.3 and
    1.10 + *	on use ELF, rtld, and dlopen()[/usr/include/ldfcn.h].
    1.11 + *
    1.12 + *	This is useful for:
    1.13 + *		OSF/1 1.0, 1.1, 1.2 (from OSF)
    1.14 + *			includes: MK4 and AD1 (from OSF RI)
    1.15 + *		OSF/1 1.3 (from OSF) using ROSE
    1.16 + *		HP OSF/1 1.0 ("Acorn") using COFF
    1.17 + *
    1.18 + *	This is likely to be useful for:
    1.19 + *		Paragon OSF/1 (from Intel) 
    1.20 + *		HI-OSF/1 (from Hitachi) 
    1.21 + *
    1.22 + *	This is NOT to be used on:
    1.23 + *		Digitial Alpha OSF/1 systems
    1.24 + *		OSF/1 1.3 or later (from OSF) using ELF
    1.25 + *			includes: MK6, MK7, AD2, AD3 (from OSF RI)
    1.26 + *
    1.27 + *	This approach to things was utter @&^#; thankfully,
    1.28 + * 	OSF/1 eventually supported dlopen().
    1.29 + *
    1.30 + *	John Robert LoVerso <loverso@freebsd.osf.org>
    1.31 + *
    1.32 + * Copyright (c) 1995-1997 Sun Microsystems, Inc.
    1.33 + *
    1.34 + * See the file "license.terms" for information on usage and redistribution
    1.35 + * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1.36 + *
    1.37 + * RCS: @(#) $Id: tclLoadOSF.c,v 1.11 2002/10/10 12:25:53 vincentdarley Exp $
    1.38 + */
    1.39 +
    1.40 +#include "tclInt.h"
    1.41 +#include <sys/types.h>
    1.42 +#include <loader.h>
    1.43 +
    1.44 +/*
    1.45 + *----------------------------------------------------------------------
    1.46 + *
    1.47 + * TclpDlopen --
    1.48 + *
    1.49 + *	Dynamically loads a binary code file into memory and returns
    1.50 + *	a handle to the new code.
    1.51 + *
    1.52 + * Results:
    1.53 + *	A standard Tcl completion code.  If an error occurs, an error
    1.54 + *	message is left in the interp's result.
    1.55 + *
    1.56 + * Side effects:
    1.57 + *	New code suddenly appears in memory.
    1.58 + *
    1.59 + *----------------------------------------------------------------------
    1.60 + */
    1.61 +
    1.62 +int
    1.63 +TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
    1.64 +    Tcl_Interp *interp;		/* Used for error reporting. */
    1.65 +    Tcl_Obj *pathPtr;		/* Name of the file containing the desired
    1.66 +				 * code (UTF-8). */
    1.67 +    Tcl_LoadHandle *loadHandle;	/* Filled with token for dynamically loaded
    1.68 +				 * file which will be passed back to 
    1.69 +				 * (*unloadProcPtr)() to unload the file. */
    1.70 +    Tcl_FSUnloadFileProc **unloadProcPtr;	
    1.71 +				/* Filled with address of Tcl_FSUnloadFileProc
    1.72 +				 * function which should be used for
    1.73 +				 * this file. */
    1.74 +{
    1.75 +    ldr_module_t lm;
    1.76 +    char *pkg;
    1.77 +    char *fileName = Tcl_GetString(pathPtr);
    1.78 +    CONST char *native;
    1.79 +
    1.80 +    /* 
    1.81 +     * First try the full path the user gave us.  This is particularly
    1.82 +     * important if the cwd is inside a vfs, and we are trying to load
    1.83 +     * using a relative path.
    1.84 +     */
    1.85 +    native = Tcl_FSGetNativePath(pathPtr);
    1.86 +    lm = (Tcl_PackageInitProc *) load(native, LDR_NOFLAGS);
    1.87 +
    1.88 +    if (lm == LDR_NULL_MODULE) {
    1.89 +	/* 
    1.90 +	 * Let the OS loader examine the binary search path for
    1.91 +	 * whatever string the user gave us which hopefully refers
    1.92 +	 * to a file on the binary path
    1.93 +	 */
    1.94 +	Tcl_DString ds;
    1.95 +	native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
    1.96 +	lm = (Tcl_PackageInitProc *) load(native, LDR_NOFLAGS);
    1.97 +	Tcl_DStringFree(&ds);
    1.98 +    }
    1.99 +    
   1.100 +    if (lm == LDR_NULL_MODULE) {
   1.101 +	Tcl_AppendResult(interp, "couldn't load file \"", fileName,
   1.102 +	    "\": ", Tcl_PosixError (interp), (char *) NULL);
   1.103 +	return TCL_ERROR;
   1.104 +    }
   1.105 +
   1.106 +    *clientDataPtr = NULL;
   1.107 +    
   1.108 +    /*
   1.109 +     * My convention is to use a [OSF loader] package name the same as shlib,
   1.110 +     * since the idiots never implemented ldr_lookup() and it is otherwise
   1.111 +     * impossible to get a package name given a module.
   1.112 +     *
   1.113 +     * I build loadable modules with a makefile rule like 
   1.114 +     *		ld ... -export $@: -o $@ $(OBJS)
   1.115 +     */
   1.116 +    if ((pkg = strrchr(fileName, '/')) == NULL) {
   1.117 +        pkg = fileName;
   1.118 +    } else {
   1.119 +	pkg++;
   1.120 +    }
   1.121 +    *loadHandle = pkg;
   1.122 +    *unloadProcPtr = &TclpUnloadFile;
   1.123 +    return TCL_OK;
   1.124 +}
   1.125 +
   1.126 +/*
   1.127 + *----------------------------------------------------------------------
   1.128 + *
   1.129 + * TclpFindSymbol --
   1.130 + *
   1.131 + *	Looks up a symbol, by name, through a handle associated with
   1.132 + *	a previously loaded piece of code (shared library).
   1.133 + *
   1.134 + * Results:
   1.135 + *	Returns a pointer to the function associated with 'symbol' if
   1.136 + *	it is found.  Otherwise returns NULL and may leave an error
   1.137 + *	message in the interp's result.
   1.138 + *
   1.139 + *----------------------------------------------------------------------
   1.140 + */
   1.141 +Tcl_PackageInitProc*
   1.142 +TclpFindSymbol(interp, loadHandle, symbol) 
   1.143 +    Tcl_Interp *interp;
   1.144 +    Tcl_LoadHandle loadHandle;
   1.145 +    CONST char *symbol;
   1.146 +{
   1.147 +    return ldr_lookup_package((char *)loadHandle, symbol);
   1.148 +}
   1.149 +
   1.150 +/*
   1.151 + *----------------------------------------------------------------------
   1.152 + *
   1.153 + * TclpUnloadFile --
   1.154 + *
   1.155 + *	Unloads a dynamically loaded binary code file from memory.
   1.156 + *	Code pointers in the formerly loaded file are no longer valid
   1.157 + *	after calling this function.
   1.158 + *
   1.159 + * Results:
   1.160 + *	None.
   1.161 + *
   1.162 + * Side effects:
   1.163 + *	Does nothing.  Can anything be done?
   1.164 + *
   1.165 + *----------------------------------------------------------------------
   1.166 + */
   1.167 +
   1.168 +void
   1.169 +TclpUnloadFile(loadHandle)
   1.170 +    Tcl_LoadHandle loadHandle;	/* loadHandle returned by a previous call
   1.171 +				 * to TclpDlopen().  The loadHandle is 
   1.172 +				 * a token that represents the loaded 
   1.173 +				 * file. */
   1.174 +{
   1.175 +}
   1.176 +
   1.177 +/*
   1.178 + *----------------------------------------------------------------------
   1.179 + *
   1.180 + * TclGuessPackageName --
   1.181 + *
   1.182 + *	If the "load" command is invoked without providing a package
   1.183 + *	name, this procedure is invoked to try to figure it out.
   1.184 + *
   1.185 + * Results:
   1.186 + *	Always returns 0 to indicate that we couldn't figure out a
   1.187 + *	package name;  generic code will then try to guess the package
   1.188 + *	from the file name.  A return value of 1 would have meant that
   1.189 + *	we figured out the package name and put it in bufPtr.
   1.190 + *
   1.191 + * Side effects:
   1.192 + *	None.
   1.193 + *
   1.194 + *----------------------------------------------------------------------
   1.195 + */
   1.196 +
   1.197 +int
   1.198 +TclGuessPackageName(fileName, bufPtr)
   1.199 +    CONST char *fileName;	/* Name of file containing package (already
   1.200 +				 * translated to local form if needed). */
   1.201 +    Tcl_DString *bufPtr;	/* Initialized empty dstring.  Append
   1.202 +				 * package name to this if possible. */
   1.203 +{
   1.204 +    return 0;
   1.205 +}