<opcode name="mono_calli_extra_arg" input="VarPop" output="VarPush" args="InlineSig" o1="0xF0" o2="0x18" flow="call" />
<opcode name="mono_lddomain" input="Pop0" output="PushI" args="InlineNone" o1="0xF0" o2="0x19" flow="next" />
<opcode name="mono_atomic_store_i4" input="PopI+PopI" output="Push0" args="InlineI" o1="0xF0" o2="0x1A" flow="next" />
+<opcode name="mono_get_last_error" input="Pop0" output="PushI" args="InlineI" o1="0xF0" o2="0x1B" flow="next" />
</opdesc>
OPDEF(CEE_MONO_CALLI_EXTRA_ARG, "mono_calli_extra_arg", VarPop, VarPush, InlineSig, X, 2, 0xF0, 0x18, CALL)
OPDEF(CEE_MONO_LDDOMAIN, "mono_lddomain", Pop0, PushI, InlineNone, X, 2, 0xF0, 0x19, NEXT)
OPDEF(CEE_MONO_ATOMIC_STORE_I4, "mono_atomic_store_i4", PopI+PopI, Push0, InlineI, X, 2, 0xF0, 0x1A, NEXT)
+OPDEF(CEE_MONO_GET_LAST_ERROR, "mono_get_last_error", Pop0, PushI, InlineI, X, 2, 0xF0, 0x1B, NEXT)
#ifndef OPALIAS
#define _MONO_CIL_OPALIAS_DEFINED_
#define OPALIAS(a,s,r)
/* Set LastError if needed */
if (piinfo->piflags & PINVOKE_ATTRIBUTE_SUPPORTS_LAST_ERROR) {
#ifdef TARGET_WIN32
- static MonoMethodSignature *get_last_error_sig = NULL;
- if (!get_last_error_sig) {
- get_last_error_sig = mono_metadata_signature_alloc (mono_defaults.corlib, 0);
- get_last_error_sig->ret = &mono_defaults.int_class->byval_arg;
- get_last_error_sig->pinvoke = 1;
- }
+ if (!aot) {
+ static MonoMethodSignature *get_last_error_sig = NULL;
+ if (!get_last_error_sig) {
+ get_last_error_sig = mono_metadata_signature_alloc (mono_defaults.corlib, 0);
+ get_last_error_sig->ret = &mono_defaults.int_class->byval_arg;
+ get_last_error_sig->pinvoke = 1;
+ }
- /*
- * Have to call GetLastError () early and without a wrapper, since various runtime components could
- * clobber its value.
- */
- mono_mb_emit_native_call (mb, get_last_error_sig, GetLastError);
- mono_mb_emit_icall (mb, mono_marshal_set_last_error_windows);
+ /*
+ * Have to call GetLastError () early and without a wrapper, since various runtime components could
+ * clobber its value.
+ */
+ mono_mb_emit_native_call (mb, get_last_error_sig, GetLastError);
+ mono_mb_emit_icall (mb, mono_marshal_set_last_error_windows);
+ }
+ else
+ {
+ mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
+ mono_mb_emit_byte (mb, CEE_MONO_GET_LAST_ERROR);
+ mono_mb_emit_icall (mb, mono_marshal_set_last_error_windows);
+ }
#else
mono_mb_emit_icall (mb, mono_marshal_set_last_error);
#endif
gc_param_slot_liveness_def: len:0
generic_class_init: src1:A len:32 clob:c
+get_last_error: dest:i len:32
case CEE_MONO_LDDOMAIN:
CHECK_STACK_OVF (1);
EMIT_NEW_PCONST (cfg, ins, cfg->compile_aot ? NULL : cfg->domain);
+ ip += 2;
+ *sp++ = ins;
+ break;
+ case CEE_MONO_GET_LAST_ERROR:
+ CHECK_OPSIZE (2);
+ CHECK_STACK_OVF (1);
+
+ MONO_INST_NEW (cfg, ins, OP_GET_LAST_ERROR);
+ ins->dreg = alloc_dreg (cfg, STACK_I4);
+ ins->type = STACK_I4;
+ MONO_ADD_INS (cfg->cbb, ins);
+
ip += 2;
*sp++ = ins;
break;
* Dietmar Maurer (dietmar@ximian.com)
* Patrik Torstensson
* Zoltan Varga (vargaz@gmail.com)
+ * Johan Lorensson (lateralusx.github@gmail.com)
*
* (C) 2003 Ximian, Inc.
* Copyright 2003-2011 Novell, Inc (http://www.novell.com)
return code;
}
+#ifdef TARGET_WIN32
+
+#define TEB_LAST_ERROR_OFFSET 0x068
+
+static guint8*
+emit_get_last_error (guint8* code, int dreg)
+{
+ /* Threads last error value is located in TEB_LAST_ERROR_OFFSET. */
+ x86_prefix (code, X86_GS_PREFIX);
+ amd64_mov_reg_membase (code, dreg, TEB_LAST_ERROR_OFFSET, 0, sizeof (guint32));
+
+ return code;
+}
+
+#else
+
+static guint8*
+emit_get_last_error (guint8* code, int dreg)
+{
+ g_assert_not_reached ();
+}
+
+#endif
+
/* benchmark and set based on cpu */
#define LOOP_ALIGNMENT 8
#define bb_is_loop_start(bb) ((bb)->loop_body_start && (bb)->nesting)
ins->backend.pc_offset = code - cfg->native_code;
bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
break;
+ case OP_GET_LAST_ERROR:
+ emit_get_last_error(code, ins->dreg);
+ break;
default:
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_assert_not_reached ();
MINI_OP(OP_GET_SP, "get_sp", IREG, NONE, NONE)
MINI_OP(OP_SET_SP, "set_sp", NONE, IREG, NONE)
+MINI_OP(OP_GET_LAST_ERROR, "get_last_error", IREG, NONE, NONE)