Skip to content

Commit c6994fc

Browse files
Mike GrierEmJayGee
authored andcommitted
Add monitoring for registry changes
1 parent 19cdee4 commit c6994fc

File tree

118 files changed

+5181
-1141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+5181
-1141
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mono_crash.*
2323
[Rr]eleases/
2424
x64/
2525
x86/
26-
[Ww][Ii][Nn]32/
26+
# [Ww][Ii][Nn]32/
2727
[Aa][Rr][Mm]/
2828
[Aa][Rr][Mm]64/
2929
bld/

src/Linux/libraries/linux_strings/include/m/linux_strings/convert.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <m/utf/encode.h>
1717
#include <m/utf/transcode.h>
1818
#include <m/utility/make_span.h>
19+
#include <m/utility/pointers.h>
1920

2021
namespace m
2122
{
@@ -139,6 +140,21 @@ namespace m
139140
return str;
140141
}
141142

143+
constexpr std::optional<std::wstring>
144+
to_wstring(char16_t const* ptr)
145+
{
146+
if (ptr != nullptr)
147+
return to_wstring(std::u16string_view(ptr));
148+
149+
return std::nullopt;
150+
}
151+
152+
constexpr std::wstring
153+
to_wstring(m::not_null<char16_t const*> ptr)
154+
{
155+
return to_wstring(std::u16string_view(ptr));
156+
}
157+
142158
constexpr void
143159
to_wstring(std::u32string_view view, std::wstring& str)
144160
{

src/Windows/libraries/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.23)
33
add_subdirectory(errors)
44
add_subdirectory(formatters)
55
add_subdirectory(multi_byte)
6+
add_subdirectory(win32)
67
add_subdirectory(windows_strings)
78
add_subdirectory(windows_wrappers)
89

src/Windows/libraries/multi_byte/include/m/multi_byte/convert_wchar.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string_view>
99

1010
#include <m/utf/transcode.h>
11+
#include <m/utility/pointers.h>
1112

1213
#include "convert.h"
1314

@@ -73,6 +74,21 @@ namespace m
7374
utf::transcode(std::u8string_view{s}, str);
7475
}
7576

77+
constexpr std::wstring
78+
to_wstring(m::not_null<char8_t const*> ptr)
79+
{
80+
return to_wstring(std::u8string_view(ptr));
81+
}
82+
83+
constexpr std::optional<std::wstring>
84+
to_wstring(char8_t const* ptr)
85+
{
86+
if (ptr)
87+
return to_wstring(m::not_null<char8_t const*>(ptr));
88+
89+
return std::nullopt;
90+
}
91+
7692
constexpr std::wstring
7793
to_wstring(std::u16string_view v)
7894
{
@@ -127,6 +143,21 @@ namespace m
127143
utf::transcode(std::u16string_view{s}, str);
128144
}
129145

146+
constexpr std::wstring
147+
to_wstring(m::not_null<char16_t const*> ptr)
148+
{
149+
return to_wstring(std::u16string_view(ptr));
150+
}
151+
152+
constexpr std::optional<std::wstring>
153+
to_wstring(char16_t const* ptr)
154+
{
155+
if (ptr)
156+
return to_wstring(m::not_null<char16_t const*>(ptr));
157+
158+
return std::nullopt;
159+
}
160+
130161
constexpr std::wstring
131162
to_wstring(std::u32string_view v)
132163
{
@@ -181,6 +212,21 @@ namespace m
181212
utf::transcode(std::u32string_view{s}, str);
182213
}
183214

215+
constexpr std::wstring
216+
to_wstring(m::not_null<char32_t const*> ptr)
217+
{
218+
return to_wstring(std::u32string_view(ptr));
219+
}
220+
221+
constexpr std::optional<std::wstring>
222+
to_wstring(char32_t const* ptr)
223+
{
224+
if (ptr)
225+
return to_wstring(m::not_null<char32_t const*>(ptr));
226+
227+
return std::nullopt;
228+
}
229+
184230
constexpr void
185231
to_u8string(std::wstring_view v, std::u8string& str)
186232
{
@@ -195,6 +241,21 @@ namespace m
195241
return str;
196242
}
197243

