Exemplo n.º 1
0
bool loadGLJumpTable( GLJumpTable& jt, const char* dllPath )
{

#ifndef LOAD_JUMPTABLE_STATICALLY
    void *handle = loadDynamicLibrary(dllPath);
    
    if ( !handle ) /* Error loading library */
        panic("", "loadGLJumpTable()","Error getting handle to Dinamic Library");

    int i;
    unsigned int func;    

    unsigned int* ptr = (unsigned int*)&jt;

    for ( i = 0; i < GLResolver::countFunctions(); i++ )
    {        
        func = (unsigned int)getFunction(handle, GLResolver::getFunctionName((APICall)i));
        if ( func ) /* function found */
            ptr[i] = func;
    }

    
    return true;

#else

    // STATICALLY LOAD

    //_this text generate an error _if #_else is selected.

    
#define _JT jt // rename names

    /**
     * Code added (example)
     *
     * ...
     * _JT.glBegin = glBegin;
     *
     * ...
     *
     * _JT.glVertex3f = glVertex3f;
     * ...
     *
     */
    #include "GLJumpTableSL.gen" // SL means: Static Link
    
    return true;

#endif

}
    /**
     * Compiles all models and generates a dynamic library.
     * 
     * @param compiler The compiler used to compile the sources and create
     *                 the dynamic library
     * @param loadLib Whether or not to load the dynamic library
     * @return The dynamic library if loadLib is true, nullptr otherwise
     */
    DynamicLib<Base>* createDynamicLibrary(CCompiler<Base>& compiler,
                                           bool loadLib = true) throw (CGException) {
        // backup output format so that it can be restored
        OStreamConfigRestore coutb(std::cout);

        this->modelLibraryHelper_->startingJob("", JobTimer::DYNAMIC_MODEL_LIBRARY);

        const std::map<std::string, ModelCSourceGen<Base>*>& models = this->modelLibraryHelper_->getModels();
        try {
            for (const auto& p : models) {
                const std::map<std::string, std::string>& modelSources = this->getSources(*p.second);

                this->modelLibraryHelper_->startingJob("", JobTimer::COMPILING_FOR_MODEL);
                compiler.compileSources(modelSources, true, this->modelLibraryHelper_);
                this->modelLibraryHelper_->finishedJob();
            }

            const std::map<std::string, std::string>& sources = this->getLibrarySources();
            compiler.compileSources(sources, true, this->modelLibraryHelper_);

            const std::map<std::string, std::string>& customSource = this->modelLibraryHelper_->getCustomSources();
            compiler.compileSources(customSource, true, this->modelLibraryHelper_);

            std::string libname = _libraryName;
            if (_customLibExtension != nullptr)
                libname += *_customLibExtension;
            else
                libname += system::SystemInfo<>::DYNAMIC_LIB_EXTENSION;

            compiler.buildDynamic(libname, this->modelLibraryHelper_);

        } catch (...) {
            compiler.cleanup();
            throw;
        }
        compiler.cleanup();

        this->modelLibraryHelper_->finishedJob();

        if (loadLib)
            return loadDynamicLibrary();
        else
            return nullptr;
    }
