Interpreter reads last error to late after pinvoke. (#15571)
commitb1b61d7cb7f580f5e5438a756ef3e67a5a832eeb
authorJohan Lorensson <lateralusx.github@gmail.com>
Fri, 5 Jul 2019 08:30:17 +0000 (5 10:30 +0200)
committerGitHub <noreply@github.com>
Fri, 5 Jul 2019 08:30:17 +0000 (5 10:30 +0200)
treed776df20c82b209d7f83047812651e314dd618ee
parenta90b735cf8532ed7658f0098f704ad38786801cc
Interpreter reads last error to late after pinvoke. (#15571)

* Interpreter reads last error to late after pinvoke.

This could lead to clobbered last error since interpreter loop needs to
run two additional IL instructions in order to read out the value. This works
on JIT since the lowering saving the last error will happen right after
pinvoke.

This fix makes sure interpreter will get needed information to read out
last error right after pinvoke (if requested).

It adds a new IL prefix issued in managed->native wrapper that will tell
codegen (and interpreter) that upcoming calli instruction needs to save
last error, meaning that it could be done right after issuing the call,
no need to run any additional IL instructions to do that work, closing
the gap between the return of pinvoke call and save of last error.

Should fix, https://github.com/mono/mono/issues/15541.

* Optimize emit_get_last_error.
mono/cil/cil-opcodes.xml
mono/cil/opcode.def
mono/metadata/marshal-ilgen.c
mono/mini/cpu-x86.md
mono/mini/interp/interp.c
mono/mini/interp/mintops.def
mono/mini/interp/transform.c
mono/mini/method-to-ir.c
mono/mini/mini-amd64.c
mono/mini/mini-x86.c