Skip to content

Commit

Permalink
Add runtime pagesize validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
teshull committed Dec 13, 2022
1 parent 3880bff commit 409c4d5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.oracle.svm.core.jdk.InternalVMMethod;
import com.oracle.svm.core.jdk.RuntimeSupport;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.os.VirtualMemoryProvider;
import com.oracle.svm.core.sampler.ProfilingSampler;
import com.oracle.svm.core.thread.JavaThreads;
import com.oracle.svm.core.thread.PlatformThreads;
Expand Down Expand Up @@ -218,11 +219,19 @@ public static int run(int argc, CCharPointerPointer argv) {
}
}

private static final CGlobalData<CCharPointer> PAGE_SIZE_CHECK_FAIL_MESSAGE = CGlobalDataFactory
.createCString("Image page size does not match the page size at run-time. Use -H:PageSize=[pagesize] to set appropriately.");

@Uninterruptible(reason = "Thread state not setup yet.")
private static int doRun(int argc, CCharPointerPointer argv) {
try {
CPUFeatureAccess cpuFeatureAccess = ImageSingletons.lookup(CPUFeatureAccess.class);
cpuFeatureAccess.verifyHostSupportsArchitectureEarlyOrExit();
if (VirtualMemoryProvider.get().getGranularity().notEqual(SubstrateOptions.getPageSize())) {
CEntryPointActions.failFatally(CEntryPointErrors.PAGE_SIZE_CHECK_FAILED, PAGE_SIZE_CHECK_FAIL_MESSAGE.get());
return 1;
}

// Create the isolate and attach the current C thread as the main Java thread.
EnterCreateIsolateWithCArgumentsPrologue.enter(argc, argv);
assert !VMThreads.wasStartedByCurrentIsolate(CurrentIsolate.getCurrentThread()) : "re-attach would cause issues otherwise";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ public ReportingSupport(String reportingPath) {
@Option(help = "Define PageSize of a machine that runs the image. The default = 0 (== same as host machine page size)")//
protected static final HostedOptionKey<Integer> PageSize = new HostedOptionKey<>(0);

@Fold
public static int getPageSize() {
int value = PageSize.getValue();
if (value == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ private CEntryPointErrors() {
@Description("Current target does not support the following CPU features that are required by the image.") //
public static final int CPU_FEATURE_CHECK_FAILED = 23;

@Description("Image page size does not match the page size at run-time.") //
public static final int PAGE_SIZE_CHECK_FAILED = 24;

public static String getDescription(int code) {
String result = null;
if (code >= 0 && code < DESCRIPTIONS.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.option.RuntimeOptionParser;
import com.oracle.svm.core.os.MemoryProtectionProvider;
import com.oracle.svm.core.os.VirtualMemoryProvider;
import com.oracle.svm.core.snippets.SnippetRuntime;
import com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor;
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
Expand Down Expand Up @@ -205,6 +206,9 @@ private static int createIsolate(CEntryPointCreateIsolateParameters parameters,
if (cpuFeatureAccess.verifyHostSupportsArchitectureEarly() != 0) {
return CEntryPointErrors.CPU_FEATURE_CHECK_FAILED;
}
if (VirtualMemoryProvider.get().getGranularity().notEqual(SubstrateOptions.getPageSize())) {
return CEntryPointErrors.PAGE_SIZE_CHECK_FAILED;
}
CLongPointer parsedArgs = StackValue.get(IsolateArgumentParser.getStructSize());
IsolateArgumentParser.parse(parameters, parsedArgs);

Expand Down

0 comments on commit 409c4d5

Please sign in to comment.