• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dlsym函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中dlsym函数的典型用法代码示例。如果您正苦于以下问题:C++ dlsym函数的具体用法?C++ dlsym怎么用?C++ dlsym使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dlsym函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: FUNC_NAME

extern "C" FUNC_RET_TYPE FUNC_NAME(ARGS_WITH_NAME){
  typedef FUNC_RET_TYPE (*orig_func_type)(ARGS_WITHOUT_NAME);

  static orig_func_type orig_func;

  void * handle;
  FUNC_RET_TYPE ret;
  void *eip = 0;

  if (!orig_func) {
    if(!(handle=dlopen("LIB_PATH", RTLD_LAZY))) {
      perror("dlopen");
      puts("here dlopen");
      abort();
    }

    orig_func = (orig_func_type) dlsym(handle, "FUNC_NAME");

    if(dlerror()) {
      perror("dlsym");
      puts("here dlsym");
      abort();
    }

    dlclose(handle);
  }

#ifdef __USE_TERN_RUNTIME
  if (Space::isApp()) {
    if (options::DMT) {
      //fprintf(stderr, "Parrot hook: pid %d self %u calls %s\n", getpid(), (unsigned)pthread_self(), "FUNC_NAME");
#ifdef __NEED_INPUT_INSID
      if (options::dync_geteip) {
        Space::enterSys();
        eip = get_eip();
        Space::exitSys();
      }
      record_rdtsc_op("FUNC_NAME", "START", 0, eip);
      ret = tern_FUNC_NAME((unsigned)(uint64_t) eip, ARGS_ONLY_NAME);
#else
      ret = tern_FUNC_NAME(ARGS_ONLY_NAME);
#endif
      record_rdtsc_op("FUNC_NAME", "END", 0, eip);
      return ret;
    } else {// For performance debugging, by doing this, we are still able to get the sync wait time for non-det mode.
      if (options::dync_geteip) {
        Space::enterSys();
        eip = get_eip();
        Space::exitSys();
      }
      record_rdtsc_op("FUNC_NAME", "START", 0, eip);
      Space::enterSys();
      ret = orig_func(ARGS_ONLY_NAME);
      Space::exitSys();
      record_rdtsc_op("FUNC_NAME", "END", 0, eip);
      return ret;
    }
  } 
#endif

  ret = orig_func(ARGS_ONLY_NAME);

  return ret;
}
开发者ID:hodiapa,项目名称:crane,代码行数:64,代码来源:func_template.cpp


示例2: Sys_GetGameAPI

/*
 * Loads the game dll
 */
void *
Sys_GetGameAPI(void *parms)
{
	void *(*GetGameAPI)(void *);

	FILE *fp;
	char name[MAX_OSPATH];
	char *path;
	char *str_p;
    #ifdef __APPLE__
        const char *gamename = "game.dylib";
    #else
        const char *gamename = "game.so";
    #endif

	setreuid(getuid(), getuid());
	setegid(getgid());

	if (game_library)
	{
		Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame");
	}

	Com_Printf("LoadLibrary(\"%s\")\n", gamename);

	/* now run through the search paths */
	path = NULL;

	while (1)
	{
		path = FS_NextPath(path);

		if (!path)
		{
			return NULL;     /* couldn't find one anywhere */
		}

		snprintf(name, MAX_OSPATH, "%s/%s", path, gamename);

		/* skip it if it just doesn't exist */
		fp = fopen(name, "rb");

		if (fp == NULL)
		{
			continue;
		}

		fclose(fp);

		game_library = dlopen(name, RTLD_NOW);

		if (game_library)
		{
			Com_MDPrintf("LoadLibrary (%s)\n", name);
			break;
		}
		else
		{
			Com_Printf("LoadLibrary (%s):", name);

			path = (char *)dlerror();
			str_p = strchr(path, ':');   /* skip the path (already shown) */

			if (str_p == NULL)
			{
				str_p = path;
			}
			else
			{
				str_p++;
			}

			Com_Printf("%s\n", str_p);

			return NULL;
		}
	}

	GetGameAPI = (void *)dlsym(game_library, "GetGameAPI");

	if (!GetGameAPI)
	{
		Sys_UnloadGame();
		return NULL;
	}

	return GetGameAPI(parms);
}
开发者ID:DanielGibson,项目名称:yquake2,代码行数:91,代码来源:system.c


示例3: initExtensions

