• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GetExecutableName();
20 std::string GetExecutablePath();
21 std::string GetExecutableDirectory();
22 std::string GetModuleDirectory();
23 const char *GetSharedLibraryExtension();
24 const char *GetExecutableExtension();
25 char GetPathSeparator();
26 Optional<std::string> GetCWD();
27 bool SetCWD(const char *dirName);
28 bool SetEnvironmentVar(const char *variableName, const char *value);
29 bool UnsetEnvironmentVar(const char *variableName);
30 bool GetBoolEnvironmentVar(const char *variableName);
31 std::string GetEnvironmentVar(const char *variableName);
32 std::string GetEnvironmentVarOrUnCachedAndroidProperty(const char *variableName,
33                                                        const char *propertyName);
34 std::string GetEnvironmentVarOrAndroidProperty(const char *variableName, const char *propertyName);
35 const char *GetPathSeparatorForEnvironmentVar();
36 bool PrependPathToEnvironmentVar(const char *variableName, const char *path);
37 bool IsDirectory(const char *filename);
38 bool IsFullPath(std::string dirName);
39 std::string GetRootDirectory();
40 std::string ConcatenatePath(std::string first, std::string second);
41 
42 // Get absolute time in seconds.  Use this function to get an absolute time with an unknown origin.
43 double GetCurrentSystemTime();
44 // Get CPU time for current process in seconds.
45 double GetCurrentProcessCpuTime();
46 
47 // Run an application and get the output.  Gets a nullptr-terminated set of args to execute the
48 // application with, and returns the stdout and stderr outputs as well as the exit code.
49 //
50 // Pass nullptr for stdoutOut/stderrOut if you don't need to capture. exitCodeOut is required.
51 //
52 // Returns false if it fails to actually execute the application.
53 bool RunApp(const std::vector<const char *> &args,
54             std::string *stdoutOut,
55             std::string *stderrOut,
56             int *exitCodeOut);
57 
58 class Library : angle::NonCopyable
59 {
60   public:
~Library()61     virtual ~Library() {}
62     virtual void *getSymbol(const char *symbolName) = 0;
63     virtual void *getNative() const                 = 0;
64     virtual std::string getPath() const             = 0;
65 
66     template <typename FuncT>
getAs(const char * symbolName,FuncT * funcOut)67     void getAs(const char *symbolName, FuncT *funcOut)
68     {
69         *funcOut = reinterpret_cast<FuncT>(getSymbol(symbolName));
70     }
71 };
72 
73 // Use SYSTEM_DIR to bypass loading ANGLE libraries with the same name as system DLLS
74 // (e.g. opengl32.dll)
75 enum class SearchType
76 {
77     // Try to find the library in the same directory as the current module
78     ModuleDir,
79     // Load the library from the system directories
80     SystemDir,
81     // Get a reference to an already loaded shared library.
82     AlreadyLoaded,
83 };
84 
85 Library *OpenSharedLibrary(const char *libraryName, SearchType searchType);
86 Library *OpenSharedLibraryWithExtension(const char *libraryName, SearchType searchType);
87 
88 // Returns true if the process is currently being debugged.
89 bool IsDebuggerAttached();
90 
91 // Calls system APIs to break into the debugger.
92 void BreakDebugger();
93 }  // namespace angle
94 
95 #endif  // COMMON_SYSTEM_UTILS_H_
96