summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api_internal.h
blob: 6e05eea748caca16da84b377103e7520e747098e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * Copyright (C) 2019 Intel Corporation.  All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

#ifndef _WASM_C_API_INTERNAL_H
#define _WASM_C_API_INTERNAL_H

#include "../include/wasm_c_api.h"
#include "wasm_runtime_common.h"

#ifndef own
#define own
#endif

/* Vectors */
/* we will malloc resource for the vector's data field */
/* we will release resource of data */
/* caller needs to take care resource for the vector itself */
#define DEFAULT_VECTOR_INIT_LENGTH (64)

WASM_DECLARE_VEC(instance, *)
WASM_DECLARE_VEC(module, *)
WASM_DECLARE_VEC(store, *)

/* Runtime Environment */
struct wasm_engine_t {
    uint32 ref_count;
    /* list of wasm_module_ex_t */
    Vector modules;
    /* list of stores which are classified according to tids */
    Vector stores_by_tid;
};

struct wasm_store_t {
    /* maybe should remove the list */
    wasm_module_vec_t *modules;
    wasm_instance_vec_t *instances;
    Vector *foreigns;
};

/* Type Representations */
struct wasm_valtype_t {
    wasm_valkind_t kind;
};

struct wasm_functype_t {
    uint32 extern_kind;
    /* gona to new and delete own */
    wasm_valtype_vec_t *params;
    wasm_valtype_vec_t *results;
};

struct wasm_globaltype_t {
    uint32 extern_kind;
    /* gona to new and delete own */
    wasm_valtype_t *val_type;
    wasm_mutability_t mutability;
};

struct wasm_tabletype_t {
    uint32 extern_kind;
    wasm_valtype_t *val_type;
    wasm_limits_t limits;
};

struct wasm_memorytype_t {
    uint32 extern_kind;
    wasm_limits_t limits;
};

struct wasm_externtype_t {
    uint32 extern_kind;
    /* reservered space */
    uint8 data[1];
};

struct wasm_importtype_t {
    wasm_name_t *module_name;
    wasm_name_t *name;
    wasm_externtype_t *extern_type;
};

struct wasm_exporttype_t {
    wasm_name_t *name;
    wasm_externtype_t *extern_type;
};

/* Runtime Objects */
enum wasm_reference_kind {
    WASM_REF_foreign,
    WASM_REF_func,
    WASM_REF_global,
    WASM_REF_memory,
    WASM_REF_table,
};

struct wasm_host_info {
    void *info;
    void (*finalizer)(void *);
};

struct wasm_ref_t {
    wasm_store_t *store;
    enum wasm_reference_kind kind;
    struct wasm_host_info host_info;
    uint32 ref_idx_rt;
    WASMModuleInstanceCommon *inst_comm_rt;
};

struct wasm_trap_t {
    wasm_byte_vec_t *message;
    Vector *frames;
};

struct wasm_foreign_t {
    wasm_store_t *store;
    enum wasm_reference_kind kind;
    struct wasm_host_info host_info;
    int32 ref_cnt;
    uint32 foreign_idx_rt;
    WASMModuleInstanceCommon *inst_comm_rt;
};

struct wasm_func_t {
    wasm_store_t *store;
    wasm_name_t *module_name;
    wasm_name_t *name;
    uint16 kind;

    struct wasm_host_info host_info;
    wasm_functype_t *type;

    bool with_env;
    union {
        wasm_func_callback_t cb;
        struct callback_ext {
            void *env;
            wasm_func_callback_with_env_t cb;
            void (*finalizer)(void *);
        } cb_env;
    } u;
    /*
     * an index in both functions runtime instance lists
     * of interpreter mode and aot mode
     */
    uint16 func_idx_rt;
    WASMModuleInstanceCommon *inst_comm_rt;
    WASMFunctionInstanceCommon *func_comm_rt;
};

struct wasm_global_t {
    wasm_store_t *store;
    wasm_name_t *module_name;
    wasm_name_t *name;
    uint16 kind;

    struct wasm_host_info host_info;
    wasm_globaltype_t *type;
    wasm_val_t *init;
    /*
     * an index in both global runtime instance lists
     * of interpreter mode and aot mode
     */
    uint16 global_idx_rt;
    WASMModuleInstanceCommon *inst_comm_rt;
};

struct wasm_memory_t {
    wasm_store_t *store;
    wasm_name_t *module_name;
    wasm_name_t *name;
    uint16 kind;

    struct wasm_host_info host_info;
    wasm_memorytype_t *type;
    /*
     * an index in both memory runtime instance lists
     * of interpreter mode and aot mode
     */
    uint16 memory_idx_rt;
    WASMModuleInstanceCommon *inst_comm_rt;
};

struct wasm_table_t {
    wasm_store_t *store;
    wasm_name_t *module_name;
    wasm_name_t *name;
    uint16 kind;

    struct wasm_host_info host_info;
    wasm_tabletype_t *type;
    /*
     * an index in both table runtime instance lists
     * of interpreter mode and aot mode
     */
    uint16 table_idx_rt;
    WASMModuleInstanceCommon *inst_comm_rt;
};

struct wasm_extern_t {
    wasm_store_t *store;
    wasm_name_t *module_name;
    wasm_name_t *name;
    wasm_externkind_t kind;
    /* reservered space */
    uint8 data[1];
};

struct wasm_instance_t {
    wasm_store_t *store;
    wasm_extern_vec_t *exports;
    struct wasm_host_info host_info;
    WASMModuleInstanceCommon *inst_comm_rt;
};

wasm_ref_t *
wasm_ref_new_internal(wasm_store_t *store, enum wasm_reference_kind kind,
                      uint32 obj_idx_rt,
                      WASMModuleInstanceCommon *inst_comm_rt);

wasm_foreign_t *
wasm_foreign_new_internal(wasm_store_t *store, uint32 foreign_idx_rt,
                          WASMModuleInstanceCommon *inst_comm_rt);

wasm_func_t *
wasm_func_new_internal(wasm_store_t *store, uint16 func_idx_rt,
                       WASMModuleInstanceCommon *inst_comm_rt);

wasm_global_t *
wasm_global_new_internal(wasm_store_t *store, uint16 global_idx_rt,
                         WASMModuleInstanceCommon *inst_comm_rt);

wasm_memory_t *
wasm_memory_new_internal(wasm_store_t *store, uint16 memory_idx_rt,
                         WASMModuleInstanceCommon *inst_comm_rt);

wasm_table_t *
wasm_table_new_internal(wasm_store_t *store, uint16 table_idx_rt,
                        WASMModuleInstanceCommon *inst_comm_rt);
#endif /* _WASM_C_API_INTERNAL_H */