示例#1
0
const char *luaG_openlibs( lua_State *L, const char *libs ) {
    const char *p;
    unsigned len;

	if (!libs) return NULL;     // no libs, not even 'base'

    // 'lua.c' stops GC during initialization so perhaps its a good idea. :)
    //
    lua_gc(L, LUA_GCSTOP, 0);

    // Anything causes 'base' to be taken in
    //
    STACK_GROW(L,2);
    lua_pushcfunction( L, luaopen_base );
    lua_pushliteral( L, "" );
    lua_call( L, 1, 0 );

    for( p= libs; *p; p+=len ) {
        len=0;
        while (*p && !is_name_char(*p)) p++;    // bypass delimiters
        while (is_name_char(p[len])) len++;     // bypass name
        if (len && (!openlib( L, p, len )))
            break;
    }
    lua_gc(L, LUA_GCRESTART, 0);

    return *p ? p : NULL;
}
示例#2
0
static void openlib_work_handler(struct work_struct * work)
{
	struct lunatikW_work_struct *	openlib_work 	= lunatikW_container_of(work);
	lua_CFunction 			luaopen_func 	= (lua_CFunction) openlib_work->work_data;

	openlib(openlib_work->L, luaopen_func);

	return;
} /* end openlib_work_handler */
示例#3
0
METAMOD_PLUGIN *_GetPluginPtr(const char *path, int fail_api)
{
	METAMOD_FN_ORIG_LOAD fn;
	METAMOD_PLUGIN *pl;
	int ret;

	if (!(g_hCore=openlib(path)))
	{
#if defined __linux__ || defined __APPLE__
		UTIL_Format(s_FailPlugin.error_buffer, 
			sizeof(s_FailPlugin.error_buffer),
			"%s",
			dlerror());
#else
		DWORD err = GetLastError();

		if (FormatMessageA(
				FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				err,
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				s_FailPlugin.error_buffer,
				sizeof(s_FailPlugin.error_buffer),
				NULL)
			== 0)
		{
			UTIL_Format(s_FailPlugin.error_buffer, 
				sizeof(s_FailPlugin.error_buffer),
				"unknown error %x",
				err);
		}
#endif

		s_FailPlugin.fail_version = fail_api;

		return (METAMOD_PLUGIN *)&s_FailPlugin;
	}

	if (!(fn=(METAMOD_FN_ORIG_LOAD)findsym(g_hCore, "CreateInterface")))
	{
		goto error;
	}

	pl = (METAMOD_PLUGIN *)fn(METAMOD_PLAPI_NAME, &ret);
	if (!pl)
	{
		goto error;
	}

	return pl;
error:
	closelib(g_hCore);
	g_hCore = NULL;
	return NULL;
}
示例#4
0
void GL_ProcMapsDumpMatches(pid_t pid, int n, ...)
{
	int i;
	va_list ap;
	char buf[256];
	unsigned int addr[8];
	struct gsl_proc_maps entry;
	struct gsl_proc_maps *map;
	FILE *fp;

	if ((unsigned int)n >= (sizeof(addr) / sizeof(addr[0]))) {
		return;
	}

	va_start(ap, n);
	for (i = 0; i < n; ++i) {
		addr[i] = va_arg(ap, unsigned int);
	}

	snprintf(buf, sizeof(buf), "/proc/%u/maps", (unsigned int)pid);
	fp = fopen(buf, "r");
	if (!fp) {
		printf("Error: open file \"%s\" failed\n", buf);
		return;
	}
	map = &entry;
	while (0 != fgets(buf, sizeof(buf), fp)) {
		int flag = 0;

		sscanf(buf, "%x-%x %4s %x %hx:%hx %u %s",
			   &map->vm_start, &map->vm_end, &map->perm_str[0], &map->offset,
			   &map->dev.major, &map->dev.minor, &map->inode, &map->name[0]);

		for (i = 0; i < n; ++i) {
			if ((addr[i] >= map->vm_start) && (addr[i] < map->vm_end)) {
				printf("--> ");
				flag = 1;
				break;
			}
		}
		if (!flag) {
			printf("    ");
		}
		printf("%08x-%08x %4s %08x %02hx:%02hx %8u %s\n", map->vm_start, map->vm_end, map->perm_str, map->offset,
				map->dev.major, map->dev.minor, map->inode, map->name);
		if (flag) {
			printf("        offset = 0x%08X\n", addr[i] - map->vm_start);
			openlib(map->name, addr[i] - map->vm_start);
		}
	}
	fclose(fp);
	va_end(ap);
}