Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os/windows/gc/z/zSyscall_windows.cpp
40948 views
1
/*
2
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
#include "precompiled.hpp"
25
#include "gc/shared/gcLogPrecious.hpp"
26
#include "gc/z/zSyscall_windows.hpp"
27
#include "runtime/java.hpp"
28
#include "runtime/os.hpp"
29
30
ZSyscall::CreateFileMappingWFn ZSyscall::CreateFileMappingW;
31
ZSyscall::CreateFileMapping2Fn ZSyscall::CreateFileMapping2;
32
ZSyscall::VirtualAlloc2Fn ZSyscall::VirtualAlloc2;
33
ZSyscall::VirtualFreeExFn ZSyscall::VirtualFreeEx;
34
ZSyscall::MapViewOfFile3Fn ZSyscall::MapViewOfFile3;
35
ZSyscall::UnmapViewOfFile2Fn ZSyscall::UnmapViewOfFile2;
36
37
static void* lookup_kernelbase_library() {
38
const char* const name = "KernelBase";
39
char ebuf[1024];
40
void* const handle = os::dll_load(name, ebuf, sizeof(ebuf));
41
if (handle == NULL) {
42
log_error_p(gc)("Failed to load library: %s", name);
43
}
44
return handle;
45
}
46
47
static void* lookup_kernelbase_symbol(const char* name) {
48
static void* const handle = lookup_kernelbase_library();
49
if (handle == NULL) {
50
return NULL;
51
}
52
return os::dll_lookup(handle, name);
53
}
54
55
static bool has_kernelbase_symbol(const char* name) {
56
return lookup_kernelbase_symbol(name) != NULL;
57
}
58
59
template <typename Fn>
60
static void install_kernelbase_symbol(Fn*& fn, const char* name) {
61
fn = reinterpret_cast<Fn*>(lookup_kernelbase_symbol(name));
62
}
63
64
template <typename Fn>
65
static void install_kernelbase_1803_symbol_or_exit(Fn*& fn, const char* name) {
66
install_kernelbase_symbol(fn, name);
67
if (fn == NULL) {
68
log_error_p(gc)("Failed to lookup symbol: %s", name);
69
vm_exit_during_initialization("ZGC requires Windows version 1803 or later");
70
}
71
}
72
73
void ZSyscall::initialize() {
74
// Required
75
install_kernelbase_1803_symbol_or_exit(CreateFileMappingW, "CreateFileMappingW");
76
install_kernelbase_1803_symbol_or_exit(VirtualAlloc2, "VirtualAlloc2");
77
install_kernelbase_1803_symbol_or_exit(VirtualFreeEx, "VirtualFreeEx");
78
install_kernelbase_1803_symbol_or_exit(MapViewOfFile3, "MapViewOfFile3");
79
install_kernelbase_1803_symbol_or_exit(UnmapViewOfFile2, "UnmapViewOfFile2");
80
81
// Optional - for large pages support
82
install_kernelbase_symbol(CreateFileMapping2, "CreateFileMapping2");
83
}
84
85
bool ZSyscall::is_supported() {
86
// Available in Windows version 1803 and later
87
return has_kernelbase_symbol("VirtualAlloc2");
88
}
89
90
bool ZSyscall::is_large_pages_supported() {
91
// Available in Windows version 1809 and later
92
return has_kernelbase_symbol("CreateFileMapping2");
93
}
94
95