+Fri Sep 26 17:00:46 CEST 2008 Paolo Molaro <lupus@ximian.com>
+
+ * mini-amd64.c, mini-amd64.h, tramp-amd64.c: amd64 support code for calling a
+ runtime-set function when going back to managed code. Currently this
+ is used to set back the protection on the soft ovf pages and/or to
+ throw the stack overflow exception that happened in unmanaged code.
+
Fri Sep 26 16:46:23 CEST 2008 Paolo Molaro <lupus@ximian.com>
* tramp-x86.c, mini-x86.h, mini-x86.c: x86 support code for calling a
pos = 0;
if (method->save_lmf) {
+ /* check if we need to restore protection of the stack after a stack overflow */
+ if (mono_get_jit_tls_offset () != -1) {
+ guint8 *patch;
+ code = emit_tls_get (code, X86_ECX, mono_get_jit_tls_offset ());
+ /* we load the value in a separate instruction: this mechanism may be
+ * used later as a safer way to do thread interruption
+ */
+ amd64_mov_reg_membase (code, X86_ECX, X86_ECX, G_STRUCT_OFFSET (MonoJitTlsData, restore_stack_prot), 8);
+ x86_alu_reg_imm (code, X86_CMP, X86_ECX, 0);
+ patch = code;
+ x86_branch8 (code, X86_CC_Z, 0, FALSE);
+ /* note that the call trampoline will preserve eax/edx */
+ x86_call_reg (code, X86_ECX);
+ x86_patch (patch, code);
+ } else {
+ /* FIXME: maybe save the jit tls in the prolog */
+ }
if ((lmf_tls_offset != -1) && !optimize_for_xen) {
/*
* Optimized version which uses the mono_lmf TLS variable instead of indirection
for (quad = 0; quad < 2; quad ++) {
switch (ainfo->pair_storage [quad]) {
case ArgInIReg:
+ /* check if we need to restore protection of the stack after a stack overflow */
+ if (mono_get_jit_tls_offset () != -1) {
+ guint8 *patch;
+ code = emit_tls_get (code, X86_ECX, mono_get_jit_tls_offset ());
+ /* we load the value in a separate instruction: this mechanism may be
+ * used later as a safer way to do thread interruption
+ */
+ x86_mov_reg_membase (code, X86_ECX, X86_ECX, G_STRUCT_OFFSET (MonoJitTlsData, restore_stack_prot), 4);
+ x86_alu_reg_imm (code, X86_CMP, X86_ECX, 0);
+ patch = code;
+ x86_branch8 (code, X86_CC_Z, 0, FALSE);
+ /* note that the call trampoline will preserve eax/edx */
+ x86_call_reg (code, X86_ECX);
+ x86_patch (patch, code);
+ } else {
+ /* FIXME: maybe save the jit tls in the prolog */
+ }
amd64_mov_reg_membase (code, ainfo->pair_regs [quad], inst->inst_basereg, inst->inst_offset + (quad * sizeof (gpointer)), sizeof (gpointer));
break;
case ArgInFloatSSEReg:
for (i = 0; i < 8; ++i)
amd64_movsd_reg_membase (code, i, AMD64_RBP, saved_fpregs_offset + (i * 8));
+ if (tramp_type == MONO_TRAMPOLINE_RESTORE_STACK_PROT)
+ amd64_mov_reg_membase (code, AMD64_RAX, AMD64_RBP, saved_regs_offset + (AMD64_RAX * 8), 8);
+
/* Restore stack */
amd64_leave (code);
if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT ||
tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT ||
+ tramp_type == MONO_TRAMPOLINE_RESTORE_STACK_PROT ||
tramp_type == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
amd64_ret (code);
else {