// Initialize X11 display and look for supported X11 extensions
//
static GLFWbool initExtensions(void)
{
    _glfw.x11.vidmode.handle = dlopen("libXxf86vm.so.1", RTLD_LAZY | RTLD_GLOBAL);
    if (_glfw.x11.vidmode.handle)
    {
        _glfw.x11.vidmode.QueryExtension = (PFN_XF86VidModeQueryExtension)
            dlsym(_glfw.x11.vidmode.handle, "XF86VidModeQueryExtension");
        _glfw.x11.vidmode.GetGammaRamp = (PFN_XF86VidModeGetGammaRamp)
            dlsym(_glfw.x11.vidmode.handle, "XF86VidModeGetGammaRamp");
        _glfw.x11.vidmode.SetGammaRamp = (PFN_XF86VidModeSetGammaRamp)
            dlsym(_glfw.x11.vidmode.handle, "XF86VidModeSetGammaRamp");
        _glfw.x11.vidmode.GetGammaRampSize = (PFN_XF86VidModeGetGammaRampSize)
            dlsym(_glfw.x11.vidmode.handle, "XF86VidModeGetGammaRampSize");

        _glfw.x11.vidmode.available =
            XF86VidModeQueryExtension(_glfw.x11.display,
                                      &_glfw.x11.vidmode.eventBase,
                                      &_glfw.x11.vidmode.errorBase);
    }

    _glfw.x11.xi.handle = dlopen("libXi.so", RTLD_LAZY | RTLD_GLOBAL);
    if (_glfw.x11.xi.handle)
    {
        _glfw.x11.xi.QueryVersion = (PFN_XIQueryVersion)
            dlsym(_glfw.x11.xi.handle, "XIQueryVersion");
        _glfw.x11.xi.SelectEvents = (PFN_XISelectEvents)
            dlsym(_glfw.x11.xi.handle, "XISelectEvents");

        if (XQueryExtension(_glfw.x11.display,
                            "XInputExtension",
                            &_glfw.x11.xi.majorOpcode,
                            &_glfw.x11.xi.eventBase,
                            &_glfw.x11.xi.errorBase))
        {
            _glfw.x11.xi.major = 2;
            _glfw.x11.xi.minor = 0;

            if (XIQueryVersion(_glfw.x11.display,
                               &_glfw.x11.xi.major,
                               &_glfw.x11.xi.minor) == Success)
            {
                _glfw.x11.xi.available = GLFW_TRUE;
            }
        }
    }

    // Check for RandR extension
    if (XRRQueryExtension(_glfw.x11.display,
                          &_glfw.x11.randr.eventBase,
                          &_glfw.x11.randr.errorBase))
    {
        if (XRRQueryVersion(_glfw.x11.display,
                            &_glfw.x11.randr.major,
                            &_glfw.x11.randr.minor))
        {
            // The GLFW RandR path requires at least version 1.3
            if (_glfw.x11.randr.major > 1 || _glfw.x11.randr.minor >= 3)
                _glfw.x11.randr.available = GLFW_TRUE;
        }
        else
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: Failed to query RandR version");
        }
    }

    if (_glfw.x11.randr.available)
    {
        XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display,
                                                              _glfw.x11.root);

        if (!sr->ncrtc || !XRRGetCrtcGammaSize(_glfw.x11.display, sr->crtcs[0]))
        {
            // This is either a headless system or an older Nvidia binary driver
            // with broken gamma support
            // Flag it as useless and fall back to Xf86VidMode gamma, if
            // available
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: Detected broken RandR gamma ramp support");
            _glfw.x11.randr.gammaBroken = GLFW_TRUE;
        }

        if (!sr->ncrtc || !sr->noutput || !sr->nmode)
        {
            // This is either a headless system or broken Cygwin/X RandR
            // Flag it as useless and fall back to Xlib display functions
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: Detected broken RandR monitor support");
            _glfw.x11.randr.monitorBroken = GLFW_TRUE;
        }

        XRRFreeScreenResources(sr);

        XRRSelectInput(_glfw.x11.display, _glfw.x11.root,
                       RROutputChangeNotifyMask);
    }

    if (XineramaQueryExtension(_glfw.x11.display,
//.........这里部分代码省略.........
开发者ID:dumganhar,项目名称:glfw,代码行数:101,代码来源:x11_init.c


示例4: f_init_func

int f_init_func(char *p_option,char *p_mod)
{
    const char *p_error;
    char *p_modpath=MOD_PATH;
    char s_module[MAX_BUF];

    if(!strcasecmp(p_option,"open-external"))
    {
        if (p_mod!=NULL)
        {
            memset(s_module,'\0',sizeof(s_module));
            tc_snprintf(s_module, sizeof(s_module), "%s/export_%s.so", p_modpath,p_mod);
            f_ext_handle=dlopen(s_module, RTLD_GLOBAL|RTLD_LAZY);
            if (!f_ext_handle)
            {
                fputs (dlerror(), stderr);
                dlclose(f_handle);
                return(1);
            }
            tc_export = dlsym(f_ext_handle, "tc_export");
            if ((p_error = dlerror()) != NULL)
            {
                fputs(p_error, stderr);
                return(1);
            }
        }
    }
    else if(!strcasecmp(p_option,"close-external"))
    {
        if (f_ext_handle!=NULL)
            dlclose(f_ext_handle);
        f_ext_handle=NULL;
        tc_export=NULL;
    }
    else if(!strcasecmp(p_option,"status-external"))
    {
        if(f_ext_handle!=NULL)
            return(1);
    }
    else if(!strcasecmp(p_option,"open"))
    {
        if (p_mod!=NULL)
        {
            tc_accel = ac_cpuinfo();
            memset(s_module,'\0',sizeof(s_module));
            tc_snprintf(s_module, sizeof(s_module), "%s/export_%s.so", p_modpath,p_mod);
            f_ext_handle=dlopen(s_module, RTLD_GLOBAL|RTLD_LAZY);
            if (!f_ext_handle)
            {
                fputs (dlerror(), stderr);
                dlclose(f_handle);
                return(1);
            }
            tc_export = dlsym(f_ext_handle, "tc_export");
            if ((p_error = dlerror()) != NULL)
            {
                fputs(p_error, stderr);
                return(1);
            }
        }
        if ((f_handle=f_init_pvm_func("open",NULL))==NULL)
            return(1);
    }
    else if(!strcasecmp(p_option,"close"))
    {
        if (f_ext_handle!=NULL)
            dlclose(f_ext_handle);
        (void *)f_init_pvm_func("close",f_handle);
        f_ext_handle=NULL;
        f_handle=NULL;
    }
    else
    {
        fprintf(stderr,"(%s) invalid command \"%s\"\n",__FILE__,p_option);
        return(1);
    }
    return(0);
}
开发者ID:BackupTheBerlios,项目名称:tcforge-svn,代码行数:78,代码来源:tcpvmexportd.c


示例5: assert

struct module *module_load(const char *module_name, struct parameters *args)
{
	void *module_handle = NULL;
	struct module *module = NULL;
	char *full_module_name;
	size_t module_name_len;

	assert(module_name);

	module_name_len = strlen(HAKA_MODULE_PREFIX) + strlen(module_name) + strlen(HAKA_MODULE_SUFFIX) + 1;
	full_module_name = malloc(module_name_len);
	if (!full_module_name) {
		return NULL;
	}

	snprintf(full_module_name, module_name_len, "%s%s%s", HAKA_MODULE_PREFIX, module_name, HAKA_MODULE_SUFFIX);
	assert(strlen(full_module_name)+1 == module_name_len);

	{
		char *current_path = modules_cpath, *iter;
		char *full_path;

		while ((iter = strchr(current_path, '*')) != NULL) {
			const int len = iter - current_path;
			const size_t full_path_len = len + strlen(full_module_name) + 1;

			full_path = malloc(full_path_len);
			if (!full_path) {
				return NULL;
			}

			snprintf(full_path, full_path_len, "%.*s%s", len, current_path, full_module_name);
			assert(strlen(full_path)+1 == full_path_len);

			module_handle = dlopen(full_path, RTLD_NOW);

			current_path = iter+1;
			if (*current_path != 0) ++current_path;

			free(full_path);
			full_path = NULL;

			if (module_handle) {
				break;
			}
		}
	}

	if (!module_handle) {
		free(full_module_name);
		error(L"%s", strdup(dlerror()));
		return NULL;
	}

	module = (struct module*)dlsym(module_handle, "HAKA_MODULE");
	if (!module) {
		error(L"%s", strdup(dlerror()));
		dlclose(module);
		free(full_module_name);
		return NULL;
	}

	module->handle = module_handle;

	if (module->api_version != HAKA_API_VERSION) {
		messagef(HAKA_LOG_INFO, L"core", L"%s: invalid API version", full_module_name);
		dlclose(module->handle);
		free(full_module_name);
		return NULL;
	}

	if (atomic_get(&module->ref) == 0) {
		/* Initialize the module */
		if (module->name && module->author) {
			messagef(HAKA_LOG_INFO, L"core", L"load module '%s', %ls, %ls",
			         full_module_name, module->name, module->author);
		}
		else if (module->name || module->author) {
			messagef(HAKA_LOG_INFO, L"core", L"load module '%s', %ls%ls",
			         full_module_name, module->name ? module->name : L"",
			         module->author ? module->author : L"");
		}
		else {
			messagef(HAKA_LOG_INFO, L"core", L"load module '%s'", full_module_name);
		}

		if (module->init(args) || check_error()) {
			if (check_error()) {
				error(L"unable to initialize module: %ls", clear_error());
			} else {
				error(L"unable to initialize module");
			}

			dlclose(module->handle);
			free(full_module_name);
			return NULL;
		}
	}

	free(full_module_name);
//.........这里部分代码省略.........
开发者ID:Oneiroi,项目名称:haka,代码行数:101,代码来源:module.c


示例6: display_fill_symbols

static int display_fill_symbols(display_table_t *device)
{
        void *handle = device->handle;

        device->func_probe = (display_type_t *(*) (void))
                dlsym(handle, device->func_probe_str);
        device->func_init = (void *(*) (char *, unsigned int))
                dlsym(handle, device->func_init_str);
        device->func_run = (void (*) (void *))
                dlsym(handle, device->func_run_str);
        device->func_done = (void (*) (void *))
                dlsym(handle, device->func_done_str);
        device->func_finish = (void (*) (void *))
                dlsym(handle, device->func_finish_str);
        device->func_getf = (struct video_frame *(*) (void *))
                dlsym(handle, device->func_getf_str);
        device->func_putf = (int (*) (void *, char *))
                dlsym(handle, device->func_putf_str);
        device->func_reconfigure = (int (*)(void *, struct video_desc))
                dlsym(handle, device->func_reconfigure_str);
        device->func_get_property = (int (*)(void *, int, void *, size_t *))
                dlsym(handle, device->func_get_property_str);
        
        device->func_get_audio_frame = (struct audio_frame *(*) (void *))
                dlsym(handle, device->func_get_audio_frame_str);
        device->func_put_audio_frame = (void (*) (void *, struct audio_frame *))
                dlsym(handle, device->func_put_audio_frame_str);
        device->func_reconfigure_audio = (int (*) (void *, int, int,
                        int))
                dlsym(handle, device->func_reconfigure_audio_str);

        if(!device->func_probe || !device->func_init || !device->func_run ||
                        !device->func_done || !device->func_finish ||
                        !device->func_getf || !device->func_getf ||
                        !device->func_putf || !device->func_reconfigure ||
                        !device->func_get_property || !device->func_get_audio_frame ||
                        !device->func_put_audio_frame || !device->func_reconfigure_audio) {
                fprintf(stderr, "Library %s opening error: %s \n", device->library_name, dlerror());
                return FALSE;
        }

        return TRUE;
}
开发者ID:248668342,项目名称:ffmpeg-windows,代码行数:43,代码来源:video_display.c


示例7: group_plugin_load

/*
 * Load the specified plugin and run its init function.
 * Returns -1 if unable to open the plugin, else it returns
 * the value from the plugin's init function.
 */
int
group_plugin_load(char *plugin_info)
{
    struct stat sb;
    char *args, path[PATH_MAX];
    char **argv = NULL;
    int len, rc = -1;

    /*
     * Fill in .so path and split out args (if any).
     */
    args = strpbrk(plugin_info, " \t");
    if ((args = strpbrk(plugin_info, " \t")) != NULL) {
	len = snprintf(path, sizeof(path), "%s%.*s",
	    (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "",
	    (int)(args - plugin_info), plugin_info);
	args++;
    } else {
	len = snprintf(path, sizeof(path), "%s%s",
	    (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info);
    }
    if (len <= 0 || len >= sizeof(path)) {
	warningx("%s%s: %s",
	    (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info,
	    strerror(ENAMETOOLONG));
	goto done;
    }

    /* Sanity check plugin path. */
    if (stat(path, &sb) != 0) {
	warning("%s", path);
	goto done;
    }
    if (sb.st_uid != ROOT_UID) {
	warningx("%s must be owned by uid %d", path, ROOT_UID);
	goto done;
    }
    if ((sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
	warningx("%s must be only be writable by owner", path);
	goto done;
    }

    /* Open plugin and map in symbol. */
    group_handle = dlopen(path, RTLD_LAZY|RTLD_LOCAL);
    if (!group_handle) {
	warningx("unable to dlopen %s: %s", path, dlerror());
	goto done;
    }
    group_plugin = dlsym(group_handle, "group_plugin");
    if (group_plugin == NULL) {
	warningx("unable to find symbol \"group_plugin\" in %s", path);
	goto done;
    }

    if (GROUP_API_VERSION_GET_MAJOR(group_plugin->version) != GROUP_API_VERSION_MAJOR) {
	warningx("%s: incompatible group plugin major version %d, expected %d",
	    path, GROUP_API_VERSION_GET_MAJOR(group_plugin->version),
	    GROUP_API_VERSION_MAJOR);
	goto done;
    }

    /*
     * Split args into a vector if specified.
     */
    if (args != NULL) {
	int ac = 0, wasblank = TRUE;
	char *cp;

        for (cp = args; *cp != '\0'; cp++) {
            if (isblank((unsigned char)*cp)) {
                wasblank = TRUE;
            } else if (wasblank) {
                wasblank = FALSE;
                ac++;
            }
        }
	if (ac != 0) 	{
	    argv = emalloc2(ac, sizeof(char *));
	    ac = 0;
	    for ((cp = strtok(args, " \t")); cp; (cp = strtok(NULL, " \t")))
		argv[ac++] = cp;
	}
    }

    rc = (group_plugin->init)(GROUP_API_VERSION, sudo_printf, argv);

done:
    efree(argv);

    if (rc != TRUE) {
	if (group_handle != NULL) {
	    dlclose(group_handle);
	    group_handle = NULL;
	    group_plugin = NULL;
	}
//.........这里部分代码省略.........
开发者ID:alagenchev,项目名称:school_code,代码行数:101,代码来源:group_plugin.c


示例8: sys_do_load_lib


//.........这里部分代码省略.........
        /* try looking in the path for (objectname).(sys_dllextent) ... */
    if ((fd = sys_trytoopenone(path, objectname, sys_dllextent,
        dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0)
            goto gotone;
        /* same, with the more generic sys_dllextent2 */
    if ((fd = sys_trytoopenone(path, objectname, sys_dllextent2,
        dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0)
            goto gotone;
        /* next try (objectname)/(classname).(sys_dllextent) ... */
    strncpy(filename, objectname, MAXPDSTRING);
    filename[MAXPDSTRING-2] = 0;
    strcat(filename, "/");
    strncat(filename, classname, MAXPDSTRING-strlen(filename));
    filename[MAXPDSTRING-1] = 0;
    if ((fd = sys_trytoopenone(path, filename, sys_dllextent,
        dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0)
            goto gotone;
    if ((fd = sys_trytoopenone(path, filename, sys_dllextent2,
        dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0)
            goto gotone;
#ifdef ANDROID
    /* Android libs have a 'lib' prefix, '.so' suffix and don't allow ~ */
    char libname[MAXPDSTRING] = "lib";
    strncat(libname, objectname, MAXPDSTRING - 4);
    int len = strlen(libname);
    if (libname[len-1] == '~' && len < MAXPDSTRING - 6) {
        strcpy(libname+len-1, "_tilde");
    }
    if ((fd = sys_trytoopenone(path, libname, ".so",
        dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0)
            goto gotone;
#endif
    return (0);
gotone:
    close(fd);
    class_set_extern_dir(gensym(dirbuf));

        /* rebuild the absolute pathname */
    strncpy(filename, dirbuf, MAXPDSTRING);
    filename[MAXPDSTRING-2] = 0;
    strcat(filename, "/");
    strncat(filename, nameptr, MAXPDSTRING-strlen(filename));
    filename[MAXPDSTRING-1] = 0;

#ifdef _WIN32
    {
        char dirname[MAXPDSTRING], *s, *basename;
        sys_bashfilename(filename, filename);
        /* set the dirname as DllDirectory, meaning in the path for
           loading other DLLs so that dependent libraries can be included
           in the same folder as the external. SetDllDirectory() needs a
           minimum supported version of Windows XP SP1 for
           SetDllDirectory, so WINVER must be 0x0502 */
        strncpy(dirname, filename, MAXPDSTRING);
        s = strrchr(dirname, '\\');
        basename = s;
        if (s && *s)
          *s = '\0';
        if (!SetDllDirectory(dirname))
           error("Could not set '%s' as DllDirectory(), '%s' might not load.",
                 dirname, basename);
        /* now load the DLL for the external */
        ntdll = LoadLibrary(filename);
        if (!ntdll)
        {
            verbose(1, "%s: couldn't load", filename);
            class_set_extern_dir(&s_);
            return (0);
        }
        makeout = (t_xxx)GetProcAddress(ntdll, symname);
        if (!makeout)
             makeout = (t_xxx)GetProcAddress(ntdll, "setup");
        SetDllDirectory(NULL); /* reset DLL dir to nothing */
    }
#elif defined(HAVE_LIBDL) || defined(__FreeBSD__)
    dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
    if (!dlobj)
    {
        verbose(1, "%s: %s", filename, dlerror());
        class_set_extern_dir(&s_);
        return (0);
    }
    makeout = (t_xxx)dlsym(dlobj,  symname);
    if(!makeout)
        makeout = (t_xxx)dlsym(dlobj,  "setup");
#else
#warning "No dynamic loading mechanism specified, \
    libdl or WIN32 required for loading externals!"
#endif

    if (!makeout)
    {
        verbose(1, "load_object: Symbol \"%s\" not found", symname);
        class_set_extern_dir(&s_);
        return 0;
    }
    (*makeout)();
    class_set_extern_dir(&s_);
    return (1);
}
开发者ID:myQuil,项目名称:amPd,代码行数:101,代码来源:s_loader.c


示例9: import_heap_image

Task*   import_heap_image   (const char* fname, Heapcleaner_Args* params) {
    //  =================
    //
    Task*		task;
    Heapfile_Header	image_header;
    Heap_Header	heap_header;
    Val		*externs;
    Pthread_Image	image;
    Inbuf		inbuf;

    if (fname != NULL) {
	//
        // Resolve the name of the image.
        //  If the file exists use it, otherwise try the
        // pathname with the machine ID as an extension.

	if ((inbuf.file = fopen(fname, "rb"))) {
	    //
	    if (verbosity > 0)   say("loading %s ", fname);

	} else {
	    //
	    if ((inbuf.file = fopen(fname, "rb"))) {
		//
	        if (verbosity > 0)   say("loading %s ", fname);

	    } else {

		die ("unable to open heap image \"%s\"\n", fname);
	    }
	}

	inbuf.needs_to_be_byteswapped = FALSE;
	inbuf.buf	    = NULL;
	inbuf.nbytes    = 0;

    } else {
	//
	// fname == NULL, so try to find
	// an in-core heap image:

  	#if defined(DLOPEN) && !defined(OPSYS_WIN32)
	    //
	    void *lib = dlopen (NULL, RTLD_LAZY);
	    void *vimg, *vimglenptr;

	    if ((vimg       = dlsym(lib,HEAP_IMAGE_SYMBOL    )) == NULL)      die("no in-core heap image found\n");
	    if ((vimglenptr = dlsym(lib,HEAP_IMAGE_LEN_SYMBOL)) == NULL)      die("unable to find length of in-core heap image\n");

	    inbuf.file      = NULL;
	    inbuf.needs_to_be_byteswapped = FALSE;

	    inbuf.base      = vimg;
	    inbuf.buf       = inbuf.base;
	    inbuf.nbytes    = *(long*)vimglenptr;
        #else
	    die("in-core heap images not implemented\n");
        #endif
    }

    READ(&inbuf, image_header);

    if (image_header.byte_order != ORDER)						die ("incorrect byte order in heap image\n");
    if (image_header.magic != IMAGE_MAGIC)						die ("bad magic number (%#x) in heap image\n", image_header.magic);
    if ((image_header.kind != EXPORT_HEAP_IMAGE) && (image_header.kind != EXPORT_FN_IMAGE))	die ("bad image kind (%d) in heap image\n", image_header.kind);

    READ(&inbuf, heap_header);

    // Check for command-line overrides of heap parameters:
    //
    if (params->agegroup0_buffer_bytesize == 0) {
        params->agegroup0_buffer_bytesize = heap_header.agegroup0_buffer_bytesize;
    }
    if (params->active_agegroups < heap_header.active_agegroups) {
        params->active_agegroups = heap_header.active_agegroups;
    }
    if (params->oldest_agegroup_keeping_idle_fromspace_buffers < 0) {
        params->oldest_agegroup_keeping_idle_fromspace_buffers = heap_header.oldest_agegroup_keeping_idle_fromspace_buffers;
    } 

    task = make_task( FALSE, params );						// make_task		def in   src/c/main/runtime-state.c

    // Get the run-time pointers into the heap:
    //
    *PTR_CAST( Val*, PERVASIVE_PACKAGE_PICKLE_LIST_REFCELL__GLOBAL )
        =
        heap_header.pervasive_package_pickle_list;

    // This carefully constructed fake looks like a normal
    // compiled package from the Mythryl side but actually
    // links to compile C code -- see the hack in
    //	
    //     src/c/main/load-compiledfiles.c
    //
    runtime_package__global =  heap_header.runtime_pseudopackage;

    #ifdef ASM_MATH
	mathvec__global = heap_header.math_package;
    #endif

//.........这里部分代码省略.........
开发者ID:spiralofhope,项目名称:mythryl,代码行数:101,代码来源:import-heap.c


示例10: xlator_dynload

int
xlator_dynload (xlator_t *xl)
{
        int                ret = -1;
        char              *name = NULL;
        void              *handle = NULL;
        volume_opt_list_t *vol_opt = NULL;


        GF_VALIDATE_OR_GOTO ("xlator", xl, out);

        INIT_LIST_HEAD (&xl->volume_options);

        ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xl->type);
        if (-1 == ret) {
                gf_log ("xlator", GF_LOG_ERROR, "asprintf failed");
                goto out;
        }

        ret = -1;

        gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name);

        handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL);
        if (!handle) {
                gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ());
                goto out;
        }
        xl->dlhandle = handle;

        if (!(xl->fops = dlsym (handle, "fops"))) {
                gf_log ("xlator", GF_LOG_WARNING, "dlsym(fops) on %s",
                        dlerror ());
                goto out;
        }

        if (!(xl->cbks = dlsym (handle, "cbks"))) {
                gf_log ("xlator", GF_LOG_WARNING, "dlsym(cbks) on %s",
                        dlerror ());
                goto out;
        }

        if (!(*VOID(&xl->init) = dlsym (handle, "init"))) {
                gf_log ("xlator", GF_LOG_WARNING, "dlsym(init) on %s",
                        dlerror ());
                goto out;
        }

        if (!(*VOID(&(xl->fini)) = dlsym (handle, "fini"))) {
                gf_log ("xlator", GF_LOG_WARNING, "dlsym(fini) on %s",
                        dlerror ());
                goto out;
        }

        if (!(*VOID(&(xl->notify)) = dlsym (handle, "notify"))) {
                gf_log ("xlator", GF_LOG_TRACE,
                        "dlsym(notify) on %s -- neglecting", dlerror ());
        }

        if (!(xl->dumpops = dlsym (handle, "dumpops"))) {
                gf_log ("xlator", GF_LOG_TRACE,
                        "dlsym(dumpops) on %s -- neglecting", dlerror ());
        }

        if (!(*VOID(&(xl->mem_acct_init)) = dlsym (handle, "mem_acct_init"))) {
                gf_log (xl->name, GF_LOG_TRACE,
                        "dlsym(mem_acct_init) on %s -- neglecting",
                        dlerror ());
        }

        if (!(*VOID(&(xl->reconfigure)) = dlsym (handle, "reconfigure"))) {
                gf_log ("xlator", GF_LOG_TRACE,
                        "dlsym(reconfigure) on %s -- neglecting",
                        dlerror());
        }

        vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
                         gf_common_mt_volume_opt_list_t);

        if (!vol_opt) {
                goto out;
        }

        if (!(vol_opt->given_opt = dlsym (handle, "options"))) {
                dlerror ();
                gf_log (xl->name, GF_LOG_TRACE,
                        "Strict option validation not enforced -- neglecting");
        }
        INIT_LIST_HEAD (&vol_opt->list);
        list_add_tail (&vol_opt->list, &xl->volume_options);

        fill_defaults (xl);

        ret = 0;

out:
        GF_FREE (name);
        return ret;
}
开发者ID:krisis,项目名称:glusterfs,代码行数:99,代码来源:xlator.c


示例11: xlator_volopt_dynload

int
xlator_volopt_dynload (char *xlator_type, void **dl_handle,
                       volume_opt_list_t *opt_list)
{
        int                     ret = -1;
        char                    *name = NULL;
        void                    *handle = NULL;
        volume_opt_list_t       *vol_opt = NULL;

        GF_VALIDATE_OR_GOTO ("xlator", xlator_type, out);

        GF_ASSERT (dl_handle);

        if (*dl_handle)
                if (dlclose (*dl_handle))
                        gf_log ("xlator", GF_LOG_WARNING, "Unable to close "
                                  "previously opened handle( may be stale)."
                                  "Ignoring the invalid handle");

        ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xlator_type);
        if (-1 == ret) {
                gf_log ("xlator", GF_LOG_ERROR, "asprintf failed");
                goto out;
        }

        ret = -1;

        gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name);

        handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL);
        if (!handle) {
                gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ());
                goto out;
        }
        *dl_handle = handle;


        vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
                         gf_common_mt_volume_opt_list_t);

        if (!vol_opt) {
                goto out;
        }

        if (!(vol_opt->given_opt = dlsym (handle, "options"))) {
                dlerror ();
                gf_log ("xlator", GF_LOG_DEBUG,
                         "Strict option validation not enforced -- neglecting");
        }
        opt_list->given_opt = vol_opt->given_opt;

        INIT_LIST_HEAD (&vol_opt->list);
        list_add_tail (&vol_opt->list, &opt_list->list);

        ret = 0;
 out:
        GF_FREE (name);

        gf_log ("xlator", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;

}
开发者ID:krisis,项目名称:glusterfs,代码行数:62,代码来源:xlator.c


示例12: ompt_try_start_tool

static ompt_start_tool_result_t *
ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
  ompt_start_tool_result_t *ret = NULL;
  ompt_start_tool_t start_tool = NULL;
#if KMP_OS_WINDOWS
  // Cannot use colon to describe a list of absolute paths on Windows
  const char *sep = ";";
#else
  const char *sep = ":";
#endif

#if KMP_OS_DARWIN
  // Try in the current address space
  ret = ompt_tool_darwin(omp_version, runtime_version);
#elif OMPT_HAVE_WEAK_ATTRIBUTE
  ret = ompt_start_tool(omp_version, runtime_version);
#elif OMPT_HAVE_PSAPI
  ret = ompt_tool_windows(omp_version, runtime_version);
#else
#error Activation of OMPT is not supported on this platform.
#endif
  if (ret)
    return ret;

  // Try tool-libraries-var ICV
  const char *tool_libs = getenv("OMP_TOOL_LIBRARIES");
  if (tool_libs) {
    char *libs = __kmp_str_format("%s", tool_libs);
    char *buf;
    char *fname = __kmp_str_token(libs, sep, &buf);
    while (fname) {
#if KMP_OS_UNIX
      void *h = dlopen(fname, RTLD_LAZY);
      if (h) {
        start_tool = (ompt_start_tool_t)dlsym(h, "ompt_start_tool");
#elif KMP_OS_WINDOWS
      HMODULE h = LoadLibrary(fname);
      if (h) {
        start_tool = (ompt_start_tool_t)GetProcAddress(h, "ompt_start_tool");
#else
#error Activation of OMPT is not supported on this platform.
#endif
        if (start_tool && (ret = (*start_tool)(omp_version, runtime_version)))
          break;
      }
      fname = __kmp_str_token(NULL, sep, &buf);
    }
    __kmp_str_free(&libs);
  }
  return ret;
}

void ompt_pre_init() {
  //--------------------------------------------------
  // Execute the pre-initialization logic only once.
  //--------------------------------------------------
  static int ompt_pre_initialized = 0;

  if (ompt_pre_initialized)
    return;

  ompt_pre_initialized = 1;

  //--------------------------------------------------
  // Use a tool iff a tool is enabled and available.
  //--------------------------------------------------
  const char *ompt_env_var = getenv("OMP_TOOL");
  tool_setting_e tool_setting = omp_tool_error;

  if (!ompt_env_var || !strcmp(ompt_env_var, ""))
    tool_setting = omp_tool_unset;
  else if (OMPT_STR_MATCH(ompt_env_var, "disabled"))
    tool_setting = omp_tool_disabled;
  else if (OMPT_STR_MATCH(ompt_env_var, "enabled"))
    tool_setting = omp_tool_enabled;

#if OMPT_DEBUG
  printf("ompt_pre_init(): tool_setting = %d\n", tool_setting);
#endif
  switch (tool_setting) {
  case omp_tool_disabled:
    break;

  case omp_tool_unset:
  case omp_tool_enabled:

    //--------------------------------------------------
    // Load tool iff specified in environment variable
    //--------------------------------------------------
    ompt_start_tool_result =
        ompt_try_start_tool(__kmp_openmp_version, ompt_get_runtime_version());

    memset(&ompt_enabled, 0, sizeof(ompt_enabled));
    break;

  case omp_tool_error:
    fprintf(stderr, "Warning: OMP_TOOL has invalid value \"%s\".\n"
                    "  legal values are (NULL,\"\",\"disabled\","
                    "\"enabled\").\n",
            ompt_env_var);
//.........这里部分代码省略.........
开发者ID:OpenMPToolsInterface,项目名称:LLVM-openmp,代码行数:101,代码来源:ompt-general.cpp


示例13: main

int
main(int argc, char *argv[])
{
	int               opt, c_flag = 0;
	CK_SLOT_ID	  slot_id = 0;
	char		 *so_pin = NULL, *user_pin = NULL, *data_store = NULL;

	CK_FUNCTION_LIST *funcs;
	CK_ULONG	  slot_count;
	CK_SESSION_HANDLE sess;
	CK_RV		  rv;
	struct object    *objs_to_migrate = NULL, *tmp, *to_free;
	int		  exit_code = 0, rc;
	
	lib_csulcca = dlopen("libcsulcca.so", (RTLD_GLOBAL | RTLD_NOW));
	if (lib_csulcca == NULL) {
		print_error("Couldn't get a handle to the CCA library.");
		return NULL;
	}

	CSNDKTC = dlsym(lib_csulcca, "CSNDKTC_32");
	CSNBKTC = dlsym(lib_csulcca, "CSNBKTC_32");	

	while ((opt = getopt(argc, argv, "c:d:s:u:nvh")) != -1) {
		switch (opt) {
		case 'c':
			c_flag++;
			slot_id = atoi(optarg);
			break;

		case 'd':
			data_store = strdup(optarg);
			break;

		case 's':
			so_pin = strdup(optarg);
			break;

		case 'u':
			user_pin = strdup(optarg);
			break;

		case 'n':
			n_flag++;
			break;

		case 'v':
			v_flag++;
			break;

		case 'h':
			usage(argv[0]);
			return 0;

		default:
			usage(argv[0]);
			return 1;
		}
	}

	if (!c_flag || !data_store || !so_pin || !user_pin) {
		usage(argv[0]);
		return 1;
	}

	if (n_flag)
		printf("Dry-run of migration in progress\n");

	funcs = p11_init();
	if (!funcs) {
		return 2;
	}

	rv = funcs->C_GetSlotList(TRUE, NULL_PTR, &slot_count);
	if (rv != CKR_OK) {
		p11_error("C_GetSlotList", rv);
		exit_code = 3;
		goto finalize;
	}

	if (slot_id >= slot_count) {
		print_error("%lu is not a valid slot ID.", slot_id);
		exit_code = 4;
		goto finalize;
	}
	if (v_flag > 1)
		printf("Slot id %lu is valid\n", slot_id);

	/* Open a r/w session */
	rv = funcs->C_OpenSession(slot_id, CKF_RW_SESSION|CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &sess);
	if (rv != CKR_OK) {
		p11_error("C_OpenSession", rv);
		exit_code = 5;
		goto finalize;
	}
	if (v_flag > 1)
		printf("PKCS#11 r/w session opened\n");

	/* Login as the SO just validate the supplied pin */
	rv = funcs->C_Login(sess, CKU_SO, (CK_BYTE *)so_pin, strlen(so_pin));
//.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:OpenCryptoki,代码行数:101,代码来源:cca_migrate.c


示例14: SolidModel


//.........这里部分代码省略.........
    _plugin += std::string("-") + QUOTE(METHOD) + ".plugin";
#endif

    //Size and create full (mechanical+thermal) material property array
    _num_props = _mechanical_constants.size() + _thermal_constants.size();
    std::vector<Real> props_array(_num_props);
    for (unsigned int i=0; i<_mechanical_constants.size(); ++i)
        props_array[i] = _mechanical_constants[i];
    for (unsigned int i=_mechanical_constants.size(); i<_num_props; ++i)
        props_array[i] = _thermal_constants[i];

    //Read mesh dimension and size UMAT arrays
    if (_mesh.dimension()==3)  //3D case
    {
        _NTENS=6;  //Size of the stress or strain component array (NDI+NSHR)
        _NSHR=3;   //Number of engineering shear stress components
        _NDI=3;    //Number of direct stress components (always 3)
    }
    else if (_mesh.dimension()==2) //2D case
    {
        _NTENS=4;
        _NSHR=1;
        _NDI=3;
    }

    _STATEV = new Real[_num_state_vars];
    _DDSDDT = new Real[_NTENS];
    _DRPLDE = new Real[_NTENS];
    _STRAN  = new Real[_NTENS];
    _DFGRD0 = new Real[9];
    _DFGRD1 = new Real[9];
    _STRESS = new Real[_NTENS];
    _DDSDDE = new Real[_NTENS*_NTENS];
    _DSTRAN = new Real[_NTENS];
    _PROPS  = new Real[_num_props];

    for (unsigned int i=0; i<_num_state_vars; ++i)
    {
        _STATEV[i] = 0.0;
    }

    for (int i=0; i<_NTENS; ++i)
    {
        _DDSDDT[i] = 0.0;
        _DRPLDE[i] = 0.0;
        _STRAN[i]  = 0.0;
        _STRESS[i] = 0.0;
        _DSTRAN[i] = 0.0;
    }

    for (unsigned int i=0; i<9; ++i)
    {
        _DFGRD0[i] = 0.0;
        _DFGRD1[i] = 0.0;
    }

    for (int i=0; i<_NTENS*_NTENS; ++i)
    {
        _DDSDDE[i] = 0.0;
    }

    //Assign materials properties from vector form into an array
    for (unsigned int i=0; i<_num_props; ++i)
    {
        _PROPS[i] = props_array[i];
    }

    //Size UMAT state variable (NSTATV) and material constant (NPROPS) arrays
    _NSTATV = _num_state_vars;
    _NPROPS = _num_props;

    // Open the library
    _handle = dlopen(_plugin.c_str(), RTLD_LAZY);

    if (!_handle)
    {
        std::ostringstream error;
        error << "Cannot open library: " << dlerror() << '\n';
        mooseError(error.str());
    }

    // Reset errors
    dlerror();

    // Snag the function pointer from the library
    {
        void * pointer = dlsym(_handle, "umat_");
        _umat = *reinterpret_cast<umat_t*>( &pointer );
    }

    // Catch errors
    const char *dlsym_error = dlerror();
    if (dlsym_error)
    {
        dlclose(_handle);
        std::ostringstream error;
        error << "Cannot load symbol 'umat_': " << dlsym_error << '\n';
        mooseError(error.str());
    }
}
开发者ID:hereiam-at-mit-dot-edu,项目名称:moose,代码行数:101,代码来源:AbaqusUmatMaterial.C


示例15: ibm_xlsmp_1_6_GetOpenMPHookPoints

static int ibm_xlsmp_1_6_GetOpenMPHookPoints (int rank)
{
	int count = 0;

	UNREFERENCED_PARAMETER(rank)

	/* Obtain @ for _xlsmpParallelDoSetup_TPO */
	_xlsmpParallelDoSetup_TPO_real =
		(void(*)(int,void**,long,long,long,long,void**,void**,void**,long,long,void**,long))
		dlsym (RTLD_NEXT, "_xlsmpParallelDoSetup_TPO");
	INC_IF_NOT_NULL(_xlsmpParallelDoSetup_TPO_real,count);

	/* Obtain @ for _xlsmpParRegionSetup_TPO */
	_xlsmpParRegionSetup_TPO_real =
		(void(*)(int,void*,int,void*,void*,void**,long,long))
		dlsym (RTLD_NEXT, "_xlsmpParRegionSetup_TPO");
	INC_IF_NOT_NULL(_xlsmpParRegionSetup_TPO_real,count);

	/* Obtain @ for _xlsmpWSDoSetup_TPO */
	_xlsmpWSDoSetup_TPO_real =
		(void(*)(int,void*,long,long,long,long,void*,void*,void**,long))
		dlsym (RTLD_NEXT, "_xlsmpWSDoSetup_TPO");
	INC_IF_NOT_NULL(_xlsmpWSDoSetup_TPO_real,count);

	/* Obtain @ for _xlsmpWSSectSetup_TPO */
	_xlsmpWSSectSetup_TPO_real =
		(void(*)(int,void*,long,void*,void*,void**,long,long))
		dlsym (RTLD_NEXT, "_xlsmpWSSectSetup_TPO");
	INC_IF_NOT_NULL(_xlsmpWSSectSetup_TPO_real,count);

	/* Obtain @ for _xlsmpSingleSetup_TPO */
	_xlsmpSingleSetup_TPO_real =
		(void(*)(int,void*,int,void*)) dlsym (RTLD_NEXT, "_xlsmpSingleSetup_TPO");
	INC_IF_NOT_NULL(_xlsmpSingleSetup_TPO_real,count);

	/* Obtain @ for _xlsmpBarrier_TPO */
	_xlsmpBarrier_TPO_real =
		(void(*)(int,int*)) dlsym (RTLD_NEXT, "_xlsmpBarrier_TPO");
	INC_IF_NOT_NULL(_xlsmpBarrier_TPO_real,count);

	/* Obtain @ for _xlsmpGetDefaultSLock */
	_xlsmpGetDefaultSLock_real =
		(void(*)(void*)) dlsym (RTLD_NEXT, "_xlsmpGetDefaultSLock");
	INC_IF_NOT_NULL(_xlsmpGetDefaultSLock_real,count);

	/* Obtain @ for _xlsmpRelDefaultSLock */
	_xlsmpRelDefaultSLock_real =
		(void(*)(void*)) dlsym (RTLD_NEXT, "_xlsmpRelDefaultSLock");
	INC_IF_NOT_NULL(_xlsmpRelDefaultSLock_real,count);

	/* Obtain @ for _xlsmpGetSLock */
	_xlsmpGetSLock_real =
		(void(*)(void*)) dlsym (RTLD_NEXT, "_xlsmpGetSLock");
	INC_IF_NOT_NULL(_xlsmpGetSLock_real,count);

	/* Obtain @ for _xlsmpRelSLock */
	_xlsmpRelSLock_real =
		(void(*)(void*)) dlsym (RTLD_NEXT, "_xlsmpRelSLock");
	INC_IF_NOT_NULL(_xlsmpRelSLock_real,count);

	/* Any hook point? */
	return count > 0;
}
开发者ID:polca-project,项目名称:polca-toolbox,代码行数:63,代码来源:ibm-xlsmp-1.6.c


示例16: slv2_ui_instantiate

SLV2UIInstance
slv2_ui_instantiate(SLV2Plugin                     plugin,
                    SLV2UI                         ui,
                    LV2UI_Write_Function           write_function,
                    LV2UI_Controller               controller,
                    const LV2_Feature* const*      features)
{
    struct _SLV2UIInstance* result = NULL;

    bool local_features = (features == NULL);
    i 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dm_block_data函数代码示例发布时间:2022-05-30
下一篇:
C++ dlopen函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap