p11_proxy_module_create (CK_FUNCTION_LIST_PTR *module,
			 CK_FUNCTION_LIST_PTR *modules)
{
	State *state;
	CK_RV rv = CKR_OK;

	assert (module != NULL);
	assert (modules != NULL);

	state = calloc (1, sizeof (State));
	if (!state)
		return CKR_HOST_MEMORY;

	p11_virtual_init (&state->virt, &proxy_functions, state, NULL);
	state->last_handle = FIRST_HANDLE;
	state->loaded = modules_dup (modules);
	state->wrapped = p11_virtual_wrap (&state->virt, (p11_destroyer)p11_virtual_uninit);
	if (state->wrapped == NULL) {
		p11_kit_modules_release (state->loaded);
		free (state);
		return CKR_GENERAL_ERROR;
	}

	*module = state->wrapped;

	return rv;
}
p11_proxy_module_create (CK_FUNCTION_LIST_PTR *module,
			 CK_FUNCTION_LIST_PTR *modules)
{
	State *state;
	CK_RV rv = CKR_OK;

	assert (module != NULL);
	assert (modules != NULL);

	state = calloc (1, sizeof (State));
	if (!state)
		return CKR_HOST_MEMORY;

	p11_virtual_init (&state->virt, &proxy_functions, state, NULL);
	state->last_handle = FIRST_HANDLE;
	state->loaded = modules_dup (modules);
	state->wrapped = p11_virtual_wrap (&state->virt, (p11_destroyer)p11_virtual_uninit);
	if (state->wrapped == NULL) {
		p11_kit_modules_release (state->loaded);
		free (state);
		return CKR_GENERAL_ERROR;
	}

	*module = state->wrapped;

	return rv;
}