1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright Epic Games, Inc. All Rights Reserved.
#include "zencore/zencore.h"
#if ZEN_PLATFORM_WINDOWS
# include <zencore/except.h>
# include "zencore/windows.h"
namespace zen::windows {
bool
IsRunningOnWine()
{
HMODULE NtDll = GetModuleHandleA("ntdll.dll");
if (NtDll)
{
return !!GetProcAddress(NtDll, "wine_get_version");
}
return false;
}
FileMapping::FileMapping(_In_ FileMapping& orig)
{
m_pData = NULL;
m_hMapping = NULL;
HRESULT hr = CopyFrom(orig);
if (FAILED(hr))
zen::ThrowSystemException(hr, "Failed to clone FileMapping");
}
FileMapping&
FileMapping::operator=(_In_ FileMapping& orig)
{
HRESULT hr = CopyFrom(orig);
if (FAILED(hr))
zen::ThrowSystemException(hr, "Failed to clone FileMapping");
return *this;
}
HRESULT
FileMapping::CopyFrom(_In_ FileMapping& orig) throw()
{
if (this == &orig)
return S_OK;
ZEN_ASSERT(m_pData == NULL);
ZEN_ASSERT(m_hMapping == NULL);
ZEN_ASSERT(orig.m_pData != NULL);
m_dwViewDesiredAccess = orig.m_dwViewDesiredAccess;
m_nOffset.QuadPart = orig.m_nOffset.QuadPart;
m_nMappingSize = orig.m_nMappingSize;
if (!::DuplicateHandle(GetCurrentProcess(), orig.m_hMapping, GetCurrentProcess(), &m_hMapping, NULL, TRUE, DUPLICATE_SAME_ACCESS))
return MapHresultFromLastError();
m_pData = ::MapViewOfFileEx(m_hMapping, m_dwViewDesiredAccess, m_nOffset.HighPart, m_nOffset.LowPart, m_nMappingSize, NULL);
if (m_pData == NULL)
{
HRESULT hr;
hr = MapHresultFromLastError();
::CloseHandle(m_hMapping);
m_hMapping = NULL;
return hr;
}
return S_OK;
}
} // namespace zen::windows
#endif
|