Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MonoAPI] Split type and function headers, add MONO_API_FUNCTION macro #65446

Merged
merged 14 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[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
  • Loading branch information
lambdageek committed Feb 23, 2022
commit 9e5ace5ae32c0e257663a6fef2de69396b14b4e5
45 changes: 45 additions & 0 deletions src/native/public/mono/utils/details/mono-counters-functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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_API void, mono_counters_enable, (int section_mask))
MONO_API_FUNCTION(MONO_API void, mono_counters_init, (void))

/*
* register addr as the address of a counter of type type.
* It may be a function pointer if MONO_COUNTER_CALLBACK is specified:
* the function should return the value and take no arguments.
*/
MONO_API_FUNCTION(MONO_API void, mono_counters_register, (const char* descr, int type, void *addr))
MONO_API_FUNCTION(MONO_API void, mono_counters_register_with_size, (const char *name, int type, void *addr, int size))

MONO_API_FUNCTION(MONO_API void, mono_counters_on_register, (MonoCounterRegisterCallback callback))

/*
* Create a readable dump of the counters for section_mask sections (ORed section values)
*/
MONO_API_FUNCTION(MONO_API void, mono_counters_dump, (int section_mask, FILE *outfile))

MONO_API_FUNCTION(MONO_API void, mono_counters_cleanup, (void))

MONO_API_FUNCTION(MONO_API void, mono_counters_foreach, (CountersEnumCallback cb, void *user_data))

MONO_API_FUNCTION(MONO_API int, mono_counters_sample, (MonoCounter *counter, void *buffer, int buffer_size))

MONO_API_FUNCTION(MONO_API const char*, mono_counter_get_name, (MonoCounter *name))
MONO_API_FUNCTION(MONO_API int, mono_counter_get_type, (MonoCounter *counter))
MONO_API_FUNCTION(MONO_API int, mono_counter_get_section, (MonoCounter *counter))
MONO_API_FUNCTION(MONO_API int, mono_counter_get_unit, (MonoCounter *counter))
MONO_API_FUNCTION(MONO_API int, mono_counter_get_variance, (MonoCounter *counter))
MONO_API_FUNCTION(MONO_API size_t, mono_counter_get_size, (MonoCounter *counter))

MONO_API_FUNCTION(MONO_API int, mono_runtime_resource_limit, (int resource_type, uintptr_t soft_limit, uintptr_t hard_limit))
MONO_API_FUNCTION(MONO_API void, mono_runtime_resource_set_callback, (MonoResourceCallback callback))
MONO_API_FUNCTION(MONO_API void, mono_runtime_resource_check_limit, (int resource_type, uintptr_t value))



lambdageek marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 73 additions & 0 deletions src/native/public/mono/utils/details/mono-counters-types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
#ifndef _MONO_COUNTERS_TYPES_H
#define _MONO_COUNTERS_TYPES_H

#include <stdio.h>
#include <mono/utils/details/mono-publib-types.h>

MONO_BEGIN_DECLS

enum {
/* Counter type, bits 0-7. */
MONO_COUNTER_INT, /* 32 bit int */
MONO_COUNTER_UINT, /* 32 bit uint */
MONO_COUNTER_WORD, /* pointer-sized int */
MONO_COUNTER_LONG, /* 64 bit int */
MONO_COUNTER_ULONG, /* 64 bit uint */
MONO_COUNTER_DOUBLE,
MONO_COUNTER_STRING, /* char* */
MONO_COUNTER_TIME_INTERVAL, /* 64 bits signed int holding usecs. */
MONO_COUNTER_TYPE_MASK = 0xf,
MONO_COUNTER_CALLBACK = 128, /* ORed with the other values */
MONO_COUNTER_SECTION_MASK = 0x00ffff00,
/* Sections, bits 8-23 (16 bits) */
MONO_COUNTER_JIT = 1 << 8,
MONO_COUNTER_GC = 1 << 9,
MONO_COUNTER_METADATA = 1 << 10,
MONO_COUNTER_GENERICS = 1 << 11,
MONO_COUNTER_SECURITY = 1 << 12,
MONO_COUNTER_RUNTIME = 1 << 13,
MONO_COUNTER_SYSTEM = 1 << 14,
MONO_COUNTER_PERFCOUNTERS = 1 << 15,
MONO_COUNTER_PROFILER = 1 << 16,
MONO_COUNTER_INTERP = 1 << 17,
MONO_COUNTER_TIERED = 1 << 18,
MONO_COUNTER_LAST_SECTION,

/* Unit, bits 24-27 (4 bits) */
MONO_COUNTER_UNIT_SHIFT = 24,
MONO_COUNTER_UNIT_MASK = 0xFu << MONO_COUNTER_UNIT_SHIFT,
MONO_COUNTER_RAW = 0 << 24, /* Raw value */
MONO_COUNTER_BYTES = 1 << 24, /* Quantity of bytes. RSS, active heap, etc */
MONO_COUNTER_TIME = 2 << 24, /* Time interval in 100ns units. Minor pause, JIT compilation*/
MONO_COUNTER_COUNT = 3 << 24, /* Number of things (threads, queued jobs) or Number of events triggered (Major collections, Compiled methods).*/
MONO_COUNTER_PERCENTAGE = 4 << 24, /* [0-1] Fraction Percentage of something. Load average. */

/* Monotonicity, bits 28-31 (4 bits) */
MONO_COUNTER_VARIANCE_SHIFT = 28,
MONO_COUNTER_VARIANCE_MASK = 0xFu << MONO_COUNTER_VARIANCE_SHIFT,
MONO_COUNTER_MONOTONIC = 1 << 28, /* This counter value always increase/decreases over time. Reported by --stat. */
MONO_COUNTER_CONSTANT = 1 << 29, /* Fixed value. Used by configuration data. */
MONO_COUNTER_VARIABLE = 1 << 30, /* This counter value can be anything on each sampling. Only interesting when sampling. */
};

