blob: bd1609e1b44b0b2a29602d972b28d5b7fdd92e7c [file] [log] [blame]
/*
*
* Copyright (c) 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <lib/fdio/directory.h>
#include <zircon/device/vfs.h>
#include "loader.h"
typedef VkResult(VKAPI_PTR *PFN_vkOpenInNamespaceAddr)(const char *pName, uint32_t handle);
typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_vkInitializeOpenInNamespaceCallbackAddr)(PFN_vkOpenInNamespaceAddr);
VKAPI_ATTR static VkResult VKAPI_CALL loader_fdio_open_in_namespace(const char *pName, uint32_t handle) {
// fdio_service_connect specifies READ+WRITE, which fails for read-only files
zx_status_t status = fdio_open(pName, ZX_FS_RIGHT_READABLE, handle);
if (status == ZX_OK) {
return VK_SUCCESS;
} else {
loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Failed to open in namespace %s - error %d", pName, status);
return VK_ERROR_INITIALIZATION_FAILED;
}
}
void loader_initialize_icd_services(loader_platform_dl_handle handle) {
PFN_vkInitializeOpenInNamespaceCallbackAddr fp_initialize_open_in_namespace_callback_addr;
fp_initialize_open_in_namespace_callback_addr =
loader_platform_get_proc_address(handle, "vk_icdInitializeOpenInNamespaceCallback");
if (fp_initialize_open_in_namespace_callback_addr) {
fp_initialize_open_in_namespace_callback_addr(&loader_fdio_open_in_namespace);
// ICD isn't required to expose this entrypoint.
return;
}
}