Edit

kc3-lang/angle/src/common/system_utils_win32.cpp

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2021-03-29 17:31:52
    Hash : 78dde332
    Message : Move restricted traces to CIPD. All traces are now stored as DEPS entries in CIPD. The auto-generation script generates the DEPS entries. Note that we don't include DEPS in the list of generated outputs to simplify other rollers. Also we update auto-generation to include full sources list to allow 'gn analyze' to work successfully. Usees a trace fixture for common code. This will enable a more compact trace without as much repeated code. We must land a set of re-trace traces to avoid breakage. Also includes a python script for uploading new traces to CIPD. The script first checks if traces are already present in the cloud, and if so it skips the upload. It will take a while to complete as the number of traces grows larger as it takes a few seconds per trace. The traces in this patch are also re-traced to use the common fixture code instead of including duplicated code in each trace. They now form a simple common interface and the autogenerated cpp is now simply a list of properties. I've also updated the capture/replay tests to use the simpler common entry point integration. There is less auto-generated glue code now. We now use a new serialized string query extension instead of calling directly into ANGLE's internals. Also includes a docs update. The capture/replay sample is broken and we'll need to update it in a follow-up CL. Also includes a few necessary fixes to the retracing script. Bug: angleproject:5811 Change-Id: I977bc6dc56843c8966377fc445ae97e91e17319a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2797833 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Tim Van Patten <timvp@google.com>

  • src/common/system_utils_win32.cpp
  • //
    // Copyright 2019 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_win32.cpp: Implementation of OS-specific functions for Windows.
    
    #include "system_utils.h"
    
    #include <windows.h>
    #include <array>
    
    namespace angle
    {
    bool UnsetEnvironmentVar(const char *variableName)
    {
        return (SetEnvironmentVariableA(variableName, nullptr) == TRUE);
    }
    
    bool SetEnvironmentVar(const char *variableName, const char *value)
    {
        return (SetEnvironmentVariableA(variableName, value) == TRUE);
    }
    
    std::string GetEnvironmentVar(const char *variableName)
    {
        std::array<char, MAX_PATH> oldValue;
        DWORD result =
            GetEnvironmentVariableA(variableName, oldValue.data(), static_cast<DWORD>(oldValue.size()));
        if (result == 0)
        {
            return std::string();
        }
        else
        {
            return std::string(oldValue.data());
        }
    }
    
    class Win32Library : public Library
    {
      public:
        Win32Library(const char *libraryName, SearchType searchType)
        {
            switch (searchType)
            {
                case SearchType::ApplicationDir:
                    mModule = LoadLibraryA(libraryName);
                    break;
                case SearchType::SystemDir:
                    mModule = LoadLibraryExA(libraryName, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
                    break;
            }
        }
    
        ~Win32Library() override
        {
            if (mModule)
            {
                FreeLibrary(mModule);
            }
        }
    
        void *getSymbol(const char *symbolName) override
        {
            if (!mModule)
            {
                fprintf(stderr, "Module was not loaded\n");
                return nullptr;
            }
    
            return reinterpret_cast<void *>(GetProcAddress(mModule, symbolName));
        }
    
        void *getNative() const override { return reinterpret_cast<void *>(mModule); }
    
      private:
        HMODULE mModule = nullptr;
    };
    
    Library *OpenSharedLibrary(const char *libraryName, SearchType searchType)
    {
        char buffer[MAX_PATH];
        int ret = snprintf(buffer, MAX_PATH, "%s.%s", libraryName, GetSharedLibraryExtension());
        if (ret > 0 && ret < MAX_PATH)
        {
            return new Win32Library(buffer, searchType);
        }
        else
        {
            fprintf(stderr, "Error loading shared library: 0x%x", ret);
            return nullptr;
        }
    }
    
    Library *OpenSharedLibraryWithExtension(const char *libraryName)
    {
        return new Win32Library(libraryName, SearchType::SystemDir);
    }
    }  // namespace angle