CommonLib
Loading...
Searching...
No Matches
this_process.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <vector>
5
6#include "diag/stack_frame.h"
7#include "ut/expr/string_expr.h"
8
9namespace hedgedev::csl::diag::this_process
10{
11 ///
12 /// Gets the command line arguments that were passed into this process at launch.
13 ///
14 template <ut::expr::any_string T>
15 inline std::vector<T> get_command_line();
16
17 ///
18 /// Gets the path to the executable this process started from.
19 ///
21
22 ///
23 /// Gets the path to the directory containing executable this process started from.
24 ///
26
27 ///
28 /// Gets the path to the module containing the specified address.
29 ///
30 /// \param in_address The address to search for.
31 ///
33
34 ///
35 /// Gets the working directory of this process.
36 ///
38
39 ///
40 /// Gets a stack trace.
41 ///
42 /// \param in_context A pointer to a CPU context structure.
43 /// \param in_max_frames The maximum number of stack frames to capture.
44 ///
45 /// \returns A collection of stack frames.
46 ///
47 inline std::vector<stack_frame> get_stack_trace(const void* in_context, const size_t in_max_frames = 0);
48
49 ///
50 /// Checks if this process is the owner of the specified address.
51 ///
52 /// \param in_address The address to search for.
53 ///
54 /// \returns `true` if the address is inside this process' memory.
55 /// Otherwise, `false`.
56 ///
57 inline bool has_address(const void* in_address);
58
59 ///
60 /// Checks if a path is in the same directory as the executable this process
61 /// started from.
62 ///
63 /// \param in_path The path to check.
64 ///
65 /// \returns `true` if both paths are in the same directory. Otherwise, `false`.
66 ///
67 inline bool is_neighbour(const std::filesystem::path& in_path);
68
69 ///
70 /// Restarts this process.
71 ///
72 /// \tparam T The string type for the arguments.
73 ///
74 /// \param in_args The command line arguments to pass into the new process.
75 ///
76 /// \returns `true` if this process was terminated successfully. Otherwise, `false`.
77 ///
78 template <ut::expr::any_string T>
79 inline bool restart(const std::vector<T>& in_args);
80
81 ///
82 /// Restarts this process.
83 ///
84 /// \returns `true` if this process was terminated successfully. Otherwise, `false`.
85 ///
86 inline bool restart();
87}
88
89#include "this_process.inl"
90
91#ifdef WIN32
92#include "os/this_process_win32.inl"
93#endif
Definition this_process_win32.inl:13
std::filesystem::path get_executable_root()
Definition this_process.inl:7
std::vector< T > get_command_line()
Definition this_process_win32.inl:15
bool is_neighbour(const std::filesystem::path &in_path)
Definition this_process.inl:12
bool restart(const std::vector< T > &in_args)
Definition this_process_win32.inl:175
std::filesystem::path get_working_directory()
Definition this_process_win32.inl:69
bool restart()
Definition this_process_win32.inl:182
std::vector< stack_frame > get_stack_trace(const void *in_context, const size_t in_max_frames)
Definition this_process_win32.inl:81
bool has_address(const void *in_address)
Definition this_process_win32.inl:157
std::filesystem::path get_module_path_from_address(const void *in_address)
Definition this_process_win32.inl:45
std::filesystem::path get_executable_path()
Definition this_process_win32.inl:33