Hash :
e2fc818a
        
        Author :
  
        
        Date :
2021-05-05T11:51:00
        
      
Reland Change to module directory when loading swiftshader ICD. This is a reland of commit 3b10dda6a479612a07673b5c87d3560e0941d41b. Extra changes: Be explicit about calling GetModuleHandleA Do not use the general GetModuleHandle, which may use wide strings Refactored ConcatenatePath and add tests GetModuleDirectory should return the full path, not relative. ANGLE wasn't able to locate the vulkan ICD file because it was searching down an invalid relative path. This can be fixed by ensuring the module directory is always the full path. on some platforms. Original change's description: > When loading vulkan, we can be running from any directory. We need > to change to the module directory to ensure the swiftshader ICD is > loaded properly. For example, in some Chrome releases, libGLESv2.dll > and libvk_swiftshader.dll are in a subdirectory relative to chrome.exe > > Bug: chromium:1198567 > Change-Id: I9e68927e512b239728fb2903d1a04702508a4948 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2873452 > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > Reviewed-by: Jamie Madill <jmadill@chromium.org> Bug: chromium:1198567 Bug: angleproject:5949 Change-Id: I63fbe93f8492b7f23566f8193b1b8fe784a34f71 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2904586 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
//
// Copyright 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// system_utils_win.cpp: Implementation of OS-specific functions for Windows
#include "system_utils.h"
#include <stdarg.h>
#include <windows.h>
#include <array>
#include <vector>
namespace angle
{
namespace
{
std::string GetPath(HMODULE module)
{
    std::array<char, MAX_PATH> executableFileBuf;
    DWORD executablePathLen = GetModuleFileNameA(module, executableFileBuf.data(),
                                                 static_cast<DWORD>(executableFileBuf.size()));
    return (executablePathLen > 0 ? std::string(executableFileBuf.data()) : "");
}
std::string GetDirectory(HMODULE module)
{
    std::string executablePath = GetPath(module);
    size_t lastPathSepLoc      = executablePath.find_last_of("\\/");
    return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : "";
}
}  // anonymous namespace
std::string GetExecutablePath()
{
    return GetPath(nullptr);
}
std::string GetExecutableDirectory()
{
    return GetDirectory(nullptr);
}
const char *GetSharedLibraryExtension()
{
    return "dll";
}
Optional<std::string> GetCWD()
{
    std::array<char, MAX_PATH> pathBuf;
    DWORD result = GetCurrentDirectoryA(static_cast<DWORD>(pathBuf.size()), pathBuf.data());
    if (result == 0)
    {
        return Optional<std::string>::Invalid();
    }
    return std::string(pathBuf.data());
}
bool SetCWD(const char *dirName)
{
    return (SetCurrentDirectoryA(dirName) == TRUE);
}
const char *GetPathSeparatorForEnvironmentVar()
{
    return ";";
}
double GetCurrentTime()
{
    LARGE_INTEGER frequency = {};
    QueryPerformanceFrequency(&frequency);
    LARGE_INTEGER curTime;
    QueryPerformanceCounter(&curTime);
    return static_cast<double>(curTime.QuadPart) / frequency.QuadPart;
}
bool IsDirectory(const char *filename)
{
    WIN32_FILE_ATTRIBUTE_DATA fileInformation;
    BOOL result = GetFileAttributesExA(filename, GetFileExInfoStandard, &fileInformation);
    if (result)
    {
        DWORD attribs = fileInformation.dwFileAttributes;
        return (attribs != INVALID_FILE_ATTRIBUTES) && ((attribs & FILE_ATTRIBUTE_DIRECTORY) > 0);
    }
    return false;
}
bool IsDebuggerAttached()
{
    return !!::IsDebuggerPresent();
}
void BreakDebugger()
{
    __debugbreak();
}
const char *GetExecutableExtension()
{
    return ".exe";
}
char GetPathSeparator()
{
    return '\\';
}
std::string GetModuleDirectory()
{
// GetModuleHandleEx is unavailable on UWP
#if !defined(ANGLE_IS_WINUWP)
    static int placeholderSymbol = 0;
    HMODULE module               = nullptr;
    if (GetModuleHandleExA(
            GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
            reinterpret_cast<LPCSTR>(&placeholderSymbol), &module))
    {
        return GetDirectory(module);
    }
#endif
    return GetDirectory(nullptr);
}
std::string GetRootDirectory()
{
    return "C:\\";
}
}  // namespace angle