Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21597661 authored by Jesse Hall's avatar Jesse Hall
Browse files

libvulkan: Update global layer loading rules

* Look for layers in /data/local/debug/vulkan instead of
  /data/local/tmp/vulkan.
* Only enumerate global layers in debuggable processes.
* Only allow force-enabling layers and callbacks in debuggable
  processes.

Change-Id: I1f41a03ecbb0cc159e7dbb0b424005559996c196
(cherry picked from commit e784c114bbdc32361096cce8f59eb9513390e2d6)
parent 55cb98da
Loading
Loading
Loading
Loading
+18 −16
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <pthread.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/prctl.h>
// standard C++ headers
// standard C++ headers
#include <algorithm>
#include <algorithm>
#include <mutex>
#include <mutex>
@@ -305,11 +306,9 @@ void DestroyDevice(Device* device) {
void FindLayersInDirectory(Instance& instance, const String& dir_name) {
void FindLayersInDirectory(Instance& instance, const String& dir_name) {
    DIR* directory = opendir(dir_name.c_str());
    DIR* directory = opendir(dir_name.c_str());
    if (!directory) {
    if (!directory) {
        android_LogPriority log_priority =
        int err = errno;
            (errno == ENOENT) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_ERROR;
        ALOGW_IF(err != ENOENT, "failed to open layer directory '%s': %s (%d)",
        LOG_PRI(log_priority, LOG_TAG,
                 dir_name.c_str(), strerror(err), err);
                "failed to open layer directory '%s': %s (%d)",
                dir_name.c_str(), strerror(errno), errno);
        return;
        return;
    }
    }


@@ -443,7 +442,7 @@ VkResult ActivateAllLayers(TInfo create_info, Instance* instance, TObject* objec
                "Cannot activate layers for unknown object %p", object);
                "Cannot activate layers for unknown object %p", object);
    CallbackAllocator<char> string_allocator(instance->alloc);
    CallbackAllocator<char> string_allocator(instance->alloc);
    // Load system layers
    // Load system layers
    {
    if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) {
        char layer_prop[PROPERTY_VALUE_MAX];
        char layer_prop[PROPERTY_VALUE_MAX];
        property_get("debug.vulkan.layers", layer_prop, "");
        property_get("debug.vulkan.layers", layer_prop, "");
        String layer_name(string_allocator);
        String layer_name(string_allocator);
@@ -1010,8 +1009,8 @@ VkResult CreateInstance(const VkInstanceCreateInfo* create_info,


    // Scan layers
    // Scan layers
    CallbackAllocator<char> string_allocator(instance->alloc);
    CallbackAllocator<char> string_allocator(instance->alloc);

    String dir_name("/data/local/debug/vulkan/", string_allocator);
    String dir_name("/data/local/tmp/vulkan/", string_allocator);
    if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0))
        FindLayersInDirectory(*instance, dir_name);
        FindLayersInDirectory(*instance, dir_name);
    const std::string& path = LoaderData::GetInstance().layer_path;
    const std::string& path = LoaderData::GetInstance().layer_path;
    dir_name.assign(path.c_str(), path.size());
    dir_name.assign(path.c_str(), path.size());
@@ -1068,13 +1067,16 @@ VkResult CreateInstance(const VkInstanceCreateInfo* create_info,
    }
    }


    // Force enable callback extension if required
    // Force enable callback extension if required
    bool enable_callback =
    bool enable_callback = false;
    bool enable_logging = false;
    if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) {
        enable_callback =
            property_get_bool("debug.vulkan.enable_callback", false);
            property_get_bool("debug.vulkan.enable_callback", false);
    bool enable_logging = enable_callback;
        enable_logging = enable_callback;
    const char* extension_name = "DEBUG_REPORT";
        if (enable_callback) {
        if (enable_callback) {
            enable_callback = AddExtensionToCreateInfo(
            enable_callback = AddExtensionToCreateInfo(
            local_create_info, extension_name, instance->alloc);
                local_create_info, "DEBUG_REPORT", instance->alloc);
        }
    }
    }


    *out_instance = instance;
    *out_instance = instance;