Interpreter reads last error to late after pinvoke. (mono/mono#15571)
authorJohan Lorensson <lateralusx.github@gmail.com>
Fri, 5 Jul 2019 08:30:17 +0000 (10:30 +0200)
committerGitHub <noreply@github.com>
Fri, 5 Jul 2019 08:30:17 +0000 (10:30 +0200)
commitf3bb4fb663ce6ca20b6565178cbd1f3980ccfab1
treeaae34237b90ccf4a802cb1ed245afe2b747c518a
parentac18ca1116fed3b29c34544403a816ed4790ac8a
Interpreter reads last error to late after pinvoke. (mono/mono#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.

Commit migrated from https://github.com/mono/mono/commit/b1b61d7cb7f580f5e5438a756ef3e67a5a832eeb
src/mono/mono/cil/cil-opcodes.xml
src/mono/mono/cil/opcode.def
src/mono/mono/metadata/marshal-ilgen.c
src/mono/mono/mini/cpu-x86.md
src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/interp/mintops.def
src/mono/mono/mini/interp/transform.c
src/mono/mono/mini/method-to-ir.c
src/mono/mono/mini/mini-amd64.c
src/mono/mono/mini/mini-x86.c