Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os/posix/gc/z/zVirtualMemory_posix.cpp
40948 views
1
/*
2
* Copyright (c) 2015, 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/z/zAddress.inline.hpp"
26
#include "gc/z/zVirtualMemory.hpp"
27
#include "logging/log.hpp"
28
29
#include <sys/mman.h>
30
#include <sys/types.h>
31
32
void ZVirtualMemoryManager::pd_initialize_before_reserve() {
33
// Does nothing
34
}
35
36
void ZVirtualMemoryManager::pd_initialize_after_reserve() {
37
// Does nothing
38
}
39
40
bool ZVirtualMemoryManager::pd_reserve(uintptr_t addr, size_t size) {
41
const uintptr_t res = (uintptr_t)mmap((void*)addr, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
42
if (res == (uintptr_t)MAP_FAILED) {
43
// Failed to reserve memory
44
return false;
45
}
46
47
if (res != addr) {
48
// Failed to reserve memory at the requested address
49
munmap((void*)res, size);
50
return false;
51
}
52
53
// Success
54
return true;
55
}
56
57
void ZVirtualMemoryManager::pd_unreserve(uintptr_t addr, size_t size) {
58
const int res = munmap((void*)addr, size);
59
assert(res == 0, "Failed to unmap memory");
60
}
61
62