typedef struct _MonoCounter MonoCounter;

typedef void (*MonoCounterRegisterCallback) (MonoCounter*);

typedef mono_bool (*CountersEnumCallback) (MonoCounter *counter, void *user_data);

typedef enum {
MONO_RESOURCE_JIT_CODE, /* bytes */
MONO_RESOURCE_METADATA, /* bytes */
MONO_RESOURCE_GC_HEAP, /* bytes */
MONO_RESOURCE_COUNT /* non-ABI value */
} MonoResourceType;

typedef void (*MonoResourceCallback) (int resource_type, uintptr_t value, int is_soft);

MONO_END_DECLS

#endif /* _MONO_COUNTERS_TYPES_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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_API MonoDlFallbackHandler *, mono_dl_fallback_register, (MonoDlFallbackLoad load_func, MonoDlFallbackSymbol symbol_func, \
MonoDlFallbackClose close_func, void *user_data))
MONO_API_FUNCTION(MONO_API void, mono_dl_fallback_unregister, (MonoDlFallbackHandler *handler))


36 changes: 36 additions & 0 deletions src/native/public/mono/utils/details/mono-dl-fallback-types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
#ifndef _MONO_DL_FALLBACK_TYPES_H
#define _MONO_DL_FALLBACK_TYPES_H

#include <mono/utils/details/mono-publib-types.h>

MONO_BEGIN_DECLS

enum {
MONO_DL_EAGER = 0,
MONO_DL_LAZY = 1,
// If MONO_DL_LOCAL is set, it will trump MONO_DL_GLOBAL.
MONO_DL_LOCAL = 2,
// MONO_DL_MASK is unused internally and no longer a full mask on netcore, given the introduction of MONO_DL_GLOBAL. Avoid.
MONO_DL_MASK = 3,
// Only applicable when building Mono in netcore mode.
MONO_DL_GLOBAL = 4
};

/*
* This is the dynamic loader fallback API
*/
typedef struct MonoDlFallbackHandler MonoDlFallbackHandler;

/*
* The "err" variable contents must be allocated using g_malloc or g_strdup
*/
typedef void* (*MonoDlFallbackLoad) (const char *name, int flags, char **err, void *user_data);
typedef void* (*MonoDlFallbackSymbol) (void *handle, const char *name, char **err, void *user_data);
typedef void* (*MonoDlFallbackClose) (void *handle, void *user_data);

MONO_END_DECLS

#endif
20 changes: 20 additions & 0 deletions src/native/public/mono/utils/details/mono-error-functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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_API MONO_RT_EXTERNAL_ONLY void, mono_error_init, (MonoError *error))
MONO_API_FUNCTION(MONO_API void, mono_error_init_flags, (MonoError *error, unsigned short flags))

MONO_API_FUNCTION(MONO_API void, mono_error_cleanup, (MonoError *error))

MONO_API_FUNCTION(MONO_API MONO_RT_EXTERNAL_ONLY mono_bool, mono_error_ok, (MonoError *error))

