Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
WindowsPlatformProcess.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "GenericPlatform/GenericPlatformProcess.h"
7#include "Windows/WindowsSystemIncludes.h"
8
9class FEvent;
10class FRunnableThread;
11
12/** Windows implementation of the process handle. */
13struct FProcHandle : public TProcHandle<Windows::HANDLE, nullptr>
14{
15public:
16 /** Default constructor. */
18 : TProcHandle()
19 {}
20
21 /** Initialization constructor. */
22 FORCEINLINE explicit FProcHandle( HandleType Other )
24 {}
25};
26
27
28/**
29* Windows implementation of the Process OS functions.
30**/
33{
34 /**
35 * Windows representation of a interprocess semaphore
36 */
38 {
39 virtual void Lock();
40 virtual bool TryLock(uint64 NanosecondsToWait);
41 virtual void Unlock();
42
43 /** Returns the OS handle */
45
46 /** Constructor */
47 FWindowsSemaphore(const FString& InName, Windows::HANDLE InSemaphore);
48
49 /** Allocation free constructor */
50 FWindowsSemaphore(const TCHAR* InName, Windows::HANDLE InSemaphore);
51
52 /** Destructor */
54
55 protected:
56
57 /** OS handle */
59 };
60
61 struct FProcEnumInfo;
62
63 /**
64 * Process enumerator.
65 */
67 {
68 public:
69 // Constructor
73
74 // Destructor
76
77 // Gets current process enumerator info.
79
80 /**
81 * Moves current to the next process.
82 *
83 * @returns True if succeeded. False otherwise.
84 */
85 bool MoveNext();
86 private:
87 // Process info structure for current process.
89
90 // Processes state snapshot handle.
92 };
93
94 /**
95 * Process enumeration info structure.
96 */
98 {
100 public:
101 // Destructor
103
104 // Gets process PID.
105 uint32 GetPID() const;
106
107 // Gets parent process PID.
108 uint32 GetParentPID() const;
109
110 // Gets process name. I.e. exec name.
112
113 // Gets process full image path. I.e. full path of the exec file.
115
116 private:
117 // Private constructor.
119
120 // Process info structure.
122 };
123
124public:
125
126 // FGenericPlatformProcess interface
127
128 static void* GetDllHandle( const TCHAR* Filename );
129 static void FreeDllHandle( void* DllHandle );
130 static void* GetDllExport( void* DllHandle, const TCHAR* ProcName );
131 static void AddDllDirectory(const TCHAR* Directory);
132 static void GetDllDirectories(TArray<FString>& OutDllDirectories);
133 static void PushDllDirectory(const TCHAR* Directory);
134 static void PopDllDirectory(const TCHAR* Directory);
135 static uint32 GetCurrentProcessId();
136 static uint32 GetCurrentCoreNumber();
137 static void SetThreadAffinityMask( uint64 AffinityMask );
138 static void SetThreadName( const TCHAR* ThreadName );
139 static const TCHAR* BaseDir();
140 static const TCHAR* UserDir();
141 static const TCHAR* UserTempDir();
142 static const TCHAR* UserSettingsDir();
143 static const TCHAR* ApplicationSettingsDir();
144 static const TCHAR* ComputerName();
145 static const TCHAR* UserName(bool bOnlyAlphaNumeric = true);
148 static const FString ShaderWorkingDir();
149 static const TCHAR* ExecutablePath();
150 static const TCHAR* ExecutableName(bool bRemoveExtension = true);
151 static FString GenerateApplicationPath( const FString& AppName, EBuildConfiguration BuildConfiguration);
152 static const TCHAR* GetModuleExtension();
153 static const TCHAR* GetBinariesSubdirectory();
155 static bool CanLaunchURL(const TCHAR* URL);
156 static void LaunchURL( const TCHAR* URL, const TCHAR* Parms, FString* Error );
157 static FProcHandle CreateProc( const TCHAR* URL, const TCHAR* Parms, bool bLaunchDetached, bool bLaunchHidden, bool bLaunchReallyHidden, uint32* OutProcessID, int32 PriorityModifier, const TCHAR* OptionalWorkingDirectory, void* PipeWriteChild, void* PipeReadChild = nullptr);
158 static FProcHandle CreateProc( const TCHAR* URL, const TCHAR* Parms, bool bLaunchDetached, bool bLaunchHidden, bool bLaunchReallyHidden, uint32* OutProcessID, int32 PriorityModifier, const TCHAR* OptionalWorkingDirectory, void* PipeWriteChild, void* PipeReadChild, void* PipeStdErrChild);
159 static bool SetProcPriority(FProcHandle & InProcHandle, int32 PriorityModifier);
160 static FProcHandle OpenProcess(uint32 ProcessID);
161 static bool IsProcRunning( FProcHandle & ProcessHandle );
162 static void WaitForProc( FProcHandle & ProcessHandle );
163 static void CloseProc( FProcHandle & ProcessHandle );
164 static void TerminateProc( FProcHandle & ProcessHandle, bool KillTree = false );
166 FProcHandle& ProcessHandle,
167 TFunctionRef<bool(uint32 ProcessId, const TCHAR* ApplicationName)> Predicate);
168 static bool GetProcReturnCode( FProcHandle & ProcHandle, int32* ReturnCode );
169 static bool GetApplicationMemoryUsage(uint32 ProcessId, SIZE_T* OutMemoryUsage);
170 static bool GetPerFrameProcessorUsage(uint32 ProcessId, float& ProcessUsageFraction, float& IdleUsageFraction);
171 static bool IsApplicationRunning( uint32 ProcessId );
172 static bool IsApplicationRunning( const TCHAR* ProcName );
173 static FString GetApplicationName( uint32 ProcessId );
174 static bool ExecProcess(const TCHAR* URL, const TCHAR* Params, int32* OutReturnCode, FString* OutStdOut, FString* OutStdErr, const TCHAR* OptionalWorkingDirectory = NULL, bool bShouldEndWithParentProcess = false);
175 static bool ExecElevatedProcess(const TCHAR* URL, const TCHAR* Params, int32* OutReturnCode);
176 static FProcHandle CreateElevatedProcess(const TCHAR* URL, const TCHAR* Params);
177 static bool LaunchFileInDefaultExternalApplication( const TCHAR* FileName, const TCHAR* Parms = NULL, ELaunchVerb::Type Verb = ELaunchVerb::Open, bool bPromptToOpenOnFailure = true );
178 static void ExploreFolder( const TCHAR* FilePath );
179 static bool ResolveNetworkPath( FString InUNCPath, FString& OutPath );
180 static void Sleep(float Seconds);
181 static void SleepNoStats(float Seconds);
182 [[noreturn]] static void SleepInfinite();
183 static void YieldThread();
184 UE_DEPRECATED(5.0, "Please use GetSynchEventFromPool to create a new event, and ReturnSynchEventToPool to release the event.")
185 static class FEvent* CreateSynchEvent(bool bIsManualReset = false);
187 static void ClosePipe( void* ReadPipe, void* WritePipe );
188 static bool CreatePipe(void*& ReadPipe, void*& WritePipe, bool bWritePipeLocal = false);
189 static FString ReadPipe( void* ReadPipe );
190 static bool ReadPipeToArray(void* ReadPipe, TArray<uint8> & Output);
191 static bool WritePipe(void* WritePipe, const FString& Message, FString* OutWritten = nullptr);
192 static bool WritePipe(void* WritePipe, const uint8* Data, const int32 DataLength, int32* OutDataLength = nullptr);
193 static FSemaphore* NewInterprocessSynchObject(const FString& Name, bool bCreate, uint32 MaxLocks = 1);
194 static FSemaphore* NewInterprocessSynchObject(const TCHAR* Name, bool bCreate, uint32 MaxLocks = 1);
196 static bool Daemonize();
197 static void SetupGameThread();
198 static void SetupAudioThread();
199 static void TeardownAudioThread();
200 static bool IsFirstInstance();
201
202 /**
203 * @brief Releases locks that we held for IsFirstInstance check
204 */
206
207protected:
208
209 /**
210 * Reads from a collection of anonymous pipes.
211 *
212 * @param OutStrings Will hold the read data.
213 * @param InPipes The pipes to read from.
214 * @param PipeCount The number of pipes.
215 */
216 static void ReadFromPipes(FString* OutStrings[], Windows::HANDLE InPipes[], int32 PipeCount);
217
218private:
219
220 /**
221 * Since Windows can only have one directory at a time,
222 * this stack is used to reset the previous DllDirectory.
223 */
225
226 /**
227 * All the DLL directories we want to load from.
228 */
230
231 /**
232 * A cache of the dlls found in each directory in DllDirectories.
233 */
235
236 /**
237 * Replacement implementation of the Win32 LoadLibrary function which searches the given list of directories for dependent imports, and attempts
238 * to load them from the correct location first. The normal LoadLibrary function (pre-Win8) only searches a limited list of locations.
239 *
240 * @param FileName Path to the library to load
241 * @param SearchPaths Search directories to scan for imports
242 */
243 static void* LoadLibraryWithSearchPaths(const FString& FileName, const TArray<FString>& SearchPaths);
244
245 /**
246 * Resolve an individual import.
247 *
248 * @param ImportName Name of the imported module
249 * @param OutFileName On success, receives the path to the imported file
250 * @return true if an import was found.
251 */
252 static bool ResolveImport(const FString& Name, const TArray<FString>& SearchPaths, FString& OutFileName);
253
254 /**
255 * Resolve all the imports for the given library, searching through a set of directories.
256 *
257 * @param FileName Path to the library to load
258 * @param SearchPaths Search directories to scan for imports
259 * @param ImportFileNames Array which is filled with a list of the resolved imports found in the given search directories
260 * @param VisitedImportNames Array which stores a list of imports which have been checked
261 */
262 static void ResolveMissingImportsRecursive(const FString& FileName, const TArray<FString>& SearchPaths, TArray<FString>& ImportFileNames, TSet<FString>& VisitedImportNames);
263};
264
266typedef FWindowsPlatformProcess FPlatformProcess;
267#endif
#define UE_DEPRECATED(Version, Message)
EBuildConfiguration
#define FORCEINLINE
Definition Platform.h:644
#define WINDOWS_USE_FEATURE_PLATFORMPROCESS_CLASS
Definition Event.h:21
FProcEnumerator(const FProcEnumerator &)=delete
FProcEnumerator & operator=(const FProcEnumerator &)=delete
tagPROCESSENTRY32W PROCESSENTRY32
FORCEINLINE FProcHandle(HandleType Other)
FORCEINLINE FProcHandle()
FProcEnumInfo(const Windows::PROCESSENTRY32 &InInfo)
FWindowsSemaphore(const TCHAR *InName, Windows::HANDLE InSemaphore)
virtual bool TryLock(uint64 NanosecondsToWait)
FWindowsSemaphore(const FString &InName, Windows::HANDLE InSemaphore)
static bool ExecProcess(const TCHAR *URL, const TCHAR *Params, int32 *OutReturnCode, FString *OutStdOut, FString *OutStdErr, const TCHAR *OptionalWorkingDirectory=NULL, bool bShouldEndWithParentProcess=false)
static bool IsProcRunning(FProcHandle &ProcessHandle)
static void TerminateProc(FProcHandle &ProcessHandle, bool KillTree=false)
static void SleepInfinite()
static const TCHAR * UserTempDir()
static TMap< FName, TArray< FString > > SearchPathDllCache
static bool SetProcPriority(FProcHandle &InProcHandle, int32 PriorityModifier)
static void TerminateProcTreeWithPredicate(FProcHandle &ProcessHandle, TFunctionRef< bool(uint32 ProcessId, const TCHAR *ApplicationName)> Predicate)
static bool WritePipe(void *WritePipe, const uint8 *Data, const int32 DataLength, int32 *OutDataLength=nullptr)
static uint32 GetCurrentCoreNumber()
static void PopDllDirectory(const TCHAR *Directory)
static const TCHAR * UserDir()
static const TCHAR * BaseDir()
static bool DeleteInterprocessSynchObject(FSemaphore *Object)
static bool ReadPipeToArray(void *ReadPipe, TArray< uint8 > &Output)
static bool CreatePipe(void *&ReadPipe, void *&WritePipe, bool bWritePipeLocal=false)
static const TCHAR * GetBinariesSubdirectory()
static bool CanLaunchURL(const TCHAR *URL)
static const TCHAR * UserName(bool bOnlyAlphaNumeric=true)
static void YieldThread()
static const TCHAR * ExecutableName(bool bRemoveExtension=true)
static void TeardownAudioThread()
static bool GetPerFrameProcessorUsage(uint32 ProcessId, float &ProcessUsageFraction, float &IdleUsageFraction)
static void ClosePipe(void *ReadPipe, void *WritePipe)
static bool GetProcReturnCode(FProcHandle &ProcHandle, int32 *ReturnCode)
static bool LaunchFileInDefaultExternalApplication(const TCHAR *FileName, const TCHAR *Parms=NULL, ELaunchVerb::Type Verb=ELaunchVerb::Open, bool bPromptToOpenOnFailure=true)
static FString ReadPipe(void *ReadPipe)
static FProcHandle CreateProc(const TCHAR *URL, const TCHAR *Parms, bool bLaunchDetached, bool bLaunchHidden, bool bLaunchReallyHidden, uint32 *OutProcessID, int32 PriorityModifier, const TCHAR *OptionalWorkingDirectory, void *PipeWriteChild, void *PipeReadChild=nullptr)
static const TCHAR * GetModuleExtension()
static void SetCurrentWorkingDirectoryToBaseDir()
static const TCHAR * UserSettingsDir()
static void FreeDllHandle(void *DllHandle)
static FString GenerateApplicationPath(const FString &AppName, EBuildConfiguration BuildConfiguration)
static FProcHandle CreateElevatedProcess(const TCHAR *URL, const TCHAR *Params)
static const TCHAR * ComputerName()
static void AddDllDirectory(const TCHAR *Directory)
static void * GetDllExport(void *DllHandle, const TCHAR *ProcName)
static void * LoadLibraryWithSearchPaths(const FString &FileName, const TArray< FString > &SearchPaths)
static void GetDllDirectories(TArray< FString > &OutDllDirectories)
static TArray< FString > DllDirectoryStack
static void WaitForProc(FProcHandle &ProcessHandle)
static bool ExecElevatedProcess(const TCHAR *URL, const TCHAR *Params, int32 *OutReturnCode)
static void PushDllDirectory(const TCHAR *Directory)
static bool IsApplicationRunning(uint32 ProcessId)
static const TCHAR * ExecutablePath()
static void Sleep(float Seconds)
static const TCHAR * ApplicationSettingsDir()
static void SetThreadAffinityMask(uint64 AffinityMask)
static FString GetCurrentWorkingDirectory()
static bool IsApplicationRunning(const TCHAR *ProcName)
static void ReadFromPipes(FString *OutStrings[], Windows::HANDLE InPipes[], int32 PipeCount)
static FString GetApplicationName(uint32 ProcessId)
static uint32 GetCurrentProcessId()
static FProcHandle OpenProcess(uint32 ProcessID)
static void CeaseBeingFirstInstance()
Releases locks that we held for IsFirstInstance check.
static void SleepNoStats(float Seconds)
static bool Daemonize()
static class FRunnableThread * CreateRunnableThread()
static void ResolveMissingImportsRecursive(const FString &FileName, const TArray< FString > &SearchPaths, TArray< FString > &ImportFileNames, TSet< FString > &VisitedImportNames)
static FProcHandle CreateProc(const TCHAR *URL, const TCHAR *Parms, bool bLaunchDetached, bool bLaunchHidden, bool bLaunchReallyHidden, uint32 *OutProcessID, int32 PriorityModifier, const TCHAR *OptionalWorkingDirectory, void *PipeWriteChild, void *PipeReadChild, void *PipeStdErrChild)
static bool IsFirstInstance()
static void SetupAudioThread()
static void * GetDllHandle(const TCHAR *Filename)
static void SetupGameThread()
static FSemaphore * NewInterprocessSynchObject(const TCHAR *Name, bool bCreate, uint32 MaxLocks=1)
static void SetThreadName(const TCHAR *ThreadName)
static bool GetApplicationMemoryUsage(uint32 ProcessId, SIZE_T *OutMemoryUsage)
static bool WritePipe(void *WritePipe, const FString &Message, FString *OutWritten=nullptr)
static const FString GetModulesDirectory()
static FSemaphore * NewInterprocessSynchObject(const FString &Name, bool bCreate, uint32 MaxLocks=1)
static bool ResolveImport(const FString &Name, const TArray< FString > &SearchPaths, FString &OutFileName)
static const FString ShaderWorkingDir()
static class FEvent * CreateSynchEvent(bool bIsManualReset=false)
static void CloseProc(FProcHandle &ProcessHandle)
static bool ResolveNetworkPath(FString InUNCPath, FString &OutPath)
static void LaunchURL(const TCHAR *URL, const TCHAR *Parms, FString *Error)
static TArray< FString > DllDirectories
static void ExploreFolder(const TCHAR *FilePath)