@@ -829,110 +829,6 @@ mono_arch_ip_from_context (void *sigctx)
829829#endif
830830}
831831
832- static MonoObject *
833- restore_soft_guard_pages (void )
834- {
835- MonoJitTlsData * jit_tls = mono_tls_get_jit_tls ();
836- if (jit_tls -> stack_ovf_guard_base )
837- mono_mprotect (jit_tls -> stack_ovf_guard_base , jit_tls -> stack_ovf_guard_size , MONO_MMAP_NONE );
838-
839- if (jit_tls -> stack_ovf_pending ) {
840- jit_tls -> stack_ovf_pending = 0 ;
841- return (MonoObject * )mini_get_stack_overflow_ex ();
842- }
843-
844- return NULL ;
845- }
846-
847- /*
848- * this function modifies mctx so that when it is restored, it
849- * won't execcute starting at mctx.eip, but in a function that
850- * will restore the protection on the soft-guard pages and return back to
851- * continue at mctx.eip.
852- */
853- static void
854- prepare_for_guard_pages (MonoContext * mctx )
855- {
856- gpointer * sp ;
857- sp = (gpointer * )(mctx -> gregs [AMD64_RSP ]);
858- sp -= 1 ;
859- /* the return addr */
860- sp [0 ] = (gpointer )(mctx -> gregs [AMD64_RIP ]);
861- mctx -> gregs [AMD64_RIP ] = (guint64 )restore_soft_guard_pages ;
862- mctx -> gregs [AMD64_RSP ] = (guint64 )sp ;
863- }
864-
865- static void
866- altstack_handle_and_restore (MonoContext * ctx , MonoObject * obj , guint32 flags )
867- {
868- MonoContext mctx ;
869- MonoJitInfo * ji = mini_jit_info_table_find (MONO_CONTEXT_GET_IP (ctx ));
870- gboolean stack_ovf = (flags & 1 ) != 0 ;
871- gboolean nullref = (flags & 2 ) != 0 ;
872-
873- if (!ji || (!stack_ovf && !nullref )) {
874- mono_handle_native_crash (mono_get_signame (SIGSEGV ), ctx , NULL );
875- // if couldn't dump or if mono_handle_native_crash returns, abort
876- abort ();
877- }
878-
879- mctx = * ctx ;
880-
881- mono_handle_exception (& mctx , obj );
882- if (stack_ovf ) {
883- MonoJitTlsData * jit_tls = mono_tls_get_jit_tls ();
884- jit_tls -> stack_ovf_pending = 1 ;
885- prepare_for_guard_pages (& mctx );
886- }
887- mono_restore_context (& mctx );
888- }
889-
890- void
891- mono_arch_handle_altstack_exception (void * sigctx , MONO_SIG_HANDLER_INFO_TYPE * siginfo , gpointer fault_addr , gboolean stack_ovf )
892- {
893- #if defined(MONO_ARCH_USE_SIGACTION )
894- MonoException * exc = NULL ;
895- gpointer * sp ;
896- MonoJitTlsData * jit_tls = NULL ;
897- MonoContext * copied_ctx = NULL ;
898- gboolean nullref = TRUE;
899-
900- jit_tls = mono_tls_get_jit_tls ();
901- g_assert (jit_tls );
902-
903- /* use TLS as temporary storage as we want to avoid
904- * (1) stack allocation on the application stack
905- * (2) calling malloc, because it is not async-safe
906- * (3) using a global storage, because this function is not reentrant
907- *
908- * tls->orig_ex_ctx is used by the stack walker, which shouldn't be running at this point.
909- */
910- copied_ctx = & jit_tls -> orig_ex_ctx ;
911-
912- if (!mono_is_addr_implicit_null_check (fault_addr ))
913- nullref = FALSE;
914-
915- if (stack_ovf )
916- exc = mini_get_stack_overflow_ex ();
917-
918- /* setup the call frame on the application stack so that control is
919- * returned there and exception handling can continue. we want the call
920- * frame to be minimal as possible, for example no argument passing that
921- * requires allocation on the stack, as this wouldn't be encoded in unwind
922- * information for the caller frame.
923- */
924- sp = (gpointer * ) ALIGN_DOWN_TO (UCONTEXT_REG_RSP (sigctx ), 16 );
925- sp [-1 ] = (gpointer )UCONTEXT_REG_RIP (sigctx );
926- mono_sigctx_to_monoctx (sigctx , copied_ctx );
927- /* at the return from the signal handler execution starts in altstack_handle_and_restore() */
928- UCONTEXT_REG_RIP (sigctx ) = (unsigned long )altstack_handle_and_restore ;
929- UCONTEXT_REG_RSP (sigctx ) = (unsigned long )(sp - 1 );
930- UCONTEXT_REG_RDI (sigctx ) = (unsigned long )(copied_ctx );
931- UCONTEXT_REG_RSI (sigctx ) = (guint64 )exc ;
932- UCONTEXT_REG_RDX (sigctx ) = (stack_ovf ? 1 : 0 ) | (nullref ? 2 : 0 );
933- #endif
934- }
935-
936832#ifndef DISABLE_JIT
937833GSList *
938834mono_amd64_get_exception_trampolines (gboolean aot )
0 commit comments