Skip to content

Commit

Permalink
[MonoAPI] Split type and function headers, add MONO_API_FUNCTION macro (
Browse files Browse the repository at this point in the history
dotnet#65446)

* [monoapi] Split type and function headers, add MONO_API_FUNCTION macro

The idea is that the function header can be included multiple times with different definitions of MONO_API_FUNCTION in order to make it easier to re-used the definitions for embedding the runtime in late-binding scenarios

* rename public mono/mini subdirectory to mono/jit

  To match how embedders see the tree.

  Update the runtime to include <mono/jit/jit.h> instead of <mono/mini/jit.h>.

  No change in public API

* Add needed includes to mobile testing host templates

* add unstable API comment to the details headers, too

* use install(FILES) to copy the headers

  not other stray files to the include dir

* update CODEOWNERS

* Remove duplicate definitions of mono_event_get_remove_method

  This was already duplicated before the header reorganization, e.g. here https://github.com/dotnet/runtime/blob/b9a55b4f52243325359ced26e3d4b31ccacdc381/src/native/public/mono/metadata/class.h#L279-L282
  • Loading branch information
lambdageek authored Feb 24, 2022
1 parent 3f99a86 commit 858221c
Show file tree
Hide file tree
Showing 103 changed files with 3,402 additions and 3,251 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

/src/mono/dlls @thaystg @lambdageek

/src/native/public/mono @marek-safar @lambdageek

# Obsoletions / Custom Diagnostics

/docs/project/list-of-diagnostics.md @jeffhandley
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eventpipe/test/ep-setup-tests.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <eventpipe/ep.h>
#include <eglib/test/test.h>
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>

MonoDomain *eventpipe_test_domain;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eventpipe/test/ep-teardown-tests.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <eventpipe/ep.h>
#include <eglib/test/test.h>
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>

#define TEST_FILE "./ep_test_create_file.txt"
#define TEST_FILE_2 "./ep_test_create_file_2.txt"
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/domain-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <mono/metadata/loader-internals.h>
#include <mono/metadata/mempool-internals.h>
#include <mono/metadata/handle-decl.h>
#include <mono/mini/mono-private-unstable.h>
#include <mono/jit/mono-private-unstable.h>

G_BEGIN_DECLS

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/jit-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <mono/metadata/loader-internals.h>
#include <mono/metadata/mempool-internals.h>
#include <mono/metadata/handle-decl.h>
#include <mono/mini/mono-private-unstable.h>
#include <mono/jit/mono-private-unstable.h>

G_BEGIN_DECLS

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/aot-runtime-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <sys/types.h>

#include "mini.h"
#include <mono/mini/mono-private-unstable.h>
#include <mono/jit/mono-private-unstable.h>
#include "interp/interp.h"

#ifdef TARGET_WASM
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#include "aot-runtime.h"
#include "jit-icalls.h"
#include "mini-runtime.h"
#include <mono/mini/mono-private-unstable.h>
#include <mono/jit/mono-private-unstable.h>
#include "llvmonly-runtime.h"

#include <mono/metadata/components.h>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/debug-mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "mini.h"
#include "mini-runtime.h"
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include "config.h"
#include <mono/metadata/verify.h>
#include <mono/metadata/mono-config.h>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include <mono/mini/debugger-agent-external.h>

#include "mini.h"
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include "aot-compiler.h"
#include "aot-runtime.h"
#include "mini-runtime.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
#include "ir-emit.h"

#include "jit-icalls.h"
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include "seq-points.h"
#include "aot-compiler.h"
#include "mini-llvm.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef struct SeqPointInfo SeqPointInfo;
#include "mini-arch.h"
#include "regalloc.h"
#include "mini-unwind.h"
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include "cfgdump.h"
#include "tiered.h"

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/monovm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _MONO_MINI_MONOVM_H_

#include <mono/utils/mono-publib.h>
#include <mono/mini/mono-private-unstable.h>
#include <mono/jit/mono-private-unstable.h>

// MonoVM equivalents of the CoreCLR hosting API and helpers
// Only functional on netcore builds
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/profiler/aot.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <mono/metadata/class-internals.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/utils/mono-publib.h>
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include <mono/utils/mono-logger-internals.h>
#include <mono/utils/mono-os-mutex.h>
#include <mono/utils/mono-threads.h>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/profiler/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#include <mono/metadata/class-internals.h>
#include <mono/metadata/object-internals.h>

#include <mono/mini/jit.h>
#include <mono/jit/jit.h>

#include <mono/utils/atomic.h>
#include <mono/utils/hazard-pointer.h>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/profiler/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/threads-types.h>
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include <mono/utils/atomic.h>
#include <mono/utils/hazard-pointer.h>
#include <mono/utils/lock-free-alloc.h>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/unit-tests/test-embed-invoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
*/

#define _TESTCASE_
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include <embed/test-invoke.c>
2 changes: 1 addition & 1 deletion src/mono/mono/unit-tests/test-mono-callspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <mono/metadata/class-internals.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include <mono/utils/mono-error-internals.h>

#define TESTPROG "callspec.exe"
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/unit-tests/test-mono-embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
*/

#define _TESTCASE_
#include <mono/mini/jit.h>
#include <mono/jit/jit.h>
#include <embed/teste.c>
2 changes: 1 addition & 1 deletion src/mono/mono/unit-tests/test-mono-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "config.h"
#include <stdio.h>
#include "metadata/object-internals.h"
#include "mini/jit.h"
#include <mono/jit/jit.h>

static int
new_string_ok (void)
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasi/mono-wasi-driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#include <mono/utils/mono-logger.h>
#include <mono/utils/mono-dl-fallback.h>
#include <mono/mini/jit.h>
#include <mono/mini/mono-private-unstable.h>
#include <mono/jit/jit.h>
#include <mono/jit/mono-private-unstable.h>

#include "wasm/runtime/pinvoke.h"

Expand Down
4 changes: 4 additions & 0 deletions src/mono/wasm/runtime/corebindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <stdint.h>
#include <assert.h>

#include <mono/metadata/appdomain.h>
#include <mono/metadata/class.h>
#include <mono/metadata/loader.h>
#include <mono/metadata/object.h>
#include <mono/jit/jit.h>

//JS funcs
Expand Down
4 changes: 4 additions & 0 deletions src/mono/wasm/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
#include <dlfcn.h>
#include <sys/stat.h>

#include <mono/metadata/appdomain.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/class.h>
#include <mono/metadata/tokentype.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/image.h>
#include <mono/metadata/loader.h>
#include <mono/metadata/mono-gc.h>
#include <mono/metadata/object.h>
// FIXME: unavailable in emscripten
// #include <mono/metadata/gc-internals.h>

Expand Down
47 changes: 47 additions & 0 deletions src/native/public/mono/jit/details/jit-functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// This file does not have ifdef guards, it is meant to be included multiple times with different definitions of MONO_API_FUNCTION
#ifndef MONO_API_FUNCTION
#error "MONO_API_FUNCTION(ret,name,args) macro not defined before including function declaration header"
#endif

MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY MonoDomain *, mono_jit_init, (const char *file))

MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY MonoDomain *, mono_jit_init_version, (const char *root_domain_name, const char *runtime_version))

MONO_API_FUNCTION(MonoDomain *, mono_jit_init_version_for_test_only, (const char *root_domain_name, const char *runtime_version))

MONO_API_FUNCTION(int, mono_jit_exec, (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]))
MONO_API_FUNCTION(void, mono_jit_cleanup, (MonoDomain *domain))

MONO_API_FUNCTION(mono_bool, mono_jit_set_trace_options, (const char* options))

MONO_API_FUNCTION(void, mono_set_signal_chaining, (mono_bool chain_signals))

MONO_API_FUNCTION(void, mono_set_crash_chaining, (mono_bool chain_signals))

/**
* This function is deprecated, use mono_jit_set_aot_mode instead.
*/
MONO_API_FUNCTION(void, mono_jit_set_aot_only, (mono_bool aot_only))

MONO_API_FUNCTION(void, mono_jit_set_aot_mode, (MonoAotMode mode))

/*
* Returns whether the runtime was invoked for the purpose of AOT-compiling an
* assembly, i.e. no managed code will run.
*/
MONO_API_FUNCTION(mono_bool, mono_jit_aot_compiling, (void))

MONO_API_FUNCTION(void, mono_set_break_policy, (MonoBreakPolicyFunc policy_callback))

MONO_API_FUNCTION(void, mono_jit_parse_options, (int argc, char * argv[]))

MONO_API_FUNCTION(char*, mono_get_runtime_build_info, (void))

MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY void, mono_set_use_llvm, (mono_bool use_llvm))

MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY void, mono_aot_register_module, (void **aot_info))

MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY MonoDomain*, mono_jit_thread_attach, (MonoDomain *domain))
61 changes: 61 additions & 0 deletions src/native/public/mono/jit/details/jit-types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
#ifndef _MONO_JIT_TYPES_H
#define _MONO_JIT_TYPES_H

#include <mono/metadata/details/appdomain-types.h>

MONO_BEGIN_DECLS

/**
* Allows control over our AOT (Ahead-of-time) compilation mode.
*/
typedef enum {
/* Disables AOT mode */
MONO_AOT_MODE_NONE,
/* Enables normal AOT mode, equivalent to mono_jit_set_aot_only (false) */
MONO_AOT_MODE_NORMAL,
/* Enables hybrid AOT mode, JIT can still be used for wrappers */
MONO_AOT_MODE_HYBRID,
/* Enables full AOT mode, JIT is disabled and not allowed,
* equivalent to mono_jit_set_aot_only (true) */
MONO_AOT_MODE_FULL,
/* Same as full, but use only llvm compiled code */
MONO_AOT_MODE_LLVMONLY,
/*
* Use interpreter only, no native code is generated
* at runtime. Trampolines are loaded from corlib aot image.
*/
MONO_AOT_MODE_INTERP,
/* Same as INTERP, but use only llvm compiled code */
MONO_AOT_MODE_INTERP_LLVMONLY,
/* Use only llvm compiled code, fall back to the interpeter */
MONO_AOT_MODE_LLVMONLY_INTERP,
/* Same as --interp */
MONO_AOT_MODE_INTERP_ONLY,
/* Sentinel value used internally by the runtime. We use a large number to avoid clashing with some internal values. */
MONO_AOT_MODE_LAST = 1000,
} MonoAotMode;

