1 // 2 // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // system_utils.h: declaration of OS-specific utility functions 8 9 #ifndef COMMON_SYSTEM_UTILS_H_ 10 #define COMMON_SYSTEM_UTILS_H_ 11 12 #include "common/Optional.h" 13 #include "common/angleutils.h" 14 15 #include <string> 16 17 namespace angle 18 { 19 std::string GetExecutablePath(); 20 std::string GetExecutableDirectory(); 21 std::string GetHelperExecutableDir(); 22 const char *GetSharedLibraryExtension(); 23 const char *GetExecutableExtension(); 24 char GetPathSeparator(); 25 Optional<std::string> GetCWD(); 26 bool SetCWD(const char *dirName); 27 bool SetEnvironmentVar(const char *variableName, const char *value); 28 bool UnsetEnvironmentVar(const char *variableName); 29 std::string GetEnvironmentVar(const char *variableName); 30 const char *GetPathSeparatorForEnvironmentVar(); 31 bool PrependPathToEnvironmentVar(const char *variableName, const char *path); 32 bool IsDirectory(const char *filename); 33 34 // Get absolute time in seconds. Use this function to get an absolute time with an unknown origin. 35 double GetCurrentTime(); 36 37 // Run an application and get the output. Gets a nullptr-terminated set of args to execute the 38 // application with, and returns the stdout and stderr outputs as well as the exit code. 39 // 40 // Pass nullptr for stdoutOut/stderrOut if you don't need to capture. exitCodeOut is required. 41 // 42 // Returns false if it fails to actually execute the application. 43 bool RunApp(const std::vector<const char *> &args, 44 std::string *stdoutOut, 45 std::string *stderrOut, 46 int *exitCodeOut); 47 48 class Library : angle::NonCopyable 49 { 50 public: ~Library()51 virtual ~Library() {} 52 virtual void *getSymbol(const char *symbolName) = 0; 53 virtual void *getNative() const = 0; 54 55 template <typename FuncT> getAs(const char * symbolName,FuncT * funcOut)56 void getAs(const char *symbolName, FuncT *funcOut) 57 { 58 *funcOut = reinterpret_cast<FuncT>(getSymbol(symbolName)); 59 } 60 }; 61 62 // Use SYSTEM_DIR to bypass loading ANGLE libraries with the same name as system DLLS 63 // (e.g. opengl32.dll) 64 enum class SearchType 65 { 66 ApplicationDir, 67 SystemDir 68 }; 69 70 Library *OpenSharedLibrary(const char *libraryName, SearchType searchType); 71 72 // Returns true if the process is currently being debugged. 73 bool IsDebuggerAttached(); 74 75 // Calls system APIs to break into the debugger. 76 void BreakDebugger(); 77 } // namespace angle 78 79 #endif // COMMON_SYSTEM_UTILS_H_ 80