GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit af134956 authored by Kunshan Wang's avatar Kunshan Wang

stubs for the new make_boot_img function

parent 625bd7e4
......@@ -433,12 +433,12 @@ struct MuCtx {
MuIRBuilder* (*new_ir_builder)(MuCtx *ctx);
// Build boot image
void (*make_boot_image)(MuVM *mvm,
void (*make_boot_image)(MuCtx *ctx,
MuID* whitelist, MuArraySize whitelist_sz,
MuIRefValue *sym_fields, MuCString *sym_strings, MuArraySize nsyms,
MuIRefValue *reloc_fields, MuCString *reloc_strings, MuArraySize nrelocs,
MuFuncRefValue primordial_func, MuStackRefValue primordial_stack,
MuRefValue primordial_threadlocal,
MuIRefValue *sym_fields, MuCString *sym_strings, MuArraySize nsyms,
MuIRefValue *reloc_fields, MuCString *reloc_strings, MuArraySize nrelocs,
MuCString output_file); /// MUAPIPARSER whitelist:array:whitelist_sz;sym_fields:array:nsyms;sym_strings:array:nsyms;reloc_fields:array:nrelocs;reloc_strings:array:nrelocs;primordial_func:optional;primordial_stack:optional;primordial_threadlocal:optional
};
......
......@@ -188,6 +188,7 @@ _array_converters = {
"uint64_t*" : "readLongArray",
"MuFlag*" : "readFlagArray",
"MuID*" : "readIntArray",
"MuCString*": "readCStringArray",
}
_special_converters = {
......
......@@ -363,9 +363,10 @@ common_instruction_opcodes = {
'@uvm.kill_dependency': 0x230,
'@uvm.native.pin': 0x240,
'@uvm.native.unpin': 0x241,
'@uvm.native.expose': 0x242,
'@uvm.native.unexpose': 0x243,
'@uvm.native.get_cookie': 0x244,
'@uvm.native.get_addr': 0x242,
'@uvm.native.expose': 0x243,
'@uvm.native.unexpose': 0x244,
'@uvm.native.get_cookie': 0x245,
'@uvm.meta.id_of': 0x250,
'@uvm.meta.name_of': 0x251,
'@uvm.meta.load_bundle': 0x252,
......@@ -1499,7 +1500,6 @@ _initialize_methods(MuVM, [
('id_of', CMuID, [CMuName]),
('name_of', CMuName, [CMuID]),
('set_trap_handler_', None, [CMuTrapHandler, CMuCPtr]),
('make_boot_image_', None, [ctypes.c_void_p, CMuArraySize, CMuCString]),
('execute', None, []),
('get_mu_error_ptr', ctypes.c_void_p, []),
## GEN:END:MuVM
......@@ -1591,9 +1591,11 @@ _initialize_methods(MuCtx, [
('disable_watchpoint', None, [CMuWPID]),
('pin', MuUPtrValue, [MuValue]),
('unpin', None, [MuValue]),
('get_addr', MuUPtrValue, [MuValue]),
('expose', MuValue, [MuFuncRefValue, CMuCallConv, MuIntValue]),
('unexpose', None, [CMuCallConv, MuValue]),
('new_ir_builder', MuIRBuilder, []),
('make_boot_image_', None, [ctypes.c_void_p, CMuArraySize, MuFuncRefValue, MuStackRefValue, MuRefValue, ctypes.c_void_p, ctypes.c_void_p, CMuArraySize, ctypes.c_void_p, ctypes.c_void_p, CMuArraySize, CMuCString]),
## GEN:END:MuCtx
])
......
......@@ -679,6 +679,23 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
}
unpin(objRef)
}
def getAddr(loc: MuValue): MuUPtrValue = {
val (objTy, (objRef, offset)) = loc match {
case MuRefValue(t, vb) => (t, (vb.objRef, 0L))
case MuIRefValue(t, vb) => (t, vb.oo)
case _ => {
throw new IllegalArgumentException("loc must be ref or iref. Found %s".format(loc.ty))
}
}
// do nothing
assert(microVM.memoryManager.globalMemory.isInSpace(objRef) || pinSet.contains(objRef),
"Attempt to get address of objref %d 0x%x, offset %d, 0x%x, which is neither a global cell nor pinned by the current thread.".format(
objRef, objRef, offset, offset))
val ptrTy = InternalTypePool.ptrOf(objTy)
val box = new BoxPointer(objRef + offset)
addHandle(MuUPtrValue(ptrTy, box))
}
def expose(func: MuFuncRefValue, callConv: Flag, cookie: MuIntValue): MuUFPValue = {
val TypeFuncRef(sig) = func.ty
......@@ -700,6 +717,13 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
def newIRBuilder(): IRBuilder = {
microVM.newIRBuilder()
}
def makeBootImage(whitelist: Seq[MuID],
primordialFunc: Option[MuFuncRefValue], primordialStack: Option[MuStackRefValue], primordialThreadLocal: Option[MuRefValue],
symFields: Seq[MuIRefValue], symStrings: Seq[String], relocFields: Seq[MuIRefValue], relocStrings: Seq[String],
outputFile: String): Unit = {
???
}
// Internal methods for the micro VM
......
......@@ -45,16 +45,6 @@ val trap_handler = _raw_trap_handler
val userdata = _raw_userdata
val _RV = mvm.setTrapHandler(trap_handler, userdata)
}
val MUVM__MAKE_BOOT_IMAGE = exposedMethod("MuVM.make_boot_image", JType.VOID, Array(JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_mvm = _jffiBuffer.getAddress(0)
val _raw_whitelist = _jffiBuffer.getAddress(1)
val _raw_whitelist_sz = _jffiBuffer.getAddress(2)
val _raw_output_file = _jffiBuffer.getAddress(3)
val mvm = getMicroVM(_raw_mvm)
val whitelist = readIntArray(_raw_whitelist, _raw_whitelist_sz)
val output_file = readCString(_raw_output_file)
val _RV = mvm.makeBootImage(whitelist, output_file)
}
val MUVM__EXECUTE = exposedMethod("MuVM.execute", JType.VOID, Array(JType.POINTER)) { _jffiBuffer =>
val _raw_mvm = _jffiBuffer.getAddress(0)
val mvm = getMicroVM(_raw_mvm)
......@@ -66,14 +56,13 @@ val mvm = getMicroVM(_raw_mvm)
val _RV = mvm.getMuErrorPtr()
_jffiBuffer.setAddressReturn(_RV)
}
val stubsOfMuVM = new Array[Word](7)
val stubsOfMuVM = new Array[Word](6)
stubsOfMuVM(0) = MUVM__NEW_CONTEXT.address
stubsOfMuVM(1) = MUVM__ID_OF.address
stubsOfMuVM(2) = MUVM__NAME_OF.address
stubsOfMuVM(3) = MUVM__SET_TRAP_HANDLER.address
stubsOfMuVM(4) = MUVM__MAKE_BOOT_IMAGE.address
stubsOfMuVM(5) = MUVM__EXECUTE.address
stubsOfMuVM(6) = MUVM__GET_MU_ERROR_PTR.address
stubsOfMuVM(4) = MUVM__EXECUTE.address
stubsOfMuVM(5) = MUVM__GET_MU_ERROR_PTR.address
val MUCTX__ID_OF = exposedMethod("MuCtx.id_of", JType.UINT32, Array(JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_ctx = _jffiBuffer.getAddress(0)
val _raw_name = _jffiBuffer.getAddress(1)
......@@ -872,6 +861,15 @@ val ctx = getMuCtx(_raw_ctx)
val loc = getMuValueNotNull(_raw_loc).asInstanceOf[MuValue]
val _RV = ctx.unpin(loc)
}
val MUCTX__GET_ADDR = exposedMethod("MuCtx.get_addr", JType.POINTER, Array(JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_ctx = _jffiBuffer.getAddress(0)
val _raw_loc = _jffiBuffer.getAddress(1)
val ctx = getMuCtx(_raw_ctx)
val loc = getMuValueNotNull(_raw_loc).asInstanceOf[MuValue]
val _RV = ctx.getAddr(loc)
val _RV_FAK = exposeMuValue(ctx, _RV)
_jffiBuffer.setAddressReturn(_RV_FAK)
}
val MUCTX__EXPOSE = exposedMethod("MuCtx.expose", JType.POINTER, Array(JType.POINTER, JType.POINTER, JType.UINT32, JType.POINTER)) { _jffiBuffer =>
val _raw_ctx = _jffiBuffer.getAddress(0)
val _raw_func = _jffiBuffer.getAddress(1)
......@@ -901,7 +899,33 @@ val _RV = ctx.newIRBuilder()
val _RV_FAK = exposeMuIRBuilder(_RV)
_jffiBuffer.setAddressReturn(_RV_FAK)
}
val stubsOfMuCtx = new Array[Word](87)
val MUCTX__MAKE_BOOT_IMAGE = exposedMethod("MuCtx.make_boot_image", JType.VOID, Array(JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_ctx = _jffiBuffer.getAddress(0)
val _raw_whitelist = _jffiBuffer.getAddress(1)
val _raw_whitelist_sz = _jffiBuffer.getAddress(2)
val _raw_primordial_func = _jffiBuffer.getAddress(3)
val _raw_primordial_stack = _jffiBuffer.getAddress(4)
val _raw_primordial_threadlocal = _jffiBuffer.getAddress(5)
val _raw_sym_fields = _jffiBuffer.getAddress(6)
val _raw_sym_strings = _jffiBuffer.getAddress(7)
val _raw_nsyms = _jffiBuffer.getAddress(8)
val _raw_reloc_fields = _jffiBuffer.getAddress(9)
val _raw_reloc_strings = _jffiBuffer.getAddress(10)
val _raw_nrelocs = _jffiBuffer.getAddress(11)
val _raw_output_file = _jffiBuffer.getAddress(12)
val ctx = getMuCtx(_raw_ctx)
val whitelist = readIntArray(_raw_whitelist, _raw_whitelist_sz)
val primordial_func = getMuValueNullable(_raw_primordial_func).asInstanceOf[Option[MuFuncRefValue]]
val primordial_stack = getMuValueNullable(_raw_primordial_stack).asInstanceOf[Option[MuStackRefValue]]
val primordial_threadlocal = getMuValueNullable(_raw_primordial_threadlocal).asInstanceOf[Option[MuRefValue]]
val sym_fields = readMuValueArray(_raw_sym_fields, _raw_nsyms)
val sym_strings = readCStringArray(_raw_sym_strings, _raw_nsyms)
val reloc_fields = readMuValueArray(_raw_reloc_fields, _raw_nrelocs)
val reloc_strings = readCStringArray(_raw_reloc_strings, _raw_nrelocs)
val output_file = readCString(_raw_output_file)
val _RV = ctx.makeBootImage(whitelist, primordial_func, primordial_stack, primordial_threadlocal, sym_fields, sym_strings, reloc_fields, reloc_strings, output_file)
}
val stubsOfMuCtx = new Array[Word](89)
stubsOfMuCtx(0) = MUCTX__ID_OF.address
stubsOfMuCtx(1) = MUCTX__NAME_OF.address
stubsOfMuCtx(2) = MUCTX__CLOSE_CONTEXT.address
......@@ -986,9 +1010,11 @@ stubsOfMuCtx(80) = MUCTX__ENABLE_WATCHPOINT.address
stubsOfMuCtx(81) = MUCTX__DISABLE_WATCHPOINT.address
stubsOfMuCtx(82) = MUCTX__PIN.address
stubsOfMuCtx(83) = MUCTX__UNPIN.address
stubsOfMuCtx(84) = MUCTX__EXPOSE.address
stubsOfMuCtx(85) = MUCTX__UNEXPOSE.address
stubsOfMuCtx(86) = MUCTX__NEW_IR_BUILDER.address
stubsOfMuCtx(84) = MUCTX__GET_ADDR.address
stubsOfMuCtx(85) = MUCTX__EXPOSE.address
stubsOfMuCtx(86) = MUCTX__UNEXPOSE.address
stubsOfMuCtx(87) = MUCTX__NEW_IR_BUILDER.address
stubsOfMuCtx(88) = MUCTX__MAKE_BOOT_IMAGE.address
val MUIRBUILDER__LOAD = exposedMethod("MuIRBuilder.load", JType.VOID, Array(JType.POINTER)) { _jffiBuffer =>
val _raw_b = _jffiBuffer.getAddress(0)
val b = getMuIRBuilder(_raw_b)
......@@ -2208,9 +2234,10 @@ val MU_CI_UVM_FUTEX_CMP_REQUEUE = 0x223
val MU_CI_UVM_KILL_DEPENDENCY = 0x230
val MU_CI_UVM_NATIVE_PIN = 0x240
val MU_CI_UVM_NATIVE_UNPIN = 0x241
val MU_CI_UVM_NATIVE_EXPOSE = 0x242
val MU_CI_UVM_NATIVE_UNEXPOSE = 0x243
val MU_CI_UVM_NATIVE_GET_COOKIE = 0x244
val MU_CI_UVM_NATIVE_GET_ADDR = 0x242
val MU_CI_UVM_NATIVE_EXPOSE = 0x243
val MU_CI_UVM_NATIVE_UNEXPOSE = 0x244
val MU_CI_UVM_NATIVE_GET_COOKIE = 0x245
val MU_CI_UVM_META_ID_OF = 0x250
val MU_CI_UVM_META_NAME_OF = 0x251
val MU_CI_UVM_META_LOAD_BUNDLE = 0x252
......
......@@ -98,6 +98,8 @@ private object CDefsHelperFunctions {
str
}
def readCStringArray(base: Long, len: Long): IndexedSeq[String] = readLongArray(base, len).map(readCString)
def readCStringOptional(addr: Long): Option[String] = {
if (addr == 0L) None else Some(readCString(addr))
}
......
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