MONO_API_FUNCTION(MONO_API unsigned short, mono_error_get_error_code, (MonoError *error))

MONO_API_FUNCTION(MONO_API const char*, mono_error_get_message, (MonoError *error))


82 changes: 82 additions & 0 deletions src/native/public/mono/utils/details/mono-error-types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
#ifndef _MONO_ERROR_TYPES_H
#define _MONO_ERROR_TYPES_H

#include <mono/utils/details/mono-publib-types.h>

enum {
/*
The supplied strings were dup'd by means of calling mono_error_dup_strings.
*/
MONO_ERROR_FREE_STRINGS = 0x0001,

/*
Something happened while processing the error and the resulting message is incomplete.
*/
MONO_ERROR_INCOMPLETE = 0x0002,
/*
This MonoError is heap allocated in a mempool
*/
MONO_ERROR_MEMPOOL_BOXED = 0x0004
};

enum {
MONO_ERROR_NONE = 0,
MONO_ERROR_MISSING_METHOD = 1,
MONO_ERROR_MISSING_FIELD = 2,
MONO_ERROR_TYPE_LOAD = 3,
MONO_ERROR_FILE_NOT_FOUND = 4,
MONO_ERROR_BAD_IMAGE = 5,
MONO_ERROR_OUT_OF_MEMORY = 6,
MONO_ERROR_ARGUMENT = 7,
MONO_ERROR_ARGUMENT_NULL = 11,
MONO_ERROR_ARGUMENT_OUT_OF_RANGE = 14,
MONO_ERROR_NOT_VERIFIABLE = 8,
MONO_ERROR_INVALID_PROGRAM = 12,
MONO_ERROR_MEMBER_ACCESS = 13,

/*
* This is a generic error mechanism is you need to raise an arbitrary corlib exception.
* You must pass the exception name otherwise prepare_exception will fail with internal execution.
*/
MONO_ERROR_GENERIC = 9,
/* This one encapsulates a managed exception instance */
MONO_ERROR_EXCEPTION_INSTANCE = 10,

/* Not a valid error code - indicates that the error was cleaned up and reused */
MONO_ERROR_CLEANUP_CALLED_SENTINEL = 0xffff
};

#ifdef _MSC_VER
__pragma(warning (push))
__pragma(warning (disable:4201))
#endif

/*Keep in sync with MonoErrorInternal*/
typedef union _MonoError {
// Merge two uint16 into one uint32 so it can be initialized
// with one instruction instead of two.
uint32_t init;
struct {
uint16_t error_code;
uint16_t private_flags; /*DON'T TOUCH */
void *hidden_1 [12]; /*DON'T TOUCH */
};
} MonoErrorExternal;

#ifdef _MSC_VER
__pragma(warning (pop))
#endif

#ifdef MONO_INSIDE_RUNTIME
typedef union _MonoErrorInternal MonoError;
#else
typedef MonoErrorExternal MonoError;
#endif

/* Mempool-allocated MonoError.*/
typedef struct _MonoErrorBoxed MonoErrorBoxed;

#endif
19 changes: 19 additions & 0 deletions src/native/public/mono/utils/details/mono-logger-functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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_API void, mono_trace_set_level_string, (const char *value))

MONO_API_FUNCTION(MONO_API void, mono_trace_set_mask_string, (const char *value))

MONO_API_FUNCTION(MONO_API void, mono_trace_set_log_handler, (MonoLogCallback callback, void *user_data))

MONO_API_FUNCTION(MONO_API void, mono_trace_set_print_handler, (MonoPrintCallback callback))

MONO_API_FUNCTION(MONO_API void, mono_trace_set_printerr_handler, (MonoPrintCallback callback))


16 changes: 16 additions & 0 deletions src/native/public/mono/utils/details/mono-logger-types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
#ifndef _MONO_LOGGER_TYPES_H
#define _MONO_LOGGER_TYPES_H

#include <mono/utils/details/mono-publib-types.h>

MONO_BEGIN_DECLS

typedef void (*MonoPrintCallback) (const char *string, mono_bool is_stdout);
typedef void (*MonoLogCallback) (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data);

MONO_END_DECLS

#endif /* _MONO_LOGGER_TYPES_H */
11 changes: 11 additions & 0 deletions src/native/public/mono/utils/details/mono-publib-functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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_API void, mono_free, (void*))
MONO_API_FUNCTION(MONO_API mono_bool, mono_set_allocator_vtable, (MonoAllocatorVTable* vtable))

Loading