Exemplo n.º 3
0
void PionPlugin::openPlugin(const std::string& plugin_file,
							PionPluginData& plugin_data)
{
	// get the name of the plugin (for create/destroy symbol names)
	plugin_data.m_plugin_name = getPluginName(plugin_file);
	
	// attempt to open the plugin; note that this tries all search paths
	// and also tries a variety of platform-specific extensions
	plugin_data.m_lib_handle = loadDynamicLibrary(plugin_file.c_str());
	if (plugin_data.m_lib_handle == NULL) {
#ifndef PION_WIN32
		char *error_msg = dlerror();
		if (error_msg != NULL) {
			std::string error_str(plugin_file);
			error_str += " (";
			error_str += error_msg;
			error_str += ')';
			throw OpenPluginException(error_str);
		} else
#endif
		throw OpenPluginException(plugin_file);
	}
	
	// find the function used to create new plugin objects
	plugin_data.m_create_func =
		getLibrarySymbol(plugin_data.m_lib_handle,
						 PION_PLUGIN_CREATE + plugin_data.m_plugin_name);
	if (plugin_data.m_create_func == NULL) {
		closeDynamicLibrary(plugin_data.m_lib_handle);
		throw PluginMissingCreateException(plugin_file);
	}

	// find the function used to destroy existing plugin objects
	plugin_data.m_destroy_func =
		getLibrarySymbol(plugin_data.m_lib_handle,
						 PION_PLUGIN_DESTROY + plugin_data.m_plugin_name);
	if (plugin_data.m_destroy_func == NULL) {
		closeDynamicLibrary(plugin_data.m_lib_handle);
		throw PluginMissingDestroyException(plugin_file);
	}
}
Exemplo n.º 4
0
int test1_22_mutatee()
{
    int retval = 0;
#if defined(os_linux_test) \
 || defined(os_windows_test) \
 || defined(os_freebsd_test)
    /* libtestA.so should already be loaded (by the mutator), but we
       need to use the dl interface to get pointers to the functions
       it defines. */
/*     int (*call22_5)(int); */
/*     int (*call22_6)(int); */
    call_type call22_5;
    call_type call22_6; /* Why shadowing the top-level declaration? */

    void *handleA;
    char dlopenName[128];
    int result;
    unused = sprintf(dlopenName, "%s", libNameA);

    handleA = loadDynamicLibrary(dlopenName);
    if (! handleA) {
	 logerror("**Failed test #22 (replaceFunction)\n");
	 logerror("  Mutatee couldn't get handle for %s\n", libNameA);
	 retval = -1; /* Test failed */
    }
    /* call22_5 = (int(*)(int)) getFuncFromDLL(handleA, "call22_5"); */
    call22_5 = (call_type) getFuncFromDLL(handleA, "call22_5a");
    if (! call22_5) {
	 logerror("**Failed test #22 (replaceFunction)\n");
	 logerror("  Mutatee couldn't get handle for call22_5 in %s\n", libNameA);
	 retval = -1; /* Test failed */
    }
    /* call22_6 = (int(*)(int)) getFuncFromDLL(handleA, "call22_6"); */
    call22_6 = (call_type) getFuncFromDLL(handleA, "call22_6");
    if (! call22_6) {
	 logerror("**Failed test #22 (replaceFunction)\n");
	 logerror("  Mutatee couldn't get handle for call22_6 in %s\n", libNameA);
	 retval = -1; /* Test failed */
    }

    /* Call functions that have been replaced by the mutator.  The
       side effects of these calls (replaced, not replaced, or
       otherwise) are independent of each other. */
    result = test1_22_call1(10);  /* replaced by test1_22_call2 */
    if (result != 10 + MAGIC22_2) {
	 logerror("**Failed test #22 (replace function) (a.out -> a.out)\n");
	 retval = -1; /* Test failed */
    }
    result = test1_22_call3(20);  /* replaced by call22_4 */
    if (result != 20 + MAGIC22_4) {
	 logerror("**Failed test #22 (replace function) (a.out -> shlib)\n");
	 retval = -1; /* Test failed */
    }
    if (call22_5 != NULL) {
      result = call22_5(30);  /* replaced by call22_5 (in libtestB) */
      if (result != 30 + MAGIC22_5B) {
	logerror("**Failed test #22 (replace function) (shlib -> shlib)\n");
	retval = -1; /* Test failed */
      }
    }
    if (call22_6 != NULL) {
      result = call22_6(40);  /* replaced by test1_22_call7 */
      if (result != 40 + MAGIC22_7) {
	logerror("**Failed test #22 (replace function) (shlib -> a.out)\n");
	retval = -1; /* Test failed */
      }
    }
    if (0 == retval) {
      logerror("Passed test #22 (replace function)\n");
      test_passes(testname);
    }
#else
    logerror("Skipped test #22 (replace function)\n");
    logerror("\t- not implemented on this platform\n");
    test_passes(testname);
#endif
    return retval;
}