244+
constexpr std::u8string
245+
to_u8string(m::not_null<wchar_t const*> ptr)
246+
{
247+
return to_u8string(std::wstring_view(ptr));
248+
}
249+
250+
constexpr std::optional<std::u8string>
251+
to_u8string(wchar_t const* ptr)
252+
{
253+
if (ptr)
254+
return to_u8string(m::not_null<wchar_t const*>(ptr));
255+
256+
return std::nullopt;
257+
}
258+
198259
constexpr void
199260
to_u16string(std::wstring_view v, std::u16string& str)
200261
{
@@ -209,6 +270,21 @@ namespace m
209270
return str;
210271
}
211272

273+
constexpr std::u16string
274+
to_u16string(m::not_null<wchar_t const*> ptr)
275+
{
276+
return to_u16string(std::wstring_view(ptr));
277+
}
278+
279+
constexpr std::optional<std::u16string>
280+
to_u16string(wchar_t const* ptr)
281+
{
282+
if (ptr)
283+
return to_u16string(m::not_null<wchar_t const*>(ptr));
284+
285+
return std::nullopt;
286+
}
287+
212288
//
213289
// to_u32string
214290
//
@@ -226,4 +302,19 @@ namespace m
226302
return str;
227303
}
228304

305+
constexpr std::u32string
306+
to_u32string(m::not_null<wchar_t const*> ptr)
307+
{
308+
return to_u32string(std::wstring_view(ptr));
309+
}
310+
311+
constexpr std::optional<std::u32string>
312+
to_u32string(wchar_t const* ptr)
313+
{
314+
if (ptr)
315+
return to_u32string(m::not_null<wchar_t const*>(ptr));
316+
317+
return std::nullopt;
318+
}
319+
229320
} // namespace m
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.23)
2+
3+
add_library(m_win32 STATIC)
4+
5+
target_compile_features(m_win32 PUBLIC ${M_CXX_STD})
6+
7+
add_subdirectory(include)
8+
add_subdirectory(src)
9+
add_subdirectory(test)
10+
11+
list(APPEND m_installation_targets
12+
m_win32
13+
)
14+
15+
set(m_installation_targets ${m_installation_targets} PARENT_SCOPE)

