Skip to content

Instantly share code, notes, and snippets.

@NattyNarwhal
Created March 6, 2018 01:59
Show Gist options
  • Save NattyNarwhal/52b953f5416b92a3af1b1d1635d7cfe7 to your computer and use it in GitHub Desktop.
Save NattyNarwhal/52b953f5416b92a3af1b1d1635d7cfe7 to your computer and use it in GitHub Desktop.
more songs about trampolines and food
diff --git a/mono/mini/mini-ppc.c b/mono/mini/mini-ppc.c
index 8a32046..5cfca95 100644
--- a/mono/mini/mini-ppc.c
+++ b/mono/mini/mini-ppc.c
@@ -800,6 +800,7 @@ mono_arch_flush_icache (guint8 *code, gint size)
if (!(cpu_hw_caps & PPC_ISA_2X))
asm ("sync");
asm ("isync");
+ __builtin___clear_cache (start, endp);
#endif
#endif
}
diff --git a/mono/mini/tramp-ppc.c b/mono/mini/tramp-ppc.c
index bfbeca9..87fab97 100644
--- a/mono/mini/tramp-ppc.c
+++ b/mono/mini/tramp-ppc.c
@@ -241,10 +241,10 @@ guchar*
mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
{
char *tramp_name;
- guint8 *buf, *code = NULL;
+ guint8 *buf, *code = NULL, *exception_branch;
int i, offset;
gconstpointer tramp_handler;
- int size = MONO_PPC_32_64_CASE (600, 800);
+ int size = MONO_PPC_32_64_CASE (700, 900);
GSList *unwind_ops = NULL;
MonoJumpInfo *ji = NULL;
@@ -365,16 +365,15 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
ppc_blrl (code);
}
- /* OK, code address is now on r3. Move it to the counter reg
- * so it will be ready for the final jump: this is safe since we
- * won't do any more calls.
+ /* OK, code address is now on r3. Move it to r14 because we need
+ * to still do exception checks.
*/
if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
#ifdef PPC_USES_FUNCTION_DESCRIPTOR
ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r3);
ppc_ldptr (code, ppc_r3, 0, ppc_r3);
#endif
- ppc_mtctr (code, ppc_r3);
+ ppc_mr (code, ppc_r14, ppc_r3);
}
/*
@@ -390,6 +389,47 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r12);
/* *(lmf_addr) = previous_lmf */
ppc_stptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r6);
+
+ /* thread interruption check */
+ if (aot) {
+ g_error ("Not implemented");
+ } else {
+ gconstpointer checkpoint = mono_thread_force_interruption_checkpoint_noraise;
+ ppc_load_func (code, PPC_CALL_REG, checkpoint);
+ ppc_mtlr (code, PPC_CALL_REG);
+ }
+ ppc_blrl (code);
+
+ ppc_compare_reg_imm (code, 0, ppc_r3, 0); // is there an exception?
+ exception_branch = code;
+ ppc_break (code); // will be rewritten
+ //ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
+
+ /* exception */
+ ppc_ldr (code, ppc_r1, 0, ppc_r1);
+ ppc_ldr (code, ppc_r12, PPC_RET_ADDR_OFFSET, ppc_r1);
+ ppc_mtlr (code, ppc_r12);
+
+ if (aot) {
+ g_error ("Not implemented");
+ } else {
+ gconstpointer throw = mono_get_throw_exception_addr ();
+ ppc_load_func (code, PPC_CALL_REG, throw);
+ ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG);
+ ppc_mtctr (code, PPC_CALL_REG);
+ }
+ ppc_bcctr (code, 20, 0);
+
+ ppc_break (code); //never reach, inject branch replacement above?
+
+ /* rewrite the trap above to a branch */
+ ppc_bc (exception_branch, PPC_BR_TRUE, PPC_BR_EQ, (code - exception_branch));
+ //ppc_patch (exception_branch, code);
+
+ /* no exception, move r14 to ctr and carry on */
+ ppc_mtctr (code, ppc_r14);
+ ppc_addi (code, ppc_r12, ppc_r1, STACK - sizeof (MonoLMF));
+
/* restore iregs */
ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r12);
/* restore fregs */
*** The runtime 'mono' doesn't appear to be usable.
*** Trying the 'monolite-linux/1051300002' directory.
mono_thread_internal_set_priority: pthread_setschedparam failed, error: "Operation not permitted." (1)
Unhandled Exception:
[ERROR] FATAL UNHANDLED EXCEPTION: Nested exception trying to figure out what went wrong
gmake[8]: *** [build/profiles/basic.make:116: build/deps/basic-profile-check.exe] Error 1
*** The contents of your 'monolite-linux/1051300002' directory may be out-of-date
*** You may want to try 'make get-monolite-latest'
gmake[8]: *** [build/profiles/basic.make:98: do-profile-check-monolite] Error 1
gmake[7]: *** [build/profiles/basic.make:74: do-profile-check] Error 2
gmake[6]: *** [build/profiles/basic.make:110: do-profile-check-monolite] Error 2
gmake[5]: *** [build/profiles/basic.make:74: do-profile-check] Error 2
gmake[4]: *** [Makefile:54: profile-do--basic--all] Error 2
gmake[3]: *** [Makefile:50: profiles-do--all] Error 2
gmake[2]: *** [Makefile:613: all-local] Error 2
gmake[2]: Leaving directory '/opt/monodev/mono/runtime'
gmake[1]: *** [Makefile:558: all-recursive] Error 1
gmake[1]: Leaving directory '/opt/monodev/mono'
gmake: *** [Makefile:488: all] Error 2
$ (reverse-i-search)`LIB': LIBPATH=mono/mini/.libs/ mono/mini/mono-sgen --trace=all -v ~/exception.exe
converting method void System.OutOfMemoryException:.ctor (string)
Method void System.OutOfMemoryException:.ctor (string) emitted at 700000000083600 to 7000000000836ec (code length 236) [exception.exe]
converting method (wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)
Method (wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr) emitted at 700000000083780 to 7000000000839f0 (code length 624) [exception.exe]
[1: 0.00000 0] ENTER: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.00016 1] ENTER: System.OutOfMemoryException:.ctor (string)() ip: 700000000083934
converting method void System.SystemException:.ctor (string)
Method void System.SystemException:.ctor (string) emitted at 7000000000839f0 to 700000000083adc (code length 236) [exception.exe]
converting method void System.Exception:SetErrorCode (int)
Method void System.Exception:SetErrorCode (int) emitted at 700000000083b10 to 700000000083bcc (code length 188) [exception.exe]
converting method void System.Exception:.cctor ()
Method void System.Exception:.cctor () emitted at 700000000083c00 to 700000000083cd8 (code length 216) [exception.exe]
converting method (wrapper runtime-invoke) object object:runtime_invoke_void (object,intptr,intptr,intptr)
Method (wrapper runtime-invoke) object object:runtime_invoke_void (object,intptr,intptr,intptr) emitted at 700000000083d08 to 700000000083f60 (code length 600) [exception.exe]
[1: 0.00165 2] ENTER: (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.00174 3] ENTER: System.Exception:.cctor ()() ip: 700000000083e14
converting method (wrapper alloc) object object:AllocSmall (intptr,intptr)
Method (wrapper alloc) object object:AllocSmall (intptr,intptr) emitted at 700000000083f90 to 700000000084164 (code length 468) [exception.exe]
[1: 0.00219 3] LEAVE: System.Exception:.cctor ()
[1: 0.00228 2] LEAVE: (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)[OBJECT:0]
[1: 0.00238 1] LEAVE: System.OutOfMemoryException:.ctor (string)
[1: 0.00247 0] LEAVE: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)[OBJECT:0]
converting method void System.NullReferenceException:.ctor (string)
Method void System.NullReferenceException:.ctor (string) emitted at 700000000084168 to 700000000084270 (code length 264) [exception.exe]
[1: 0.00295 0] ENTER: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.00304 1] ENTER: System.NullReferenceException:.ctor (string)() ip: 700000000083934
[1: 0.00313 1] LEAVE: System.NullReferenceException:.ctor (string)
[1: 0.00323 0] LEAVE: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)[OBJECT:0]
converting method void System.StackOverflowException:.ctor (string)
Method void System.StackOverflowException:.ctor (string) emitted at 700000000084270 to 700000000084378 (code length 264) [exception.exe]
[1: 0.00368 0] ENTER: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.00377 1] ENTER: System.StackOverflowException:.ctor (string)() ip: 700000000083934
[1: 0.00387 1] LEAVE: System.StackOverflowException:.ctor (string)
[1: 0.00396 0] LEAVE: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)[OBJECT:0]
mono_thread_internal_set_priority: pthread_setschedparam failed, error: "Operation not permitted." (1)
converting method void Entry:Main ()
Method void Entry:Main () emitted at 700000000084378 to 700000000084424 (code length 172) [exception.exe]
converting method (wrapper runtime-invoke) object object:runtime_invoke_void (object,intptr,intptr,intptr)
Method (wrapper runtime-invoke) object object:runtime_invoke_void (object,intptr,intptr,intptr) emitted at 700000000084458 to 7000000000846b0 (code length 600) [exception.exe]
[1: 0.00874 0] ENTER: (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.00876 1] ENTER: Entry:Main ()() ip: 7000000000845f4
converting method void Offending:Hello ()
Method void Offending:Hello () emitted at 7000000000846e0 to 7000000000847ec (code length 268) [exception.exe]
converting method void Offending:.cctor ()
Method void Offending:.cctor () emitted at 700000000084850 to 700000000084968 (code length 280) [exception.exe]
[1: 0.00916 2] ENTER: (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.00919 3] ENTER: Offending:.cctor ()() ip: 700000000084564
converting method (wrapper managed-to-native) object object:__icall_wrapper_mono_helper_ldstr (intptr,intptr)
Method (wrapper managed-to-native) object object:__icall_wrapper_mono_helper_ldstr (intptr,intptr) emitted at 700000000084998 to 700000000084c48 (code length 688) [exception.exe]
converting method void System.Exception:.ctor (string)
Method void System.Exception:.ctor (string) emitted at 700000000084c48 to 700000000084d80 (code length 312) [exception.exe]
[1: 0.00958 4] ENTER: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.00960 5] ENTER: System.Exception:.ctor (string)() ip: 700000000083934
converting method void System.Exception:Init ()
Method void System.Exception:Init () emitted at 700000000084db0 to 700000000084f34 (code length 388) [exception.exe]
[1: 0.00992 5] LEAVE: System.Exception:.ctor (string)
[1: 0.00995 4] LEAVE: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)[OBJECT:0]
converting method string System.Exception:get_Message ()
Method string System.Exception:get_Message () emitted at 700000000084f38 to 700000000085154 (code length 540) [exception.exe]
converting method (wrapper runtime-invoke) object <Module>:runtime_invoke_object__this__ (object,intptr,intptr,intptr)
Method (wrapper runtime-invoke) object <Module>:runtime_invoke_object__this__ (object,intptr,intptr,intptr) emitted at 7000000000851e8 to 700000000085450 (code length 616) [exception.exe]
[1: 0.01233 4] ENTER: (wrapper runtime-invoke) <Module>:runtime_invoke_object__this__ (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.01242 5] ENTER: System.Exception:get_Message ()() ip: 7000000000852f8
converting method string System.Exception:GetClassName ()
Method string System.Exception:GetClassName () emitted at 700000000085450 to 7000000000855b0 (code length 352) [exception.exe]
converting method (wrapper alloc) object object:AllocVector (intptr,intptr)
Method (wrapper alloc) object object:AllocVector (intptr,intptr) emitted at 7000000000855e0 to 70000000008598c (code length 940) [exception.exe]
converting method void System.NullReferenceException:.ctor ()
Method void System.NullReferenceException:.ctor () emitted at 700000000085990 to 700000000085aa4 (code length 276) [exception.exe]
converting method (wrapper runtime-invoke) object object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
Method (wrapper runtime-invoke) object object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) emitted at 700000000085aa8 to 700000000085d08 (code length 608) [exception.exe]
[1: 0.01409 6] ENTER: (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.01417 7] ENTER: System.NullReferenceException:.ctor ()() ip: 700000000085c4c
[1: 0.01425 7] LEAVE: System.NullReferenceException:.ctor ()
[1: 0.01433 6] LEAVE: (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)[OBJECT:0]
[1: 0.01443 6] ENTER: (wrapper runtime-invoke) <Module>:runtime_invoke_object__this__ (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.01452 7] ENTER: System.Exception:get_Message ()() ip: 7000000000852f8
[1: 0.01459 8] ENTER: System.Exception:GetClassName ()() ip: 700000000084fd4
converting method string System.RuntimeType:ToString ()
Method string System.RuntimeType:ToString () emitted at 700000000085d08 to 700000000085dd0 (code length 200) [exception.exe]
converting method void System.RuntimeType:.cctor ()
Method void System.RuntimeType:.cctor () emitted at 700000000085e00 to 700000000086110 (code length 784) [exception.exe]
[1: 0.01556 9] ENTER: (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)() ip: 900000007e708a8
[1: 0.01564 10] ENTER: System.RuntimeType:.cctor ()() ip: 700000000083e14
[1: 0.01572 10] LEAVE: System.RuntimeType:.cctor ()
[1: 0.01580 9] LEAVE: (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)[OBJECT:0]
[1: 0.01588 8] LEAVE: System.Exception:GetClassName ()[OBJECT:0]
[1: 0.01597 8] ENTER: (wrapper alloc) object:AllocVector (intptr,intptr)() ip: 700000000085050
[1: 0.01605 8] LEAVE: (wrapper alloc) object:AllocVector (intptr,intptr)[System.Object[]:7000000004005c8]
converting method (wrapper stelemref) void object:virt_stelemref_object (intptr,object)
Method (wrapper stelemref) void object:virt_stelemref_object (intptr,object) emitted at 700000000086110 to 700000000086274 (code length 356) [exception.exe]
converting method string System.Environment:GetResourceString (string,object[])
Method string System.Environment:GetResourceString (string,object[]) emitted at 700000000086278 to 700000000086364 (code length 236) [exception.exe]
[1: 0.01670 7] LEAVE: System.Exception:get_Message ()[OBJECT:0]
[1: 0.01685 6] LEAVE: (wrapper runtime-invoke) <Module>:runtime_invoke_object__this__ (object,intptr,intptr,intptr)[OBJECT:0]
[1:] EXCEPTION handling: System.NullReferenceException: (System.Exception.Message property not available)
EXCEPTION: catch found at clause 0 of (wrapper runtime-invoke) <Module>:runtime_invoke_object__this__ (object,intptr,intptr,intptr)
[1: 0.01716 5] LEAVE: (wrapper runtime-invoke) <Module>:runtime_invoke_object__this__ (object,intptr,intptr,intptr)[OBJECT:0]
* Assertion at mini-exceptions.c:1976, condition `exc == NULL' not met
Stacktrace:
at <unknown> <0xffffffff>
at Entry.Main () [0x00005] in <59f53618e91349c388e3e2bc22135e36>:0
at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) [0x0004c] in <ed20377020504649863303af004d6a67>:0
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
IOT/Abort trap (core dumped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment