-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configs for sandbox features, added TrapSite, began work on boo…
…tstrapping TrapSite dynamic constants.
- Loading branch information
1 parent
e00ed9b
commit 30875c7
Showing
6 changed files
with
298 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
package chipmunk.vm; | ||
|
||
import chipmunk.vm.jvm.TrapSite; | ||
|
||
public interface TrapHandler { | ||
|
||
default void runtimeTrap(Object payload){} | ||
|
||
// TODO - replace this verbosity with dynamically computed constants | ||
default void backJump(String cls, String method, int line){} | ||
default void methodCall(String cls, String method, int line, | ||
default void backJump(TrapSite site){} | ||
default void methodCall(TrapSite site, | ||
String targetCls, String targetMethodName, String targetMethodSignature){} | ||
|
||
default void recursiveCall(String cls, String method, int line){} | ||
|
||
default void arrayAlloc(String cls, String method, int line, int dimensions, int capacity){} | ||
default void arrayAlloc(TrapSite site, int dimensions, int capacity){} | ||
|
||
default void objectAlloc(String cls, String method, int line, String targetCls, String targetConstructorSignature){} | ||
default void objectAlloc(TrapSite site, String targetCls, String targetConstructorSignature){} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2023 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk 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 for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.vm.jvm; | ||
|
||
import chipmunk.vm.invoke.security.LinkingPolicy; | ||
|
||
public class SandboxContext { | ||
|
||
protected final String className; | ||
protected final String methodName; | ||
protected final String methodDescriptor; | ||
protected final LinkingPolicy policy; | ||
protected final TrapConfig trapConfig; | ||
|
||
public SandboxContext(String className, String methodName, String methodDescriptor, LinkingPolicy policy, TrapConfig trapConfig){ | ||
this.className = className; | ||
this.methodName = methodName; | ||
this.methodDescriptor = methodDescriptor; | ||
this.policy = policy; | ||
this.trapConfig = trapConfig; | ||
} | ||
|
||
public SandboxContext(String className, String methodName, String methodDescriptor, LinkingPolicy policy){ | ||
this(className, methodName, methodDescriptor, policy, new TrapConfig()); | ||
} | ||
|
||
public String getClassName(){ | ||
return className; | ||
} | ||
|
||
public String getMethodName(){ | ||
return methodName; | ||
} | ||
|
||
public String getMethodDescriptor(){ | ||
return methodDescriptor; | ||
} | ||
|
||
public LinkingPolicy getLinkingPolicy(){ | ||
return policy; | ||
} | ||
|
||
public TrapConfig getTrapConfig(){ | ||
return trapConfig; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2023 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk 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 for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.vm.jvm; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class TrapConfig { | ||
|
||
protected final Set<TrapFlag> enabledTraps; | ||
|
||
public TrapConfig(){ | ||
enabledTraps = new HashSet<>(); | ||
} | ||
|
||
public void enable(TrapFlag flag){ | ||
enabledTraps.add(flag); | ||
} | ||
|
||
public boolean isEnabled(TrapFlag... flags){ | ||
return Arrays.stream(flags).anyMatch(enabledTraps::contains); | ||
} | ||
|
||
public void disable(TrapFlag flag){ | ||
enabledTraps.remove(flag); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2023 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk 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 for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.vm.jvm; | ||
|
||
public enum TrapFlag { | ||
BACK_JUMP, | ||
METHOD_CALL, | ||
PRE_METHOD_CALL, | ||
POST_METHOD_CALL, | ||
ARRAY_ALLOC, | ||
PRE_ARRAY_ALLOC, | ||
POST_ARRAY_ALLOC, | ||
OBJECT_ALLOC, | ||
PRE_OBJECT_ALLOC, | ||
POST_OBJECT_ALLOC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2023 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk 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 for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.vm.jvm; | ||
|
||
public record TrapSite(Position position, String className, String methodName, Class<?>[] signature, int lineNumber) { | ||
|
||
public enum Position { | ||
PRE, POST | ||
} | ||
|
||
} |