/* Allow embedders to decide wherther to actually obey breakpoint instructions
* in specific methods (works for both break IL instructions and Debugger.Break ()
* method calls).
*/
typedef enum {
/* the default is to always obey the breakpoint */
MONO_BREAK_POLICY_ALWAYS,
/* a nop is inserted instead of a breakpoint */
MONO_BREAK_POLICY_NEVER,
/* the breakpoint is executed only if the program has ben started under
* the debugger (that is if a debugger was attached at the time the method
* was compiled).
*/
MONO_BREAK_POLICY_ON_DBG
} MonoBreakPolicy;

typedef MonoBreakPolicy (*MonoBreakPolicyFunc) (MonoMethod *method);

MONO_END_DECLS

#endif /* _MONO_JIT_TYPES_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
/**
*
* Private unstable APIs.
*
* WARNING: The declarations and behavior of functions in this header are NOT STABLE and can be modified or removed at
* any time.
*
*/
// This file does not have ifdef guards, it is meant to be included multiple times with different definitions of MONO_API_FUNCTION
#ifndef MONO_API_FUNCTION
#error "MONO_API_FUNCTION(ret,name,args) macro not defined before including function declaration header"
#endif

MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY void, mono_install_load_aot_data_hook, (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, void* user_data))

MONO_API_FUNCTION(int, monovm_initialize, (int propertyCount, const char **propertyKeys, const char **propertyValues))

MONO_API_FUNCTION(int, monovm_runtimeconfig_initialize, (MonovmRuntimeConfigArguments *arg, MonovmRuntimeConfigArgumentsCleanup cleanup_fn, void *user_data))

// The wrapper MonoCoreRuntimeProperties struct can be stack-allocated or freed, but the structs inside it _must_ be heap-allocated and never freed, as they are not copied to avoid extra allocations
MONO_API_FUNCTION(int, monovm_initialize_preparsed, (MonoCoreRuntimeProperties *parsed_properties, int propertyCount, const char **propertyKeys, const char **propertyValues))

//#ifdef HOST_WASM
MONO_API_FUNCTION(void, mono_wasm_install_get_native_to_interp_tramp, (MonoWasmGetNativeToInterpTramp cb))
//#endif
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
/**
* \file
*
* Private unstable APIs.
*
* WARNING: The declarations and behavior of functions in this header are NOT STABLE and can be modified or removed at
* any time.
*
*/
#ifndef _MONO_JIT_PRIVATE_UNSTABLE_TYPES_H
#define _MONO_JIT_PRIVATE_UNSTABLE_TYPES_H

#include <mono/utils/details/mono-publib-types.h>
#include <mono/metadata/details/image-types.h>
#include <mono/metadata/details/mono-private-unstable-types.h>

#ifndef __MONO_JIT_MONO_PRIVATE_UNSTABLE_H__
#define __MONO_JIT_MONO_PRIVATE_UNSTABLE_H__

#include <mono/utils/mono-publib.h>
#include <mono/metadata/image.h>
#include <mono/metadata/mono-private-unstable.h>
MONO_BEGIN_DECLS

typedef struct {
uint32_t kind; // 0 = Path of runtimeconfig.blob, 1 = pointer to image data, >= 2 undefined
Expand Down Expand Up @@ -58,24 +60,11 @@ typedef struct {
typedef unsigned char* (*MonoLoadAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void **out_handle);
/* Not yet used */
typedef void (*MonoFreeAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void *handle);
MONO_API MONO_RT_EXTERNAL_ONLY void
mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, void* user_data);

MONO_API int
monovm_initialize (int propertyCount, const char **propertyKeys, const char **propertyValues);

MONO_API int
monovm_runtimeconfig_initialize (MonovmRuntimeConfigArguments *arg, MonovmRuntimeConfigArgumentsCleanup cleanup_fn, void *user_data);

// The wrapper MonoCoreRuntimeProperties struct can be stack-allocated or freed, but the structs inside it _must_ be heap-allocated and never freed, as they are not copied to avoid extra allocations
MONO_API int
monovm_initialize_preparsed (MonoCoreRuntimeProperties *parsed_properties, int propertyCount, const char **propertyKeys, const char **propertyValues);

//#ifdef HOST_WASM
typedef void* (*MonoWasmGetNativeToInterpTramp) (MonoMethod *method, void *extra_arg);

MONO_API void
mono_wasm_install_get_native_to_interp_tramp (MonoWasmGetNativeToInterpTramp cb);
//#endif

#endif /*__MONO_JIT_MONO_PRIVATE_UNSTABLE_H__*/
MONO_END_DECLS

#endif /* _MONO_JIT_PRIVATE_UNSTABLE_TYPES_H */
Loading

0 comments on commit 858221c

Please sign in to comment.