本文整理汇总了C#中Drivers.Compiler.IL.ILConversionState.GetThrowNullReferenceExceptionMethodInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ILConversionState.GetThrowNullReferenceExceptionMethodInfo方法的具体用法?C# ILConversionState.GetThrowNullReferenceExceptionMethodInfo怎么用?C# ILConversionState.GetThrowNullReferenceExceptionMethodInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drivers.Compiler.IL.ILConversionState
的用法示例。
在下文中一共展示了ILConversionState.GetThrowNullReferenceExceptionMethodInfo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if field to load is a floating value or the field to load
/// is not of size 4 or 8 bytes.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
conversionState.CurrentStackFrame.Stack.Pop();
Types.TypeInfo arrayTypeInfo = conversionState.GetArrayTypeInfo();
int lengthOffset = conversionState.TheILLibrary.GetFieldInfo(arrayTypeInfo, "length").OffsetInBytes;
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
// 1. Check array reference is not null
// 1.1. Move array ref into eax
// 1.2. Compare eax (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
// 2. Load array length
// 1.1. Move array ref into eax
GlobalMethods.InsertPageFaultDetection(conversionState, "ESP", 0, (OpCodes)theOp.opCode.Value);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP]", Dest = "EAX" });
// 1.2. Compare eax (array ref) to 0
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "0" });
// 1.3. If not zero, jump to continue execution further down
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotZero, DestILPosition = currOpPosition, Extension = "ContinueExecution1" });
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "ContinueExecution1" });
//2. Load array length
// - Pop array ref
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "ECX" });
// - Load length from array ref
GlobalMethods.InsertPageFaultDetection(conversionState, "ECX", lengthOffset, (OpCodes)theOp.opCode.Value);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ECX+" + lengthOffset.ToString() + "]", Dest = "EAX" });
// - Push array length
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false
});
}
示例2: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if field to load is a floating value or the field to load
/// is not of size 4 or 8 bytes.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
conversionState.CurrentStackFrame.Stack.Pop();
Types.TypeInfo arrayTypeInfo = conversionState.GetArrayTypeInfo();
int lengthOffset = conversionState.TheILLibrary.GetFieldInfo(arrayTypeInfo, "length").OffsetInBytes;
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
// 1. Check array reference is not null
// 1.1. Move array ref into $t0
// 1.2. Compare $t0 (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
// 2. Load array length
// 1.1. Move array ref into eax
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "0($sp)", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.SrcMemoryToDestReg });
// 1.2. Compare eax (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
conversionState.Append(new ASMOps.Branch() { Src1 = "$t0", Src2 = "0", BranchType = ASMOps.BranchOp.BranchNotZero, DestILPosition = currOpPosition, Extension = "ContinueExecution1", UnsignedTest = false });
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "ContinueExecution1" });
//2. Load array length
// - Pop array ref
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t2" });
// - Load length from array ref
//conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = lengthOffset.ToString() + "($t2)", Dest = "$t0" });
GlobalMethods.LoadData(conversionState, theOp, "$t2", "$t0", lengthOffset, 4);
// - Push array length
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t0" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false,
isValue = true
});
}
示例3: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
Type elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetNewArrMethodInfo().ID);
//New array must:
// - Allocate memory on the heap for the object
// - If no memory is left, throw a panic attack because we're out of memory...
// - Call the specified constructor
int currOpPosition = conversionState.PositionOf(theOp);
//Attempt to allocate memory on the heap for the new array
//This involves:
// - (Number of elements is already on the stack)
// - Pushing the element type reference onto the stack
// - Calling GC NewArr method
// - Check the pointer == 0, if so, out of memory
//Push type reference
string typeIdStr = conversionState.TheILLibrary.GetTypeInfo(elementType).ID;
conversionState.AddExternalLabel(typeIdStr);
conversionState.Append(new ASMOps.La() { Label = typeIdStr, Dest = "$t4" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t4" });
//Push a dword for return value (i.e. new array pointer)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
//Get the GC.NewArr method ID (i.e. ASM label)
string methodLabel = conversionState.GetNewArrMethodInfo().ID;
//Call GC.NewArr
conversionState.Append(new ASMOps.Call() { Target = methodLabel });
//Pop the return value (i.e. new array pointer)
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
//Remove args from stack
conversionState.Append(new ASMOps.Add() { Src1 = "$sp", Src2 = "8", Dest = "$sp" });
//Check if pointer == 0?
//If it isn't 0, not out of memory so continue execution
conversionState.Append(new ASMOps.Branch() { Src1 = "$t0", BranchType = ASMOps.BranchOp.BranchNotZero, DestILPosition = currOpPosition, Extension = "NotNullMem", UnsignedTest = true });
//If we are out of memory, we have a massive problem
//Because it means we don't have space to create a new exception object
//So ultimately we just have to throw a kernel panic
//Throw a panic attack... ( :/ ) by calling kernel Halt(uint lastAddress)
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
//Insert the not null label
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "NotNullMem" });
//Push new array pointer
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t0" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isNewGCObject = true,
isGCManaged = true
});
}
示例4: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
MethodBase constructorMethod = theOp.MethodToCall;
Type objectType = constructorMethod.DeclaringType;
//New obj must:
// - Ignore for creation of Delegates
// - Allocate memory on the heap for the object
// - If no memory is left, throw a panic attack because we're out of memory...
// - Call the specified constructor
if (typeof(Delegate).IsAssignableFrom(objectType))
{
conversionState.Append(new ASMOps.Comment("Ignore newobj calls for Delegates"));
//Still need to:
// - Remove the "object" param but preserve the "function pointer"
StackItem funcPtrItem = conversionState.CurrentStackFrame.Stack.Pop(); ;
conversionState.CurrentStackFrame.Stack.Pop();
conversionState.CurrentStackFrame.Stack.Push(funcPtrItem);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "0($sp)", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.SrcMemoryToDestReg });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "$t0", Dest = "4($sp)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Add() { Src1 = "$sp", Src2 = "4", Dest = "$sp" });
return;
}
Types.MethodInfo constructorMethodInfo = conversionState.TheILLibrary.GetMethodInfo(constructorMethod);
conversionState.AddExternalLabel(conversionState.GetNewObjMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(constructorMethodInfo.ID);
int currOpPosition = conversionState.PositionOf(theOp);
//Attempt to allocate memory on the heap for the new object
//This involves:
// - Pushing the type reference onto the stack
// - Calling GC NewObj method
// - Check the pointer == 0, if so, out of memory
//Push type reference
string typeIdStr = conversionState.TheILLibrary.GetTypeInfo(objectType).ID;
conversionState.AddExternalLabel(typeIdStr);
conversionState.Append(new ASMOps.La() { Dest = "$t4", Label = typeIdStr });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t4" });
//Push a word for return value (i.e. new object pointer)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
//Get the GC.NewObj method ID (i.e. ASM label)
string methodLabel = conversionState.GetNewObjMethodInfo().ID;
//Call GC.NewObj
conversionState.Append(new ASMOps.Call() { Target = methodLabel });
//Pop the return value (i.e. new object pointer)
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
//Remove arg 0 from stack
conversionState.Append(new ASMOps.Add() { Src1 = "$sp", Src2 = "4", Dest = "$sp" });
//Check if pointer == 0?
//If it isn't 0, not out of memory so continue execution
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.BranchNotZero, Src1 = "$t0", DestILPosition = currOpPosition, Extension = "NotNullMem" });
//If we are out of memory, we have a massive problem
//Because it means we don't have space to create a new exception object
//So ultimately we just have to throw a kernel panic
//Throw a panic attack... ( :/ ) by calling kernel Halt(uint lastAddress)
//result.AppendLine("call GetEIP");
//result.AppendLine("push dword esp");
//result.AppendLine("push dword ebp");
//result.AppendLine("pushad");
//result.AppendLine("mov dword eax, 0xDEADBEEF");
//result.AppendLine("mov dword ebx, 0x1");
//result.AppendLine("mov dword ecx, 1");
//result.AppendLine("mov dword [staticfield_System_Boolean_Kernel_FOS_System_GC_Enabled], 1");
//result.AppendLine("mov dword [staticfield_System_Boolean_Kernel_FOS_System_Heap_PreventAllocation], 0");
//result.AppendLine("jmp method_System_Void_RETEND_Kernel_PreReqs_DECLEND_PageFaultDetection_NAMEEND___Fail");
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
//Insert the not null label
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "NotNullMem" });
//Call the specified constructor
//This involves:
// - Push empty dword onto stack
// - Move all args down by one dword
// - Move object reference into dword as first arg
// - Call constructor
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
int sizeOfArgs = 0;
ParameterInfo[] allParams = constructorMethod.GetParameters();
foreach (ParameterInfo aParam in allParams)
{
sizeOfArgs += conversionState.TheILLibrary.GetTypeInfo(aParam.ParameterType).SizeOnStackInBytes;
conversionState.CurrentStackFrame.Stack.Pop();
}
//.........这里部分代码省略.........
示例5: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if constant is a floating point number.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetThrowIndexOutOfRangeExceptionMethodInfo().ID);
Type elementType = null;
bool pushValue = true;
int sizeToPush = 4;
bool signExtend = true;
bool isFloat = false;
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Ldelem:
{
signExtend = false;
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
}
break;
case OpCodes.Ldelema:
{
signExtend = false;
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
pushValue = false;
}
break;
case OpCodes.Ldelem_R4:
case OpCodes.Ldelem_R8:
//TODO - Add more LdElem op variants support
throw new NotSupportedException("Ldelem op variant not supported yet!");
case OpCodes.Ldelem_I1:
sizeToPush = 1;
elementType = typeof(sbyte);
break;
case OpCodes.Ldelem_I2:
sizeToPush = 2;
elementType = typeof(Int16);
break;
case OpCodes.Ldelem_U1:
sizeToPush = 1;
signExtend = false;
elementType = typeof(byte);
break;
case OpCodes.Ldelem_U2:
sizeToPush = 2;
signExtend = false;
elementType = typeof(UInt16);
break;
case OpCodes.Ldelem_Ref:
signExtend = false;
elementType = null;
break;
case OpCodes.Ldelem_U4:
signExtend = false;
elementType = typeof(UInt32);
break;
case OpCodes.Ldelem_I4:
elementType = typeof(Int32);
break;
case OpCodes.Ldelem_I8:
sizeToPush = 8;
elementType = typeof(Int64);
break;
}
if (isFloat)
{
//TODO - Support floats
throw new NotSupportedException("LdElem for floats not supported yet!");
}
//Get element from array and push the value onto the stack
// (or for LdElemA push the address of the value)
//.........这里部分代码省略.........
示例6: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if constant is a floating point number.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
Type elementType = null;
//bool pushValue = true;
int sizeToPop = 4;
bool isFloat = false;
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetThrowIndexOutOfRangeExceptionMethodInfo().ID);
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Stelem:
{
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
}
break;
case OpCodes.Stelem_R4:
case OpCodes.Stelem_R8:
//TODO - Add more StElem op variants support
throw new NotSupportedException("Stelem op variant not supported yet!");
case OpCodes.Stelem_I1:
sizeToPop = 1;
elementType = typeof(sbyte);
break;
case OpCodes.Stelem_I2:
sizeToPop = 2;
elementType = typeof(Int16);
break;
case OpCodes.Stelem_Ref:
elementType = null;
break;
case OpCodes.Stelem_I4:
elementType = typeof(Int32);
break;
case OpCodes.Stelem_I8:
sizeToPop = 8;
elementType = typeof(Int64);
break;
}
if (isFloat)
{
//TODO - Support floats
throw new NotSupportedException("StElem for floats not supported yet!");
}
//Get element from array and push the value onto the stack
// (or for LdElemA push the address of the value)
//This involves:
// 1. Check array reference is not null
// - If it is, throw NullReferenceException
// 2. Check array element type is correct
// - If not, throw ArrayTypeMismatchException
// 3. Check index to get is > -1 and < array length
// - If not, throw IndexOutOfRangeException
// 4. Calculate address of element
// 5. Pop the value from the stack into the element
//Stack setup upon entering this op: (top-most downwards)
// 0. Value to store (dword or 2 dwords)
// 1. Index of element to get as Int32 (dword)
// 2. Array object reference as address (dword)
Types.TypeInfo arrayTypeInfo = conversionState.GetArrayTypeInfo();
// 1. Check array reference is not null
// 1.1. Move array ref into EAX
// 1.2. Compare EAX (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
// 1.1. Move array ref into EAX
GlobalMethods.InsertPageFaultDetection(conversionState, "ESP", sizeToPop == 8 ? 12 : 8, (OpCodes)theOp.opCode.Value);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP+" + (sizeToPop == 8 ? 12 : 8).ToString() + "]", Dest = "EAX" });
// 1.2. Compare EAX (array ref) to 0
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "0" });
// 1.3. If not zero, jump to continue execution further down
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotZero, DestILPosition = currOpPosition, Extension = "Continue1" });
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
//.........这里部分代码省略.........
示例7: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
Type elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetNewArrMethodInfo().ID);
//New array must:
// - Allocate memory on the heap for the object
// - If no memory is left, throw a panic attack because we're out of memory...
// - Call the specified constructor
int currOpPosition = conversionState.PositionOf(theOp);
//Attempt to allocate memory on the heap for the new array
//This involves:
// - (Number of elements is already on the stack)
// - Pushing the element type reference onto the stack
// - Calling GC NewArr method
// - Check the pointer == 0, if so, out of memory
//Push type reference
string typeIdStr = conversionState.TheILLibrary.GetTypeInfo(elementType).ID;
conversionState.AddExternalLabel(typeIdStr);
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = typeIdStr });
//Push a dword for return value (i.e. new array pointer)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
//Get the GC.NewArr method ID (i.e. ASM label)
string methodLabel = conversionState.GetNewArrMethodInfo().ID;
//Call GC.NewArr
conversionState.Append(new ASMOps.Call() { Target = methodLabel });
//Pop the return value (i.e. new array pointer)
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
//Remove args from stack
conversionState.Append(new ASMOps.Add() { Src = "8", Dest = "ESP" });
//Check if pointer == 0?
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "0" });
//If it isn't 0, not out of memory so continue execution
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotZero, DestILPosition = currOpPosition, Extension = "NotNullMem" });
//If we are out of memory, we have a massive problem
//Because it means we don't have space to create a new exception object
//So ultimately we just have to throw a kernel panic
//Throw a panic attack... ( :/ ) by calling kernel Halt(uint lastAddress)
//result.AppendLine("call GetEIP");
//result.AppendLine("push dword esp");
//result.AppendLine("push dword ebp");
//result.AppendLine("pushad");
//result.AppendLine("mov dword eax, 0xDEADBEEF");
//result.AppendLine("mov dword ebx, 0x2");
//result.AppendLine("mov dword ecx, 1");
//result.AppendLine("mov dword [staticfield_System_Boolean_Kernel_FOS_System_GC_Enabled], 1");
//result.AppendLine("mov dword [staticfield_System_Boolean_Kernel_FOS_System_Heap_PreventAllocation], 0");
//result.AppendLine("jmp method_System_Void_RETEND_Kernel_PreReqs_DECLEND_PageFaultDetection_NAMEEND___Fail");
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
//Insert the not null label
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "NotNullMem" });
//Push new array pointer
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isNewGCObject = true,
isGCManaged = true
});
}
示例8: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if constant is a floating point number.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetThrowIndexOutOfRangeExceptionMethodInfo().ID);
Type elementType = null;
Types.TypeInfo elemTypeInfo = null;
bool pushValue = true;
int sizeToPush = 4;
int sizeToLoad = 4;
bool signExtend = true;
bool isFloat = false;
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Ldelem:
{
signExtend = false;
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
elemTypeInfo = conversionState.TheILLibrary.GetTypeInfo(elementType);
sizeToLoad = elemTypeInfo.IsValueType ? elemTypeInfo.SizeOnHeapInBytes : elemTypeInfo.SizeOnStackInBytes;
sizeToPush = elemTypeInfo.SizeOnStackInBytes;
}
break;
case OpCodes.Ldelema:
{
signExtend = false;
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
elemTypeInfo = conversionState.TheILLibrary.GetTypeInfo(elementType);
sizeToPush = 4;
sizeToLoad = 0;
pushValue = false;
}
break;
case OpCodes.Ldelem_R4:
case OpCodes.Ldelem_R8:
//TODO - Add more LdElem op variants support
throw new NotSupportedException("Ldelem op variant not supported yet!");
case OpCodes.Ldelem_I1:
sizeToPush = 4;
sizeToLoad = 1;
elementType = typeof(sbyte);
elemTypeInfo = conversionState.TheILLibrary.GetTypeInfo(elementType);
break;
case OpCodes.Ldelem_I2:
sizeToPush = 4;
sizeToLoad = 2;
elementType = typeof(Int16);
elemTypeInfo = conversionState.TheILLibrary.GetTypeInfo(elementType);
break;
case OpCodes.Ldelem_U1:
sizeToPush = 4;
sizeToLoad = 1;
signExtend = false;
elementType = typeof(byte);
elemTypeInfo = conversionState.TheILLibrary.GetTypeInfo(elementType);
break;
case OpCodes.Ldelem_U2:
sizeToPush = 4;
sizeToLoad = 2;
signExtend = false;
elementType = typeof(UInt16);
elemTypeInfo = conversionState.TheILLibrary.GetTypeInfo(elementType);
break;
case OpCodes.Ldelem_Ref:
signExtend = false;
elementType = null;
elemTypeInfo = null;
sizeToPush = 4;
sizeToLoad = 4;
break;
case OpCodes.Ldelem_U4:
signExtend = false;
elementType = typeof(UInt32);
elemTypeInfo = conversionState.TheILLibrary.GetTypeInfo(elementType);
sizeToPush = 4;
sizeToLoad = 4;
//.........这里部分代码省略.........
示例9: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if any argument or the return value is a floating point number.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
MethodBase methodToCall = theOp.MethodToCall;
Types.MethodInfo methodToCallInfo = conversionState.TheILLibrary.GetMethodInfo(methodToCall);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
//The method to call is a method base
//A method base can be either a method info i.e. a normal method
//or a constructor method. The two types are treated separately.
if(methodToCall is MethodInfo)
{
//Need to do callvirt related stuff to load address of method to call
// - Check for invoke of a delegate - if so, treat rather differently from normal callvirt
if (typeof(Delegate).IsAssignableFrom(((MethodInfo)methodToCall).DeclaringType))
{
//Callvirt to delegate method
// - We only support calls to Invoke at the moment
if (methodToCall.Name != "Invoke")
{
throw new NotSupportedException("Callvirt to Delegate method not supported! Method name: " + methodToCall.Name);
}
int bytesForAllParams = ((MethodInfo)methodToCall).GetParameters().Select(x => conversionState.TheILLibrary.GetTypeInfo(x.ParameterType).SizeOnStackInBytes).Sum();
// - Move into eax address of function to call from stack - delegate reference is function pointer
//All the parameters for the method that was called
List<Type> allParams = ((MethodInfo)methodToCall).GetParameters().Select(x => x.ParameterType).ToList();
int bytesForParams = allParams.Select(x => conversionState.TheILLibrary.GetTypeInfo(x).SizeOnStackInBytes).Sum();
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP+" + bytesForParams + "]", Dest = "EAX" });
//Allocate space on the stack for the return value as necessary
Type retType = ((MethodInfo)methodToCall).ReturnType;
Types.TypeInfo retTypeInfo = conversionState.TheILLibrary.GetTypeInfo(retType);
StackItem returnItem = new StackItem()
{
isFloat = Utilities.IsFloat(retType),
sizeOnStackInBytes = retTypeInfo.SizeOnStackInBytes,
isGCManaged = retTypeInfo.IsGCManaged
};
//We do not push the return value onto the stack unless it has size > 0
//We do not push the return value onto our stack at this point - it is pushed after the call is done
if (returnItem.sizeOnStackInBytes != 0)
{
if (returnItem.isFloat)
{
//SUPPORT - floats
throw new NotSupportedException("Cannot handle float return values!");
}
else if (returnItem.sizeOnStackInBytes == 4)
{
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
}
else if (returnItem.sizeOnStackInBytes == 8)
{
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
}
else
{
throw new NotSupportedException("Invalid return stack operand size!");
}
}
//Append the actual call
conversionState.Append(new ASMOps.Call() { Target = "EAX" });
//After a call, we need to remove the return value and parameters from the stack
//This is most easily done by just adding the total number of bytes for params and
//return value to the stack pointer (ESP register).
//Stores the number of bytes to add
// - Initially at least 4 for the delegate (method) ref/pointer
int bytesToAdd = 4;
//Go through all params that must be removed
foreach (Type aParam in allParams)
{
//Pop the paramter off our stack
//(Note: Return value was never pushed onto our stack. See above)
conversionState.CurrentStackFrame.Stack.Pop();
//Add the size of the paramter to the total number of bytes to pop
bytesToAdd += conversionState.TheILLibrary.GetTypeInfo(aParam).SizeOnStackInBytes;
}
//.........这里部分代码省略.........
示例10: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if constant is a floating point number.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
Type elementType = null;
//bool pushValue = true;
int sizeToPop = 4;
bool isFloat = false;
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetThrowIndexOutOfRangeExceptionMethodInfo().ID);
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Stelem:
{
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
}
break;
case OpCodes.Stelem_R4:
case OpCodes.Stelem_R8:
//TODO - Add more StElem op variants support
throw new NotSupportedException("Stelem op variant not supported yet!");
case OpCodes.Stelem_I1:
sizeToPop = 1;
elementType = typeof(sbyte);
break;
case OpCodes.Stelem_I2:
sizeToPop = 2;
elementType = typeof(Int16);
break;
case OpCodes.Stelem_Ref:
elementType = null;
break;
case OpCodes.Stelem_I4:
elementType = typeof(Int32);
break;
case OpCodes.Stelem_I8:
sizeToPop = 8;
elementType = typeof(Int64);
break;
}
if (isFloat)
{
//TODO - Support floats
throw new NotSupportedException("StElem for floats not supported yet!");
}
//Get element from array and push the value onto the stack
// (or for LdElemA push the address of the value)
//This involves:
// 1. Check array reference is not null
// - If it is, throw NullReferenceException
// 2. Check array element type is correct
// - If not, throw ArrayTypeMismatchException
// 3. Check index to get is > -1 and < array length
// - If not, throw IndexOutOfRangeException
// 4. Calculate address of element
// 5. Pop the value from the stack into the element
//Stack setup upon entering this op: (top-most downwards)
// 0. Value to store (word or 2 words)
// 1. Index of element to get as Int32 (word)
// 2. Array object reference as address (word)
Types.TypeInfo arrayTypeInfo = conversionState.GetArrayTypeInfo();
// 1. Check array reference is not null
// 1.1. Move array ref into $t0
// 1.2. Compare $t0 (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
// 1.1. Move array ref into $t0
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = (sizeToPop == 8 ? 12 : 8).ToString() + "($sp)", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.SrcMemoryToDestReg });
// 1.2. Compare $t0 (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.BranchNotZero, Src1 = "$t0", DestILPosition = currOpPosition, Extension = "Continue1" });
// 1.4. Otherwise, call Exceptions.Throw1NullReferenceException
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
//.........这里部分代码省略.........