src/Windows/libraries/win32/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# What is m/src/Windows/libraries/wrappers?
2+
3+
The Win32 API has a lot of cases of use of primitive types like a DWORD which
4+
is a simple typedef / type alias of a 32 bit unsigned integer (whose type
5+
varies between platforms! oh my!) where in some contexts is it a holder of
6+
a certain set of bit flags, in another it is a millisecond count, and in
7+
another it is an error code with a specific range.
8+
9+
The wrappers here are _intended_ to be very simple wrapper types that give
10+
some type-wise uniqueness around these primitive types so that they can be
11+
used in overloads and their use in parameter lists is "self documenting"
12+
to some degree.
13+
14+
This is not _intended_ to be the beginning of yet another HANDLE-with-
15+
automatic-CloseHandle-semantics set of classes or such. These are useful
16+
and necessary. There is a set of these provided by the `wil` library, the
17+
Windows Implementation Library, freely and publicly available. `wil` has
18+
its ups and downs and trying to "compete" with it is well outside the
19+
scope of anything I would want to do here with "m".
20+
21+
"m" is intended to move C++ forward, indeally in the context of Windows as
22+
well as other platforms, not move Windows forward in the context of C++.
23+
24+
Unfortunately, it has proven difficult to compose `wil` with "m", so I have
25+
found myself building RAII classes that overlap but they are not part of
26+
the public API surface area of "m" and they are not intended to be for the
27+
foreseeable future.
28+
29+
These types however, are innocuous structs around DWORDs and the like,
30+
just with explicit conversions in and out.
31+
32+
The C++ Guidelines recommend use of a scoped enumeration for these sorts
33+
of things. The problem with scoped enumerations is that you cannot add
34+
some of the operators to them so my default stance is a struct with
35+
explicit constructor and explicit operator T to convert in and out
36+
which should get the basic type safety.
37+
38+
Thus, the default "wrapper" for, for example, a DWORD type might look like:
39+
40+
```
41+
struct dword_for_ms
42+
{
43+
dword_for_ms() = default;
44+
constexpr explicit dword_for_ms(DWORD v) noexcept : m_v(v) {}
45+
constexpr dword_for_ms(dword_for_ms const& other) noexcept : m_v(other.m_v) {}
46+
constexpr dword_for_ms(dword_for_ms&& other) noexcept : m_v(other.m_v) {}
47+
~dword_for_ms() = default;
48+
49+
constexpr dword_for_ms& operator=(dword_for_ms const& other) noexcept { m_v = other.m_v; return *this; }
50+
constexpr dword_for_ms& operator=(dword_for_ms&& other) noexcept { m_v = other.m_v; return *this; }
51+
52+
constexpr void swap(dword_for_ms& other) noexcept {
53+
using std::swap;
54+
swap(m_v, other.m_v);
55+
}
56+
57+
explicit constexpr operator DWORD() const { return m_v; }
58+
constexpr bool operator==(dword_for_ms other) const { return m_v == other.m_v; }
59+
60+
constexpr auto operator<=>(dword_for_ms other) const { return operator<=>(m_v, other.m_v); }
61+
62+
DWORD m_v;
63+
};
64+
```
65+
66+
Language experts can probably hone this to what really has to be implemented,
67+
for example, perhaps the move constructor should _not_ be implemented.
68+
69+
Also note that this is prime real estate for a template.
70+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.23)
2+
3+
target_sources(m_win32 PUBLIC FILE_SET HEADERS FILES
4+
m/win32/handle.h
5+
m/win32/registry.h
6+
m/win32/threadpool.h
7+
)
8+
9+
set(m_installation_targets ${m_installation_targets} PARENT_SCOPE)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
3+
#pragma once
4+
5+
#include <system_error>
6+
#include <utility>
7+
8+
#include <m/utility/enum_operations.h.h>
9+
#include <m/win32/handle.h>
10+
11+
#undef NOMINMAX
12+
#define NOMINMAX
13+
14+
#include <Windows.h>
15+
16+
namespace m::win32
17+
{
18+
enum class create_event_flags : uint32_t
19+
{
20+
initial_set = 0x00000002, // CREATE_EVENT_INITIAL_SET
21+
manual_reset = 0x00000001, // CREATE_EVENT_MANUAL_RESET
22+
};
23+
24+
M_DEFINE_SCOPED_ENUM_BITFLAG_OPS(create_event_flags);
25+
26+
class event : protected handle
27+
{
28+
using base_type = handle;
29+
30+
public:
31+
event() = default;
32+
33+
enum class event_kind
34+
{
35+
automatic,
36+
manual,
37+
};
38+
39+
event(create_event_flags flags, DWORD desired_access = SYNCHRONIZE | EVENT_MODIFY_STATE);
40+
41+
event(event_kind kind, DWORD desired_access = SYNCHRONIZE | EVENT_MODIFY_STATE);
42+
43+
constexpr event(HANDLE hdl, event_kind kind) noexcept: base_type(hdl), m_event_kind(kind) {}
44+
45+
constexpr event(event&& other) noexcept: m_event_kind{}
46+
{
47+
using std::swap;
48+
swap(m_event_kind, other.m_event_kind);
49+
swap(m_handle, other.m_handle);
50+
}
51+
52+
event(event const& other) = delete;
53+
54+
constexpr event&
55+
operator=(event&& other) noexcept
56+
{
57+
using std::swap;
58+
swap(m_handle, other.m_handle);
59+
return *this;
60+
}
61+
62+
event&
63+
operator=(event const&) = delete;
64+
65+
~event() = default;
66+
67+
constexpr void
68+
swap(event& other) noexcept
69+
{
70+
using std::swap;
71+
72+
swap(m_handle, other.m_handle);
73+
}
74+
75+
using base_type::addressof;
76+
using base_type::get;
77+
using base_type::handle;
78+
using base_type::is_valid;
79+
using base_type::reset;
80+
81+
void
82+
create(create_event_flags flags, DWORD desired_access = SYNCHRONIZE | EVENT_MODIFY_STATE);
83+
84+
[[nodiscard]] std::error_code
85+
createq(create_event_flags flags, DWORD desired_access = SYNCHRONIZE | EVENT_MODIFY_STATE);
86+
87+
enum class event_state
88+
{
89+
reset,
90+
set,
91+
};
92+
93+
void
94+
set_event_state(event_state state);
95+
96+
private:
97+
event_kind m_event_kind;
98+
};
99+
100+
} // namespace m::win32

0 commit comments

Comments
 (0)