[Mono.Runtime.Tests] Exclude simd tests
[mono-project.git] / mono / metadata / handle-decl.h
bloba6085bed86fab6c0cc166153c7dee48a473dd1fc
1 /**
2 * \file
3 * Handle to object in native code
5 * Authors:
6 * - Ludovic Henry <ludovic@xamarin.com>
7 * - Aleksey Klieger <aleksey.klieger@xamarin.com>
8 * - Rodrigo Kumpera <kumpera@xamarin.com>
10 * Copyright 2016 Dot net foundation.
11 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
14 #ifndef __MONO_HANDLE_DECL_H__
15 #define __MONO_HANDLE_DECL_H__
17 #include <config.h>
18 #include <glib.h>
19 #include <mono/metadata/object-forward.h>
20 #include <mono/utils/mono-compiler.h>
22 // Type-safe handles are a struct with a pointer to pointer.
23 // The only operations allowed on them are the functions/macros in this file, and assignment
24 // from same handle type to same handle type.
26 // Raw handles are void* but still same underlying representation, really void**.
28 // marshal-ilgen.c does not know how to marshal type safe handles.
29 // It passes/accepts raw handles and generated wrappers in C convert.
32 Handle macros/functions
35 #define TYPED_HANDLE_NAME(TYPE) TYPE ## Handle
36 #define TYPED_OUT_HANDLE_NAME(TYPE) TYPE ## HandleOut
37 #define TYPED_IN_OUT_HANDLE_NAME(TYPE) TYPE ## HandleInOut
39 // internal helpers:
40 #define MONO_HANDLE_CAST_FOR(type) mono_handle_cast_##type
41 #define MONO_HANDLE_TYPECHECK_FOR(type) mono_handle_typecheck_##type
44 * TYPED_HANDLE_DECL(SomeType):
45 * Expands to a decl for handles to SomeType.
47 * For example, TYPED_HANDLE_DECL(MonoObject) (see below) expands to:
49 * typedef struct {
50 * MonoObject **__raw;
51 * } MonoObjectHandle,
52 * MonoObjectHandleOut,
53 * MonoObjectHandleInOut;
55 * Out is intended for out parameters, InOut is intended for ref parameters.
56 * This is not enforced.
57 * Internal helper functions are also generated.
59 #ifdef __cplusplus
60 #define MONO_IF_CPLUSPLUS(x) x
61 #else
62 #define MONO_IF_CPLUSPLUS(x) /* nothing */
63 #endif
65 #define TYPED_HANDLE_DECL(TYPE) \
66 typedef struct { \
67 MONO_IF_CPLUSPLUS ( \
68 MONO_ALWAYS_INLINE \
69 TYPE * GetRaw () const { return __raw ? *__raw : NULL; } \
70 ) \
71 TYPE * volatile *__raw; \
72 } TYPED_HANDLE_NAME (TYPE), \
73 TYPED_OUT_HANDLE_NAME (TYPE), \
74 TYPED_IN_OUT_HANDLE_NAME (TYPE); \
75 /* Do not call these functions directly. Use MONO_HANDLE_NEW and MONO_HANDLE_CAST. */ \
76 /* Another way to do this involved casting mono_handle_new function to a different type. */ \
77 static inline MONO_ALWAYS_INLINE TYPED_HANDLE_NAME (TYPE) \
78 MONO_HANDLE_CAST_FOR (TYPE) (MonoRawHandle a) \
79 { \
80 TYPED_HANDLE_NAME (TYPE) b = { (TYPE**)a }; \
81 return b; \
82 } \
83 static inline MONO_ALWAYS_INLINE MonoObject* \
84 MONO_HANDLE_TYPECHECK_FOR (TYPE) (TYPE *a) \
85 { \
86 return (MonoObject*)a; \
87 } \
88 /* Out/InOut synonyms for icall-def.h HANDLES () */ \
89 static inline MONO_ALWAYS_INLINE TYPED_HANDLE_NAME (TYPE) \
90 MONO_HANDLE_CAST_FOR (TYPE##Out) (gpointer a) \
91 { \
92 return MONO_HANDLE_CAST_FOR (TYPE) (a); \
93 } \
94 static inline MONO_ALWAYS_INLINE MonoObject* \
95 MONO_HANDLE_TYPECHECK_FOR (TYPE##Out) (TYPE *a) \
96 { \
97 return MONO_HANDLE_TYPECHECK_FOR (TYPE) (a); \
98 } \
99 static inline MONO_ALWAYS_INLINE TYPED_HANDLE_NAME (TYPE) \
100 MONO_HANDLE_CAST_FOR (TYPE##InOut) (gpointer a) \
102 return MONO_HANDLE_CAST_FOR (TYPE) (a); \
104 static inline MONO_ALWAYS_INLINE MonoObject* \
105 MONO_HANDLE_TYPECHECK_FOR (TYPE##InOut) (TYPE *a) \
107 return MONO_HANDLE_TYPECHECK_FOR (TYPE) (a); \
110 #endif /* __MONO_HANDLE_DECL_H__ */