/// <summary> /// Generates the exception handlers /// </summary> /// <param name="memoryManager">The memory manager</param> /// <param name="callingConventions">The calling conventions</param> public void GenerateHandlers(MemoryManager memoryManager, CallingConventions callingConventions) { var handlerCode = new List <byte>(); var assembler = new Assembler(handlerCode); //Create handler calls var nullHandlerOffset = this.CreateHandlerCall(assembler, callingConventions, RuntimeInterface.NullReferenceError); var arrayBoundsHandlerOffset = this.CreateHandlerCall(assembler, callingConventions, RuntimeInterface.ArrayOutOfBoundsError); var arrayCreationHandler = this.CreateHandlerCall(assembler, callingConventions, RuntimeInterface.InvalidArrayCreation); var stackOverflowHandler = this.CreateHandlerCall(assembler, callingConventions, RuntimeInterface.StackOverflow); //Allocate and copy memory var handlerMemory = memoryManager.AllocateCode(handlerCode.Count); NativeHelpers.CopyTo(handlerMemory, handlerCode); //Set the pointers to the handlers this.nullCheckHandler = handlerMemory + nullHandlerOffset; this.arrayBoundsCheckHandler = handlerMemory + arrayBoundsHandlerOffset; this.arrayCreationCheckHandler = handlerMemory + arrayCreationHandler; this.stackOverflowCheckHandler = handlerMemory + stackOverflowHandler; }