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 namespace angle 16 { 17 std::string GetExecutablePath(); 18 std::string GetExecutableDirectory(); 19 const char *GetSharedLibraryExtension(); 20 Optional<std::string> GetCWD(); 21 bool SetCWD(const char *dirName); 22 bool SetEnvironmentVar(const char *variableName, const char *value); 23 bool UnsetEnvironmentVar(const char *variableName); 24 std::string GetEnvironmentVar(const char *variableName); 25 const char *GetPathSeparator(); 26 bool PrependPathToEnvironmentVar(const char *variableName, const char *path); 27 bool IsDirectory(const char *filename); 28 29 // Run an application and get the output. Gets a nullptr-terminated set of args to execute the 30 // application with, and returns the stdout and stderr outputs as well as the exit code. 31 // 32 // Pass nullptr for stdoutOut/stderrOut if you don't need to capture. exitCodeOut is required. 33 // 34 // Returns false if it fails to actually execute the application. 35 bool RunApp(const std::vector<const char *> &args, 36 std::string *stdoutOut, 37 std::string *stderrOut, 38 int *exitCodeOut); 39 40 class Library : angle::NonCopyable 41 { 42 public: ~Library()43 virtual ~Library() {} 44 virtual void *getSymbol(const char *symbolName) = 0; 45 virtual void *getNative() const = 0; 46 47 template <typename FuncT> getAs(const char * symbolName,FuncT * funcOut)48 void getAs(const char *symbolName, FuncT *funcOut) 49 { 50 *funcOut = reinterpret_cast<FuncT>(getSymbol(symbolName)); 51 } 52 }; 53 54 // Use SYSTEM_DIR to bypass loading ANGLE libraries with the same name as system DLLS 55 // (e.g. opengl32.dll) 56 enum class SearchType 57 { 58 ApplicationDir, 59 SystemDir 60 }; 61 62 Library *OpenSharedLibrary(const char *libraryName, SearchType searchType); 63 64 // Returns true if the process is currently being debugged. 65 bool IsDebuggerAttached(); 66 67 // Calls system APIs to break into the debugger. 68 void BreakDebugger(); 69 } // namespace angle 70 71 #endif // COMMON_SYSTEM_UTILS_H_ 72