C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
{
	CK_FUNCTION_LIST_PTR module = NULL;
	CK_FUNCTION_LIST **loaded = NULL;
	State *state;
	CK_RV rv = CKR_OK;

	p11_library_init_once ();
	p11_lock ();

	/* WARNING: Reentrancy can occur here */
	rv = p11_modules_load_inlock_reentrant (P11_KIT_MODULE_LOADED_FROM_PROXY, &loaded);
	if (rv == CKR_OK) {
		state = calloc (1, sizeof (State));
		if (!state) {
			rv = CKR_HOST_MEMORY;

		} else {
			p11_virtual_init (&state->virt, &proxy_functions, state, NULL);
			state->last_handle = FIRST_HANDLE;
			state->loaded = loaded;
			loaded = NULL;

			module = p11_virtual_wrap (&state->virt, free);
			if (module == NULL) {
				rv = CKR_GENERAL_ERROR;

			} else {
				state->wrapped = module;
				state->next = all_instances;
				all_instances = state;
			}
		}
	}

	if (rv == CKR_OK)
		*list = module;

	if (loaded)
		p11_kit_modules_release (loaded);

	p11_unlock ();

	return rv;
}
C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
{
	CK_FUNCTION_LIST_PTR module = NULL;
	CK_FUNCTION_LIST **loaded = NULL;
	State *state;
	CK_RV rv = CKR_OK;

	p11_library_init_once ();
	p11_lock ();

	 
	rv = p11_modules_load_inlock_reentrant (P11_KIT_MODULE_LOADED_FROM_PROXY, &loaded);
	if (rv == CKR_OK) {
		state = calloc (1, sizeof (State));
		if (!state) {
			rv = CKR_HOST_MEMORY;

		} else {
			p11_virtual_init (&state->virt, &proxy_functions, state, NULL);
			state->last_handle = FIRST_HANDLE;
			state->loaded = loaded;
			loaded = NULL;

			module = p11_virtual_wrap (&state->virt, free);
			if (module == NULL) {
				rv = CKR_GENERAL_ERROR;

			} else {
				state->wrapped = module;
				state->next = all_instances;
				all_instances = state;
			}
		}
	}

	if (rv == CKR_OK)
		*list = module;

	if (loaded)
		p11_kit_modules_release (loaded);

	p11_unlock ();

	return rv;
}