Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
"subDir": "src",
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.core.graal.amd64",
"com.oracle.svm.hosted",
"com.oracle.svm.core.graal.aarch64",
"com.oracle.svm.core.graal.riscv64",
],
Expand Down Expand Up @@ -511,7 +511,7 @@
"subDir": "src",
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.core.graal.amd64",
"com.oracle.svm.hosted",
],
"requiresConcealed" : {
"jdk.internal.vm.ci" : [
Expand Down Expand Up @@ -639,8 +639,8 @@
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.objectfile",
"com.oracle.svm.core",
"com.oracle.graal.reachability"
"com.oracle.graal.reachability",
"com.oracle.svm.core.graal.amd64",
],
"requires" : [
"jdk.jfr",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
import com.oracle.svm.core.meta.SubstrateObjectConstant;
import com.oracle.svm.core.nodes.SafepointCheckNode;
import com.oracle.svm.core.pltgot.PLTGOTConfiguration;
import com.oracle.svm.core.thread.VMThreads.StatusSupport;
import com.oracle.svm.core.util.VMError;

Expand Down Expand Up @@ -667,6 +668,14 @@ public Register getHeapBaseRegister() {
protected int getVMPageSize() {
return SubstrateOptions.getPageSize();
}

@Override
public void emitExitMethodAddressResolution(Value ip) {
PLTGOTConfiguration configuration = PLTGOTConfiguration.singleton();
RegisterValue exitThroughRegisterValue = configuration.getExitMethodAddressResolutionRegister(getRegisterConfig()).asValue(ip.getValueKind());
emitMove(exitThroughRegisterValue, ip);
append(configuration.createExitMethodAddressResolutionOp(exitThroughRegisterValue));
}
}

public class SubstrateAArch64NodeLIRBuilder extends AArch64NodeLIRBuilder implements SubstrateNodeLIRBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
import com.oracle.svm.core.meta.SubstrateObjectConstant;
import com.oracle.svm.core.nodes.SafepointCheckNode;
import com.oracle.svm.core.pltgot.PLTGOTConfiguration;
import com.oracle.svm.core.thread.VMThreads.StatusSupport;
import com.oracle.svm.core.util.VMError;

Expand Down Expand Up @@ -748,6 +749,14 @@ public void emitInstructionSynchronizationBarrier() {
throw shouldNotReachHere("AMD64 does not need instruction synchronization");
}

@Override
public void emitExitMethodAddressResolution(Value ip) {
PLTGOTConfiguration configuration = PLTGOTConfiguration.singleton();
RegisterValue exitThroughRegisterValue = configuration.getExitMethodAddressResolutionRegister(getRegisterConfig()).asValue(ip.getValueKind());
emitMove(exitThroughRegisterValue, ip);
append(configuration.createExitMethodAddressResolutionOp(exitThroughRegisterValue));
}

@Override
public void emitFarReturn(AllocatableValue result, Value sp, Value ip, boolean fromMethodWithCalleeSavedRegisters) {
append(new AMD64FarReturnOp(result, asAllocatable(sp), asAllocatable(ip), fromMethodWithCalleeSavedRegisters));
Expand Down Expand Up @@ -1813,7 +1822,7 @@ public void emitCode(CompilationResultBuilder crb, ResolvedJavaMethod installedC
}
}

private AMD64Assembler createAssemblerNoOptions() {
public AMD64Assembler createAssemblerNoOptions() {
OptionValues o = new OptionValues(EconomicMap.create());
return createAssembler(o);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,11 @@ public void emitInstructionSynchronizationBarrier() {
throw unimplemented("the LLVM backend doesn't support instruction synchronization"); // ExcludeFromJacocoGeneratedReport
}

@Override
public void emitExitMethodAddressResolution(Value ip) {
throw unimplemented("the LLVM backend doesn't support PLT/GOT"); // ExcludeFromJacocoGeneratedReport
}

@Override
public <I extends LIRInstruction> I append(I op) {
throw unimplemented("the LLVM backend doesn't support LIR instructions"); // ExcludeFromJacocoGeneratedReport
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.posix.darwin;

import static com.oracle.svm.core.posix.headers.Mman.MAP_ANON;
import static com.oracle.svm.core.posix.headers.Mman.MAP_FAILED;
import static com.oracle.svm.core.posix.headers.Mman.MAP_PRIVATE;
import static com.oracle.svm.core.posix.headers.Mman.PROT_READ;
import static com.oracle.svm.core.posix.headers.Mman.PROT_WRITE;
import static com.oracle.svm.core.posix.headers.Mman.NoTransitions.mmap;

import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.c.type.CIntPointer;
import org.graalvm.nativeimage.c.type.WordPointer;
import org.graalvm.word.Pointer;
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.c.CGlobalData;
import com.oracle.svm.core.c.CGlobalDataFactory;
import com.oracle.svm.core.c.function.CEntryPointErrors;
import com.oracle.svm.core.headers.LibC;
import com.oracle.svm.core.os.VirtualMemoryProvider;
import com.oracle.svm.core.os.VirtualMemoryProvider.Access;
import com.oracle.svm.core.pltgot.GOTHeapSupport;
import com.oracle.svm.core.posix.headers.darwin.DarwinVirtualMemory;

public class DarwinGOTHeapSupport extends GOTHeapSupport {

private static final CGlobalData<WordPointer> DARWIN_GOT_START_ADDRESS = CGlobalDataFactory.createWord();

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
protected int initialize(WordPointer gotStartAddress) {
int flags = MAP_ANON() | MAP_PRIVATE();
Pointer gotMemory = mmap(WordFactory.nullPointer(), getPageAlignedGotSize(), PROT_READ() | PROT_WRITE(), flags, -1, 0);
if (gotMemory.isNull() || gotMemory.equal(MAP_FAILED())) {
return CEntryPointErrors.DYNAMIC_METHOD_ADDRESS_RESOLUTION_GOT_FD_CREATE_FAILED;
}

Pointer gotStartInMemory = gotMemory.add(getGotOffsetFromStartOfMapping());
LibC.memcpy(gotStartInMemory, IMAGE_GOT_BEGIN.get(), getGotSectionSize());

gotStartAddress.write(gotMemory);
DARWIN_GOT_START_ADDRESS.get().write(gotMemory);

return CEntryPointErrors.NO_ERROR;
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public int mapGot(Pointer start) {
WordPointer taskSelf = DarwinVirtualMemory.mach_task_self();

/* Unmap part of the heap address space that is designated for the GOT */
int ret = DarwinVirtualMemory.vm_deallocate(DarwinVirtualMemory.mach_task_self(), start, getPageAlignedGotSize());
if (ret != 0) {
return CEntryPointErrors.DYNAMIC_METHOD_ADDRESS_RESOLUTION_GOT_MMAP_FAILED;
}

WordPointer gotStart = StackValue.get(WordPointer.class);
gotStart.write(start);

CIntPointer currentProt = StackValue.get(CIntPointer.class);
CIntPointer maxProt = StackValue.get(CIntPointer.class);

int intFalse = 0;

/*
* Map reserved address space for GOT to "global" GOT allocation, so that all isolates are
* backed by the same table.
*/
ret = DarwinVirtualMemory.vm_remap(taskSelf, gotStart, getPageAlignedGotSize(), WordFactory.nullPointer(), intFalse,
taskSelf, DARWIN_GOT_START_ADDRESS.get().read(), intFalse, currentProt, maxProt, DarwinVirtualMemory.VM_INHERIT_SHARE());
if (ret != 0) {
return CEntryPointErrors.DYNAMIC_METHOD_ADDRESS_RESOLUTION_GOT_WRONG_MMAP;
}

/*
* The new mapping "inherits" cur_prot and max_prot from the original mapping, but another
* isolate could race trying to write the original GOT => the new mapping could inherit
* cur_prot=RW. Ensure that the new-mapping remains read-only, regardless of races.
*/
if (currentProt.read() != PROT_READ()) {
ret = VirtualMemoryProvider.get().protect(start, getPageAlignedGotSize(), Access.READ);
if (ret != 0) {
return ret;
}
}

return CEntryPointErrors.NO_ERROR;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.posix.darwin;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;

import com.oracle.svm.core.code.DynamicMethodAddressResolutionHeapSupport;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.hosted.pltgot.PLTGOTOptions;

@AutomaticallyRegisteredFeature
public class DarwinPLTGOTFeature implements InternalFeature {

@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return Platform.includedIn(Platform.DARWIN.class) && PLTGOTOptions.EnablePLTGOT.getValue();
}

@Override
public void afterRegistration(AfterRegistrationAccess access) {
ImageSingletons.add(DynamicMethodAddressResolutionHeapSupport.class, new DarwinGOTHeapSupport());
}
}
Loading