Commit 0c68c435 authored by Kunshan Wang's avatar Kunshan Wang

Implement uPtrHack as an option

This will allow mu-client-pypy to use this hack in the master branch by
setting the --uPtrHack=true VM option.
parent 7d36baaf
...@@ -210,6 +210,11 @@ globalSize must be a multiple of 32768 bytes (32K).* ...@@ -210,6 +210,11 @@ globalSize must be a multiple of 32768 bytes (32K).*
any extra libraries. any extra libraries.
- **bootImg**: The path to the boot image. Only useful in the C API. By default, - **bootImg**: The path to the boot image. Only useful in the C API. By default,
it does not load any boot image. it does not load any boot image.
- **uPtrHack**: When true, it will allow memory locations of general reference
types to be accessed by `uptr<T>`. By default, such fields can only be
accessed by `iref<T>`, but this hack is necessary for the current
[mu-client-pypy](https://gitlab.anu.edu.au/mu/mu-client-pypy/) project to
work. default: false
*Log levels can be: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF. Case-insensitive. *Log levels can be: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF. Case-insensitive.
Setting to WARN should get rid of most logging information, except the serious Setting to WARN should get rid of most logging information, except the serious
......
...@@ -95,6 +95,18 @@ class MicroVM private (val vmConf: VMConf, val allArgs: Option[Seq[String]]) ext ...@@ -95,6 +95,18 @@ class MicroVM private (val vmConf: VMConf, val allArgs: Option[Seq[String]]) ext
} }
} }
/**
* A hack that allows general reference types to be accessed by pointers.
* <p>
* By default (true), memory locations of general reference types can only be accessed via iref.
* This enforcement can be disabled as a workaround for the current mu-client-pypy project.
*/
val enforceRefTypeNoPointerAccess = !vmConf.uPtrHack
if (!enforceRefTypeNoPointerAccess) {
MicroVM.logger.warn("Allowing memory locations of general reference types to be accessed by uptr.")
}
val memoryManager = new MemoryManager(vmConf) val memoryManager = new MemoryManager(vmConf)
private implicit val memorySupport = memoryManager.memorySupport private implicit val memorySupport = memoryManager.memorySupport
......
...@@ -136,6 +136,12 @@ Each is passed to the dlsym function.""", ...@@ -136,6 +136,12 @@ Each is passed to the dlsym function.""",
desc = """The log level of the garbage collector. Can be ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF""", desc = """The log level of the garbage collector. Can be ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF""",
parser = identity, parser = identity,
default = "ERROR") default = "ERROR")
val uPtrHack = opt[Boolean](
name = "uPtrHack",
desc = """Allow memory locations of general reference types to be accessed by uptr""",
parser = parseBoolean,
default = false)
} }
object VMConf { object VMConf {
...@@ -171,7 +177,8 @@ object VMConf { ...@@ -171,7 +177,8 @@ object VMConf {
sourceInfo = VMConfParser.sourceInfo(kvMap), sourceInfo = VMConfParser.sourceInfo(kvMap),
automagicReloc = VMConfParser.automagicReloc(kvMap), automagicReloc = VMConfParser.automagicReloc(kvMap),
extraLibs = VMConfParser.extraLibs(kvMap), extraLibs = VMConfParser.extraLibs(kvMap),
bootImg = VMConfParser.bootImg(kvMap) bootImg = VMConfParser.bootImg(kvMap),
uPtrHack = VMConfParser.uPtrHack(kvMap)
) )
} }
...@@ -196,5 +203,7 @@ class VMConf( ...@@ -196,5 +203,7 @@ class VMConf(
val sourceInfo: Boolean = false, val sourceInfo: Boolean = false,
val automagicReloc: Boolean = false, val automagicReloc: Boolean = false,
val extraLibs: Seq[String] = Seq(), val extraLibs: Seq[String] = Seq(),
val bootImg: Option[String] = None) val bootImg: Option[String] = None,
val uPtrHack: Boolean = false
)
...@@ -362,8 +362,9 @@ object MemoryOperations { ...@@ -362,8 +362,9 @@ object MemoryOperations {
} }
} }
def noAccessViaPointer(ptr: Boolean, ty: Type) { @inline
if (ptr) { private def noAccessViaPointer(ptr: Boolean, ty: Type)(implicit microVM: MicroVM) {
if (microVM.enforceRefTypeNoPointerAccess && ptr) {
throw new UvmIllegalMemoryAccessException("Cannot access type %s via pointer".format(ty.repr)) throw new UvmIllegalMemoryAccessException("Cannot access type %s via pointer".format(ty.repr))
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment