Typesafe coop handles for all platforms. (#11012)
commit44db64c620c2c957a49b3f5a69cb09c19c1c8c1a
authorJay Krell <jay.krell@cornell.edu>
Fri, 19 Oct 2018 21:13:28 +0000 (19 14:13 -0700)
committerGitHub <noreply@github.com>
Fri, 19 Oct 2018 21:13:28 +0000 (19 14:13 -0700)
tree0259edb92e50cca138c18be8af94d42873330b7e
parenteaaf83ef921323b3c10f62d0d5c7256c63228957
Typesafe coop handles for all platforms. (#11012)

This is an alternative or precursor to https://github.com/mono/mono/pull/10212.

 - Removes the dependency of some ABIs passing a pointer and a pointer in a struct the same.
 - Therefore gives all platforms the same type safety.
 - *If* we move to C++, allows us to have member functions in coop handles.
 -  Having the coop signatures available in C can provide  benefits, though we should
    probably generate them from reading metadata -- though they won't match w/o more changes,
    since we mixup types in several places, like IntPtr vs. pointers.

JIT now traffics in old type-unsafe handles, and wrappers are generated with C preprocessor to trivially convert.
 This way the JIT doesn't have to pass structs by value here, which was tried/failed.

The C preprocessor machinery can/should be extended for additional gains.
In particular driving managed/native coop icall transitions from 3+ per call to 1 (like https://github.com/mono/mono/pull/10212).

That will require better verification of the signatures in icall-def.h, either automated and en masses or gradually manually. Embedders will likely do something else, or at least have to independently invent similar.

Whereever a native function was exposed via multiple managed names, wrappers are reused.
16 files changed:
mono/metadata/Makefile.am
mono/metadata/handle-decl.h
mono/metadata/handle.c
mono/metadata/handle.h
mono/metadata/icall-decl.h
mono/metadata/icall-def.h
mono/metadata/icall-table.c
mono/metadata/icall-table.h
mono/metadata/icall.c
mono/metadata/marshal-ilgen.c
mono/metadata/marshal.c
mono/metadata/marshal.h
mono/metadata/object-offsets.h
mono/metadata/object.h
mono/utils/mono-publib.h
tools/offsets-tool/MonoAotOffsetsDumper.cs