public void BeginHandler(ExceptionBlock block, ExceptionHandlerType handlerType, Type exceptionType = null) { var prev = block.prev = block.cur; if (prev != null) { EndHandler(block, prev); } block.skip = DeclareLabel(); Emit(OpCodes.Leave, block.skip); var handlerLabel = DeclareLabel(); MarkLabel(handlerLabel); block.cur = new LabelledExceptionHandler { tryStart = block.start, tryEnd = handlerLabel, handlerType = handlerType, handlerEnd = block.skip, exceptionType = exceptionType != null?IL.Import(exceptionType) : null }; if (handlerType == ExceptionHandlerType.Filter) { block.cur.filterStart = handlerLabel; } else { block.cur.handlerStart = handlerLabel; } }
/// <summary> /// Reads the specified reader. /// </summary> /// <param name="reader">The reader.</param> /// <param name="isFat">if set to <c>true</c> [is fat].</param> public void Read(BinaryReader reader, bool isFat) { if (!isFat) { this.ExceptionHandlerType = (ExceptionHandlerType)reader.ReadInt16(); this.TryOffset = reader.ReadInt16(); this.TryLength = reader.ReadByte(); this.HandlerOffset = reader.ReadInt16(); this.HandlerLength = reader.ReadByte(); } else { this.ExceptionHandlerType = (ExceptionHandlerType)reader.ReadInt32(); this.TryOffset = reader.ReadInt32(); this.TryLength = reader.ReadInt32(); this.HandlerOffset = reader.ReadInt32(); this.HandlerLength = reader.ReadInt32(); } if (ExceptionHandlerType.Exception == this.ExceptionHandlerType) { this.ClassToken = new Token(reader.ReadUInt32()); } else if (ExceptionHandlerType.Filter == this.ExceptionHandlerType) { this.FilterOffset = reader.ReadInt32(); } else { reader.ReadInt32(); } }
public LabelledExceptionHandler BeginHandler(ExceptionHandlerType type) { LabelledExceptionHandler prev = _Prev = _Handler; if (prev != null) { EndHandler(prev); } IL.Emit(SRE.OpCodes.Leave, _SkipHandler = IL.DefineLabel()); Label handlerStart = IL.DefineLabel(); IL.MarkLabel(handlerStart); LabelledExceptionHandler next = _Handler = new LabelledExceptionHandler { TryStart = _Start, TryEnd = handlerStart, HandlerType = type, HandlerEnd = _SkipHandler }; if (type == ExceptionHandlerType.Filter) { next.FilterStart = handlerStart; } else { next.HandlerStart = handlerStart; } return(next); }
private void PatchRawExceptionHandlers(ByteBuffer buffer, MetadataBuilder metadata, int count, bool fat_entry) { for (int i = 0; i < count; i++) { ExceptionHandlerType exceptionHandlerType; if (fat_entry) { uint num = base.ReadUInt32(); exceptionHandlerType = (ExceptionHandlerType)(num & 7u); buffer.WriteUInt32(num); } else { ushort num2 = base.ReadUInt16(); exceptionHandlerType = (ExceptionHandlerType)(num2 & 7); buffer.WriteUInt16(num2); } buffer.WriteBytes(base.ReadBytes(fat_entry ? 16 : 6)); ExceptionHandlerType exceptionHandlerType2 = exceptionHandlerType; if (exceptionHandlerType2 == ExceptionHandlerType.Catch) { IMetadataTokenProvider provider = this.reader.LookupToken(this.ReadToken()); buffer.WriteUInt32(metadata.LookupToken(provider).ToUInt32()); } else { buffer.WriteUInt32(base.ReadUInt32()); } } }
internal ExceptionHandler(ExceptionHandlerType type, int trystart, int trylength, int handlerstart, int handlerlength) { Type = type; TryStart = trystart; TryEnd = trystart+trylength; HandlerStart = handlerstart; HandlerEnd = handlerstart + handlerlength; }
internal ExceptionHandler(ExceptionHandlerType type, int trystart, int trylength, int handlerstart, int handlerlength) { Type = type; TryStart = trystart; TryEnd = trystart + trylength; HandlerStart = handlerstart; HandlerEnd = handlerstart + handlerlength; }
public ExceptionHandlerOptions(Dictionary<object, object> ops, ExceptionHandler eh) { this.TryStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryStart); this.TryEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryEnd); this.FilterStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.FilterStart); this.HandlerStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerStart); this.HandlerEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerEnd); this.CatchType = eh.CatchType; this.HandlerType = eh.HandlerType; }
private void InitTypes(ExceptionHandlerType selected) { cboType.Items.Clear(); foreach (string s in AssemblyUtils.GetEnumNames(typeof(ExceptionHandlerType))) { cboType.Items.Add(s); } cboType.SelectedIndex = (int)selected; }
private void InitTypes(ExceptionHandlerType selected) { cboType.Items.Clear(); foreach (string s in AssemblyUtils.GetEnumNames(typeof(ExceptionHandlerType))) { cboType.Items.Add(s); } cboType.SelectedIndex = (int)selected; }
public ExceptionHandlerOptions(Dictionary <object, object> ops, ExceptionHandler eh) { this.TryStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryStart); this.TryEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryEnd); this.FilterStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.FilterStart); this.HandlerStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerStart); this.HandlerEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerEnd); this.CatchType = eh.CatchType; this.HandlerType = eh.HandlerType; }
public ExceptionHandler( ExceptionHandlerType type, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int filterOffset) { _type = type; _tryOffset = tryOffset; _tryLength = tryLength; _handlerOffset = handlerOffset; _handlerLength = handlerLength; _filterOffset = filterOffset; }
public MosaExceptionHandler(ExceptionHandlerType ehType, int tryStart, int tryEnd, int handlerStart, int handlerEnd, MosaType type, int?filterOffset) { HandlerType = ehType; TryStart = tryStart; TryEnd = tryEnd; HandlerStart = handlerStart; HandlerEnd = handlerEnd; Type = type; FilterOffset = filterOffset; }
public MosaExceptionHandler(ExceptionHandlerType ehType, int tryStart, int tryEnd, int handlerStart, int handlerEnd, MosaType type, int? filterOffset) { HandlerType = ehType; TryStart = tryStart; TryEnd = tryEnd; HandlerStart = handlerStart; HandlerEnd = handlerEnd; Type = type; FilterOffset = filterOffset; }
public ExceptionHandler( ExceptionHandlerType type, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int filterOffset, TypeSignature catchType) { _type = type; _tryOffset = tryOffset; _tryLength = tryLength; _handlerOffset = handlerOffset; _handlerLength = handlerLength; _filterOffset = filterOffset; _catchType = catchType; }
private static int GetExceptionHandlerTypePriority(ExceptionHandlerType type) { switch (type) { case ExceptionHandlerType.Catch: case ExceptionHandlerType.Filter: case ExceptionHandlerType.Fault: return(0); case ExceptionHandlerType.Finally: return(1); default: throw new Exception(); } }
public ExceptionInfo(int tryStart, int tryEnd, int filterStart, int handlerStart, int handlerEnd, ITypeDefOrRef catchType, ExceptionHandlerType handlerType) { if (tryStart > tryEnd || filterStart > handlerStart || tryStart < 0 || tryEnd < 0 || filterStart < 0 || handlerStart < 0 || handlerEnd < 0) throw new ApplicationException("Invalid start/end/filter/handler indexes"); this.tryStart = tryStart; this.tryEnd = tryEnd; this.filterStart = filterStart == handlerStart ? -1 : filterStart; this.handlerStart = handlerStart; this.handlerEnd = handlerEnd; this.catchType = catchType; this.handlerType = handlerType; }
private void ReadExceptionHandlerSpecific(ExceptionHandler handler) { ExceptionHandlerType handlerType = handler.HandlerType; if (handlerType == ExceptionHandlerType.Catch) { handler.CatchType = (TypeReference)this.reader.LookupToken(this.ReadToken()); return; } if (handlerType != ExceptionHandlerType.Filter) { base.Advance(4); return; } handler.FilterStart = this.GetInstruction(base.ReadInt32()); }
private void Types_SelectedIndexChanged(object sender, EventArgs e) { if (Types.SelectedItem != null) { ExceptionHandlerType ehtype = (ExceptionHandlerType)Types.SelectedItem; if (ehtype == ExceptionHandlerType.Filter) { FilterStart.Enabled = FilterEnd.Enabled = true; } else { FilterStart.Enabled = FilterEnd.Enabled = false; FilterStart.Text = FilterEnd.Text = string.Empty; } } }
private void WriteExceptionHandlerSpecific(ExceptionHandler handler) { ExceptionHandlerType handlerType = handler.HandlerType; if (handlerType == ExceptionHandlerType.Catch) { this.WriteMetadataToken(this.metadata.LookupToken(handler.CatchType)); return; } if (handlerType != ExceptionHandlerType.Filter) { base.WriteInt32(0); return; } base.WriteInt32(handler.FilterStart.Offset); }
public ExceptionInfo(int tryStart, int tryEnd, int filterStart, int handlerStart, int handlerEnd, ITypeDefOrRef catchType, ExceptionHandlerType handlerType) { if (tryStart > tryEnd || filterStart > handlerStart || tryStart < 0 || tryEnd < 0 || filterStart < 0 || handlerStart < 0 || handlerEnd < 0) { throw new ApplicationException("Invalid start/end/filter/handler indexes"); } this.tryStart = tryStart; this.tryEnd = tryEnd; this.filterStart = filterStart == handlerStart ? -1 : filterStart; this.handlerStart = handlerStart; this.handlerEnd = handlerEnd; this.catchType = catchType; this.handlerType = handlerType; }
public static ExceptionHandler ToDNLib(this ExceptionHandlingClause clause, ModuleDef module, IList <Instruction> instructions) { ExceptionHandlerType type = clause.Flags.ToDNLib(); ExceptionHandler result = new ExceptionHandler(type); if (clause.CatchType != null) { result.CatchType = module.ToSig(clause.CatchType.ToSignature()).ToTypeDefOrRef(); } if (type.HasFlag(ExceptionHandlerType.Filter)) { result.FilterStart = instructions.AtOffset(clause.FilterOffset); } result.HandlerStart = instructions.AtOffset(clause.HandlerOffset); result.HandlerEnd = instructions.AtOffset(clause.HandlerOffset + clause.HandlerLength); result.TryStart = instructions.AtOffset(clause.TryOffset); result.TryEnd = instructions.AtOffset(clause.TryOffset + clause.TryLength); return(result); }
private void ComputeExceptionHandlerStackSize(ref Dictionary <Instruction, int> stack_sizes) { Collection <ExceptionHandler> exceptionHandlers = this.body.ExceptionHandlers; for (int i = 0; i < exceptionHandlers.Count; i++) { ExceptionHandler item = exceptionHandlers[i]; ExceptionHandlerType handlerType = item.HandlerType; if (handlerType == ExceptionHandlerType.Catch) { CodeWriter.AddExceptionStackSize(item.HandlerStart, ref stack_sizes); } else if (handlerType == ExceptionHandlerType.Filter) { CodeWriter.AddExceptionStackSize(item.FilterStart, ref stack_sizes); CodeWriter.AddExceptionStackSize(item.HandlerStart, ref stack_sizes); } } }
private Mono.Cecil.Cil.ExceptionHandler AddExceptionHandler<TException>( ExceptionHandlerType handlerType, Instruction tryStart, Instruction handlerStart, Instruction handlerEnd) { var exceptionHandler = new Mono.Cecil.Cil.ExceptionHandler(handlerType) { TryStart = tryStart, TryEnd = handlerStart, HandlerStart = handlerStart, HandlerEnd = handlerEnd, CatchType = Module.Import(typeof(TException)) }; Method.Body.ExceptionHandlers.Add(exceptionHandler); return exceptionHandler; }
private LinkerSymbol CreateProtectedRegionDefinition(string name, uint start, uint end, uint handler, ExceptionHandlerType handlerType, MosaType exceptionType) { // Emit parameter table var protectedRegionDefinitionSymbol = MethodCompiler.Linker.CreateSymbol(name, SectionKind.ROData, TypeLayout.NativePointerAlignment, 0); var writer1 = new EndianAwareBinaryWriter(protectedRegionDefinitionSymbol.Stream, Architecture.Endianness); // 1. Offset to start writer1.Write(start, TypeLayout.NativePointerSize); // 2. Offset to end writer1.Write(end, TypeLayout.NativePointerSize); // 3. Offset to handler writer1.Write(handler, TypeLayout.NativePointerSize); // 4. Handler type writer1.Write((uint)handlerType, TypeLayout.NativePointerSize); // 5. Exception object type if (handlerType == ExceptionHandlerType.Exception) { // Store method table pointer of the exception object type // The VES exception runtime will uses this to compare exception object types MethodCompiler.Linker.Link(LinkType.AbsoluteAddress, NativePatchType, protectedRegionDefinitionSymbol, (int)writer1.Position, 0, exceptionType.FullName + Metadata.TypeDefinition, SectionKind.ROData, 0); } else if (handlerType == ExceptionHandlerType.Filter) { // TODO: There are no plans in the short term to support filtered exception clause as C# does not use them } else { } writer1.WriteZeroBytes(TypeLayout.NativePointerSize); // Return protectedRegionSymbol for linker usage return protectedRegionDefinitionSymbol; }
public void ReadBig(BinaryReader r, List <Instruction> body) { HandlerType = (ExceptionHandlerType)r.ReadUInt32(); uint offset = r.ReadUInt32(); TryStart = GetInstruction(offset, body); TryStartRaw = offset; var off2 = offset + r.ReadUInt32(); TryEnd = GetInstruction(off2, body); TryEndRaw = off2; offset = r.ReadUInt32(); HandlerStart = GetInstruction(offset, body); HandlerStartRaw = offset; var off3 = offset + r.ReadUInt32(); HandlerEnd = GetInstruction(off3, body); HandlerEndRaw = off3; if (HandlerType == ExceptionHandlerType.Catch) { CatchTypeToken = r.ReadUInt32(); } else if (HandlerType == ExceptionHandlerType.Filter) { var off4 = r.ReadUInt32(); FilterStart = GetInstruction(off4, body); FilterStartRaw = off4; } else { r.ReadUInt32(); } }
private void ComputeExceptionHandlerStackSize(ref Dictionary <Instruction, int> stack_sizes) { Collection <ExceptionHandler> exceptionHandlers = this.body.ExceptionHandlers; for (int i = 0; i < exceptionHandlers.Count; i++) { ExceptionHandler handler = exceptionHandlers[i]; ExceptionHandlerType handlerType = handler.HandlerType; switch (handlerType) { case ExceptionHandlerType.Catch: AddExceptionStackSize(handler.HandlerStart, ref stack_sizes); break; case ExceptionHandlerType.Filter: AddExceptionStackSize(handler.FilterStart, ref stack_sizes); AddExceptionStackSize(handler.HandlerStart, ref stack_sizes); break; default: break; } } }
/// <summary> /// Constructor /// </summary> /// <param name="handlerType">Exception clause type</param> public ExceptionHandler(ExceptionHandlerType handlerType) { this.HandlerType = handlerType; }
public ExceptionHandler(ExceptionHandlerType handlerType) { this.handler_type = handlerType; }
/// <summary> /// Reads the specified reader. /// </summary> /// <param name="reader">The reader.</param> /// <param name="isFat">if set to <c>true</c> [is fat].</param> public void Read(BinaryReader reader, bool isFat) { if (!isFat) { this.ExceptionHandler = (ExceptionHandlerType)reader.ReadInt16(); this.TryOffset = reader.ReadInt16(); this.TryLength = reader.ReadByte(); this.HandlerOffset = reader.ReadInt16(); this.HandlerLength = reader.ReadByte(); } else { this.ExceptionHandler = (ExceptionHandlerType)reader.ReadInt32(); this.TryOffset = reader.ReadInt32(); this.TryLength = reader.ReadInt32(); this.HandlerOffset = reader.ReadInt32(); this.HandlerLength = reader.ReadInt32(); } if (ExceptionHandlerType.Exception == this.ExceptionHandler) { this.ClassToken = reader.ReadUInt32(); } else if (ExceptionHandlerType.Filter == this.ExceptionHandler) { this.FilterOffset = reader.ReadInt32(); } else { reader.ReadInt32(); } }
public TryHandlerBlock(ExceptionHandler handler) { catchType = handler.CatchType; handlerType = handler.HandlerType; }
public ProtectedBlock(uint start, uint end, uint handler, ExceptionHandlerType kind, MosaType type, uint filter) { Start = start; End = end; Kind = kind; Handler = handler; Type = type; Filter = filter; }
private LinkerSymbol CreateProtectedRegionDefinition(string name, uint start, uint end, uint handler, ExceptionHandlerType handlerType, MosaType exceptionType) { // Emit parameter table var protectedRegionDefinitionSymbol = MethodCompiler.Linker.DefineSymbol(name, SectionKind.ROData, 0 /*TypeLayout.NativePointerAlignment*/, 0); var writer1 = new EndianAwareBinaryWriter(protectedRegionDefinitionSymbol.Stream, Architecture.Endianness); // 1. Offset to start writer1.Write(start, TypeLayout.NativePointerSize); // 2. Offset to end writer1.Write(end, TypeLayout.NativePointerSize); // 3. Offset to handler writer1.Write(handler, TypeLayout.NativePointerSize); // 4. Handler type writer1.Write((uint)handlerType, TypeLayout.NativePointerSize); // 5. Exception object type if (handlerType == ExceptionHandlerType.Exception) { // Store method table pointer of the exception object type // The VES exception runtime will uses this to compare exception object types Linker.Link(LinkType.AbsoluteAddress, NativePatchType, protectedRegionDefinitionSymbol, writer1.Position, Metadata.TypeDefinition + exceptionType.FullName, 0); } else if (handlerType == ExceptionHandlerType.Filter) { // TODO: There are no plans in the short term to support filtered exception clause as C# does not use them } else { } writer1.WriteZeroBytes(TypeLayout.NativePointerSize); // Return protectedRegionSymbol for linker usage return(protectedRegionDefinitionSymbol); }
private ExceptionHandler(ExceptionHandlerType handlerType) { HandlerType = handlerType; }
public ExceptionHandler(ExceptionHandlerType handlerType) { HandlerType = handlerType; }
public TryHandlerBlock(ExceptionHandler handler) { this.catchType = handler.CatchType; this.handlerType = handler.HandlerType; }
public ExceptionHandler (ExceptionHandlerType type) { m_type = type; }
public TryHandlerBlock(ExceptionHandler handler) { this.catchType = handler.CatchType; this.handlerType = handler.HandlerType; }
public ExceptionHandler(ExceptionHandlerType type) { m_type = type; }