2019-03-18 05:52:32 +00:00
|
|
|
// Copyright 2018-2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief File for verifing app input into api functions.
|
|
|
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup oxr_main
|
|
|
|
* @ingroup oxr_api
|
|
|
|
*/
|
|
|
|
|
2019-04-05 09:37:57 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
#include "xrt/xrt_compiler.h"
|
|
|
|
#include "util/u_debug.h"
|
|
|
|
|
|
|
|
#include "oxr_objects.h"
|
|
|
|
#include "oxr_logger.h"
|
|
|
|
#include "oxr_api_verify.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Path verification.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-04-05 09:37:57 +00:00
|
|
|
static bool
|
|
|
|
valid_path_char(const char c)
|
|
|
|
{
|
|
|
|
if ('a' <= c && c <= 'z') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('0' <= c && c <= '9') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '-' || c == '_' || c == '.' || c == '/') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-25 01:18:17 +00:00
|
|
|
static bool
|
2019-03-18 05:52:32 +00:00
|
|
|
contains_zero(const char* path, uint32_t size)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < size; i++) {
|
|
|
|
if (path[i] == '\0') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-25 01:18:17 +00:00
|
|
|
extern "C" XrResult
|
2019-03-18 05:52:32 +00:00
|
|
|
oxr_verify_fixed_size_single_level_path(struct oxr_logger* log,
|
|
|
|
const char* path,
|
2019-04-05 09:37:57 +00:00
|
|
|
uint32_t array_size,
|
2019-03-18 05:52:32 +00:00
|
|
|
const char* name)
|
|
|
|
{
|
2019-04-05 09:37:57 +00:00
|
|
|
if (array_size == 0) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(%s) internal runtime error", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path[0] == '\0') {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(%s) can not be empty", name);
|
|
|
|
}
|
|
|
|
|
2019-04-05 09:37:57 +00:00
|
|
|
if (!contains_zero(path, array_size)) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(%s) must include zero termination '\\0'.",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
|
2019-04-05 09:37:57 +00:00
|
|
|
size_t length = strlen(path);
|
|
|
|
for (size_t i = 0; i < length; i++) {
|
|
|
|
const char c = path[i];
|
|
|
|
|
|
|
|
// Slashes are not valid in single level paths.
|
|
|
|
if (valid_path_char(c) && c != '/') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(%s) 0x%02x is not a valid character at position %u", name,
|
|
|
|
c, (uint32_t)i);
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Other verification.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-03-25 01:18:17 +00:00
|
|
|
extern "C" XrResult
|
2019-03-18 05:52:32 +00:00
|
|
|
oxr_verify_XrSessionCreateInfo(struct oxr_logger* log,
|
2019-03-25 01:18:17 +00:00
|
|
|
const struct oxr_instance* inst,
|
2019-03-18 05:52:32 +00:00
|
|
|
const XrSessionCreateInfo* createInfo)
|
|
|
|
{
|
|
|
|
if (createInfo->type != XR_TYPE_SESSION_CREATE_INFO) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"createInfo->type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (createInfo->next == NULL) {
|
2019-03-23 01:11:14 +00:00
|
|
|
if (inst->headless) {
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"createInfo->next");
|
|
|
|
}
|
|
|
|
|
|
|
|
XrStructureType* next_type = (XrStructureType*)createInfo->next;
|
|
|
|
#ifdef XR_USE_PLATFORM_XLIB
|
|
|
|
if (*next_type == XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR) {
|
2019-03-24 21:13:35 +00:00
|
|
|
if (!inst->opengl_enable) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"OpenGL "
|
|
|
|
"requires " XR_KHR_OPENGL_ENABLE_EXTENSION_NAME);
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_verify_XrGraphicsBindingOpenGLXlibKHR(
|
|
|
|
log, (XrGraphicsBindingOpenGLXlibKHR*)createInfo->next);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef XR_USE_GRAPHICS_API_VULKAN
|
2019-03-27 13:35:15 +00:00
|
|
|
if (*next_type == XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR) {
|
2019-03-24 21:13:35 +00:00
|
|
|
if (!inst->vulkan_enable) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"Vulkan "
|
|
|
|
"requires " XR_KHR_VULKAN_ENABLE_EXTENSION_NAME);
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_verify_XrGraphicsBindingVulkanKHR(
|
|
|
|
log, (XrGraphicsBindingVulkanKHR*)createInfo->next);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"createInfo->next->type");
|
|
|
|
}
|
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-03-25 01:18:17 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#ifdef XR_USE_PLATFORM_XLIB
|
2019-03-25 01:18:17 +00:00
|
|
|
|
|
|
|
extern "C" XrResult
|
2019-03-18 05:52:32 +00:00
|
|
|
oxr_verify_XrGraphicsBindingOpenGLXlibKHR(
|
|
|
|
struct oxr_logger* log, const XrGraphicsBindingOpenGLXlibKHR* next)
|
|
|
|
{
|
|
|
|
if (next->type != XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"createInfo->next->type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next->next != NULL) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"createInfo->next->next");
|
|
|
|
}
|
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
2019-03-25 01:18:17 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#endif
|
|
|
|
|
2019-03-25 01:18:17 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#ifdef XR_USE_GRAPHICS_API_VULKAN
|
2019-03-25 01:18:17 +00:00
|
|
|
|
|
|
|
extern "C" XrResult
|
2019-03-18 05:52:32 +00:00
|
|
|
oxr_verify_XrGraphicsBindingVulkanKHR(struct oxr_logger* log,
|
|
|
|
const XrGraphicsBindingVulkanKHR* next)
|
|
|
|
{
|
|
|
|
if (next->type != XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"createInfo->next->type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next->next != NULL) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"createInfo->next->next");
|
|
|
|
}
|
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
2019-03-25 01:18:17 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#endif
|