From 7a27990faa557c5c93f52e5cb082d551ad119ed0 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 12 Mar 2018 01:04:52 -0300 Subject: Allow more than one process, free resources on process dispose, implement SvcExitThread --- ChocolArm64/Instruction/AInstEmitException.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ChocolArm64/Instruction') diff --git a/ChocolArm64/Instruction/AInstEmitException.cs b/ChocolArm64/Instruction/AInstEmitException.cs index fe348edd..3964c949 100644 --- a/ChocolArm64/Instruction/AInstEmitException.cs +++ b/ChocolArm64/Instruction/AInstEmitException.cs @@ -34,6 +34,22 @@ namespace ChocolArm64.Instruction Context.EmitCall(MthdInfo); + //Check if the thread should still be running, if it isn't then we return 0 + //to force a return to the dispatcher and then exit the thread. + Context.EmitLdarg(ATranslatedSub.StateArgIdx); + + Context.EmitCallPropGet(typeof(AThreadState), nameof(AThreadState.Running)); + + AILLabel LblEnd = new AILLabel(); + + Context.Emit(OpCodes.Brtrue_S, LblEnd); + + Context.EmitLdc_I8(0); + + Context.Emit(OpCodes.Ret); + + Context.MarkLabel(LblEnd); + if (Context.CurrBlock.Next != null) { Context.EmitLoadState(Context.CurrBlock.Next); -- cgit v1.2.3