Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/dfix/dfix.c
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2014 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
#if defined(WIN32) || defined (WIN64)
23
#include <windows.h>
24
#endif
25
26
#include "j9.h"
27
#include "dfix.h"
28
#include "dfix_internal.h"
29
#include "ut_j9dfix.h"
30
31
void
32
fixup(void* returnAddress, void* resolved)
33
{
34
U_8* callsite = ((U_8*)returnAddress) - 5;
35
IDATA oldDisplacement, newDisplacement, *displacementPtr;
36
DWORD oldProtectionBits = 0;
37
BOOL rcProtect = FALSE;
38
39
/* Mark the code pages read/write */
40
rcProtect = VirtualProtect(callsite, 5, PAGE_EXECUTE_READWRITE, &oldProtectionBits);
41
if (!rcProtect) {
42
Assert_DFIX_FixupFailed();
43
return;
44
}
45
46
/**
47
On x86 the instruction looks like:
48
00c01454 e847ffffff call dfixtest!zero_memory (00c013a0)
49
00c01459 83c408 add esp, <-- returnAddress points here
50
*/
51
52
displacementPtr = (IDATA*)(callsite+1);
53
oldDisplacement = *displacementPtr;
54
newDisplacement = ((U_8*)resolved) - callsite - 5 /* instructions in this sequence*/ ;
55
*displacementPtr = newDisplacement;
56
57
/* Restore the original protection bits */
58
rcProtect = VirtualProtect(callsite, 5, oldProtectionBits, &oldProtectionBits);
59
if (!rcProtect) {
60
Assert_DFIX_FixupFailed();
61
return;
62
}
63
64
printf(
65
"fixup(returnAddress=0x%p, callsite=0x%p (opcode=%x) resolved=0x%p)\n",
66
returnAddress, callsite, *callsite, resolved);
67
68
}
69
70
#if defined(WIN32) || defined (WIN64)
71
BOOL WINAPI
72
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
73
{
74
if (DLL_PROCESS_ATTACH == fdwReason) {
75
if (!resolve_dfix_zero_memory()) {
76
return FALSE;
77
}
78
if (!resolve_dfix_memcpy()) {
79
return FALSE;
80
}
81
}
82
return TRUE;
83
}
84
#endif
85
86
87