-
Notifications
You must be signed in to change notification settings - Fork 786
Expand file tree
/
Copy pathwasm.h
More file actions
1519 lines (1371 loc) · 41.9 KB
/
wasm.h
File metadata and controls
1519 lines (1371 loc) · 41.9 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASM_H_
#define _WASM_H_
#include "bh_platform.h"
#include "bh_hashmap.h"
#include "bh_assert.h"
#if WASM_ENABLE_GC != 0
#include "gc_export.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Value Type */
#define VALUE_TYPE_I32 0x7F
#define VALUE_TYPE_I64 0X7E
#define VALUE_TYPE_F32 0x7D
#define VALUE_TYPE_F64 0x7C
#define VALUE_TYPE_V128 0x7B
#define VALUE_TYPE_FUNCREF 0x70
#define VALUE_TYPE_EXTERNREF 0x6F
#define VALUE_TYPE_VOID 0x40
/* Packed Types */
#define PACKED_TYPE_I8 0x78
#define PACKED_TYPE_I16 0x77
/* Reference Types */
#define REF_TYPE_NULLFUNCREF 0x73
#define REF_TYPE_NULLEXTERNREF 0x72
#define REF_TYPE_NULLREF 0x71
#define REF_TYPE_FUNCREF VALUE_TYPE_FUNCREF /* 0x70 */
#define REF_TYPE_EXTERNREF VALUE_TYPE_EXTERNREF /* 0x6F */
#define REF_TYPE_ANYREF 0x6E
#define REF_TYPE_EQREF 0x6D
#define REF_TYPE_I31REF 0x6C
#define REF_TYPE_STRUCTREF 0x6B
#define REF_TYPE_ARRAYREF 0x6A
#define REF_TYPE_HT_NON_NULLABLE 0x64
#define REF_TYPE_HT_NULLABLE 0x63
#define REF_TYPE_STRINGREF VALUE_TYPE_STRINGREF /* 0x67 */
#define REF_TYPE_STRINGVIEWWTF8 VALUE_TYPE_STRINGVIEWWTF8 /* 0x66 */
#define REF_TYPE_STRINGVIEWWTF16 VALUE_TYPE_STRINGVIEWWTF16 /* 0x62 */
#define REF_TYPE_STRINGVIEWITER VALUE_TYPE_STRINGVIEWITER /* 0x61 */
/* Heap Types */
#define HEAP_TYPE_NOFUNC (-0x0D)
#define HEAP_TYPE_NOEXTERN (-0x0E)
#define HEAP_TYPE_NONE (-0x0F)
#define HEAP_TYPE_FUNC (-0x10)
#define HEAP_TYPE_EXTERN (-0x11)
#define HEAP_TYPE_ANY (-0x12)
#define HEAP_TYPE_EQ (-0x13)
#define HEAP_TYPE_I31 (-0x14)
#define HEAP_TYPE_STRUCT (-0x15)
#define HEAP_TYPE_ARRAY (-0x16)
#define HEAP_TYPE_STRINGREF (-0x19)
#define HEAP_TYPE_STRINGVIEWWTF8 (-0x1A)
#define HEAP_TYPE_STRINGVIEWWTF16 (-0x1E)
#define HEAP_TYPE_STRINGVIEWITER (-0x1F)
/* Defined Types */
#define DEFINED_TYPE_FUNC 0x60
#define DEFINED_TYPE_STRUCT 0x5F
#define DEFINED_TYPE_ARRAY 0x5E
#define DEFINED_TYPE_SUB 0x50
#define DEFINED_TYPE_SUB_FINAL 0x4F
#define DEFINED_TYPE_REC 0x4E
/* Used by AOT */
#define VALUE_TYPE_I1 0x41
/**
* Used by loader to represent any type of i32/i64/f32/f64/v128
* and ref types, including funcref, externref, anyref, eqref,
* (ref null $ht), (ref $ht), i31ref, structref, arrayref,
* nullfuncref, nullexternref, nullref and stringref
*/
#define VALUE_TYPE_ANY 0x42
/**
* Used by wamr compiler to represent object ref types,
* including func object ref, externref object ref,
* internal object ref, eq object ref, i31 object ref,
* struct object ref, array object ref
*/
#define VALUE_TYPE_GC_REF 0x43
#define MAX_PAGE_COUNT_FLAG 0x01
#define SHARED_MEMORY_FLAG 0x02
#define MEMORY64_FLAG 0x04
#define MAX_TABLE_SIZE_FLAG 0x01
/* the shared flag for table is not actual used now */
#define SHARED_TABLE_FLAG 0x02
#define TABLE64_FLAG 0x04
/**
* In the multi-memory proposal, the memarg in loads and stores are
* reinterpreted as a bitfield, bit 6 serves as a flag indicating the presence
* of the optional memory index, if it is set, then an i32 memory index follows
* after the alignment bitfield
*/
#define OPT_MEMIDX_FLAG 0x40
#define DEFAULT_NUM_BYTES_PER_PAGE 65536
#define DEFAULT_MAX_PAGES 65536
#define DEFAULT_MEM64_MAX_PAGES UINT32_MAX
/* Max size of linear memory */
#define MAX_LINEAR_MEMORY_SIZE (4 * (uint64)BH_GB)
/* Roughly 274 TB */
#define MAX_LINEAR_MEM64_MEMORY_SIZE \
(DEFAULT_MEM64_MAX_PAGES * (uint64)64 * (uint64)BH_KB)
/* Macro to check memory flag and return appropriate memory size */
#define GET_MAX_LINEAR_MEMORY_SIZE(is_memory64) \
(is_memory64 ? MAX_LINEAR_MEM64_MEMORY_SIZE : MAX_LINEAR_MEMORY_SIZE)
#if WASM_ENABLE_GC == 0
typedef uintptr_t table_elem_type_t;
#define NULL_REF (0xFFFFFFFF)
#else
typedef void *table_elem_type_t;
#define NULL_REF (NULL)
#define REF_CELL_NUM ((uint32)sizeof(uintptr_t) / sizeof(uint32))
#endif
#define INIT_EXPR_NONE 0x00
#define INIT_EXPR_TYPE_I32_CONST 0x41
#define INIT_EXPR_TYPE_I64_CONST 0x42
#define INIT_EXPR_TYPE_F32_CONST 0x43
#define INIT_EXPR_TYPE_F64_CONST 0x44
#define INIT_EXPR_TYPE_V128_CONST 0xFD
#define INIT_EXPR_TYPE_GET_GLOBAL 0x23
#define INIT_EXPR_TYPE_I32_ADD 0x6A
#define INIT_EXPR_TYPE_I32_SUB 0x6B
#define INIT_EXPR_TYPE_I32_MUL 0x6C
#define INIT_EXPR_TYPE_I64_ADD 0x7C
#define INIT_EXPR_TYPE_I64_SUB 0x7D
#define INIT_EXPR_TYPE_I64_MUL 0x7E
#define INIT_EXPR_TYPE_REFNULL_CONST 0xD0
#define INIT_EXPR_TYPE_FUNCREF_CONST 0xD2
#define INIT_EXPR_TYPE_STRUCT_NEW 0xD3
#define INIT_EXPR_TYPE_STRUCT_NEW_DEFAULT 0xD4
#define INIT_EXPR_TYPE_ARRAY_NEW 0xD5
#define INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT 0xD6
#define INIT_EXPR_TYPE_ARRAY_NEW_FIXED 0xD7
#define INIT_EXPR_TYPE_I31_NEW 0xD8
#define INIT_EXPR_TYPE_ANY_CONVERT_EXTERN 0xD9
#define INIT_EXPR_TYPE_EXTERN_CONVERT_ANY 0xDA
#define WASM_MAGIC_NUMBER 0x6d736100
#define WASM_CURRENT_VERSION 1
#define SECTION_TYPE_USER 0
#define SECTION_TYPE_TYPE 1
#define SECTION_TYPE_IMPORT 2
#define SECTION_TYPE_FUNC 3
#define SECTION_TYPE_TABLE 4
#define SECTION_TYPE_MEMORY 5
#define SECTION_TYPE_GLOBAL 6
#define SECTION_TYPE_EXPORT 7
#define SECTION_TYPE_START 8
#define SECTION_TYPE_ELEM 9
#define SECTION_TYPE_CODE 10
#define SECTION_TYPE_DATA 11
#if WASM_ENABLE_BULK_MEMORY != 0
#define SECTION_TYPE_DATACOUNT 12
#endif
#if WASM_ENABLE_TAGS != 0
#define SECTION_TYPE_TAG 13
#endif
#if WASM_ENABLE_STRINGREF != 0
#define SECTION_TYPE_STRINGREF 14
#endif
#define SUB_SECTION_TYPE_MODULE 0
#define SUB_SECTION_TYPE_FUNC 1
#define SUB_SECTION_TYPE_LOCAL 2
#define IMPORT_KIND_FUNC 0
#define IMPORT_KIND_TABLE 1
#define IMPORT_KIND_MEMORY 2
#define IMPORT_KIND_GLOBAL 3
#if WASM_ENABLE_TAGS != 0
#define IMPORT_KIND_TAG 4
#endif
#define EXPORT_KIND_FUNC 0
#define EXPORT_KIND_TABLE 1
#define EXPORT_KIND_MEMORY 2
#define EXPORT_KIND_GLOBAL 3
#if WASM_ENABLE_TAGS != 0
#define EXPORT_KIND_TAG 4
#endif
#define LABEL_TYPE_BLOCK 0
#define LABEL_TYPE_LOOP 1
#define LABEL_TYPE_IF 2
#define LABEL_TYPE_FUNCTION 3
#if WASM_ENABLE_EXCE_HANDLING != 0
#define LABEL_TYPE_TRY 4
#define LABEL_TYPE_CATCH 5
#define LABEL_TYPE_CATCH_ALL 6
#endif
#define WASM_TYPE_FUNC 0
#define WASM_TYPE_STRUCT 1
#define WASM_TYPE_ARRAY 2
#if WASM_ENABLE_STRINGREF != 0
#define WASM_TYPE_STRINGREF 3
#define WASM_TYPE_STRINGVIEWWTF8 4
#define WASM_TYPE_STRINGVIEWWTF16 5
#define WASM_TYPE_STRINGVIEWITER 6
#endif
/* In WasmGC, a table can start with [0x40 0x00] to indicate it has an
* initializer */
#define TABLE_INIT_EXPR_FLAG 0x40
typedef struct WASMModule WASMModule;
typedef struct WASMFunction WASMFunction;
typedef struct WASMGlobal WASMGlobal;
#if WASM_ENABLE_TAGS != 0
typedef struct WASMTag WASMTag;
#endif
#ifndef WASM_VALUE_DEFINED
#define WASM_VALUE_DEFINED
typedef union V128 {
int8 i8x16[16];
int16 i16x8[8];
int32 i32x4[4];
int64 i64x2[2];
float32 f32x4[4];
float64 f64x2[2];
} V128;
typedef union WASMValue {
int32 i32;
uint32 u32;
uint32 global_index;
uint32 ref_index;
int64 i64;
uint64 u64;
float32 f32;
float64 f64;
V128 v128;
#if WASM_ENABLE_GC != 0
wasm_obj_t gc_obj;
uint32 type_index;
struct {
uint32 type_index;
uint32 length;
} array_new_default;
/* pointer to a memory space holding more data, current usage:
* struct.new init value: WASMStructNewInitValues *
* array.new init value: WASMArrayNewInitValues *
*/
void *data;
#endif
} WASMValue;
#endif /* end of WASM_VALUE_DEFINED */
typedef struct WASMStructNewInitValues {
uint32 type_idx;
uint32 count;
WASMValue fields[1];
} WASMStructNewInitValues;
typedef struct WASMArrayNewInitValues {
uint32 type_idx;
uint32 length;
WASMValue elem_data[1];
} WASMArrayNewInitValues;
typedef struct InitializerExpression {
/* type of INIT_EXPR_TYPE_XXX, which is an instruction of
constant expression */
uint8 init_expr_type;
union {
struct {
WASMValue v;
} unary;
struct {
struct InitializerExpression *l_expr;
struct InitializerExpression *r_expr;
} binary;
} u;
} InitializerExpression;
static inline bool
is_expr_binary_op(uint8 flag)
{
return flag == INIT_EXPR_TYPE_I32_ADD || flag == INIT_EXPR_TYPE_I32_SUB
|| flag == INIT_EXPR_TYPE_I32_MUL || flag == INIT_EXPR_TYPE_I64_ADD
|| flag == INIT_EXPR_TYPE_I64_SUB || flag == INIT_EXPR_TYPE_I64_MUL;
}
/* check if table or data offset is valid for i32 offset */
static inline bool
is_valid_i32_offset(uint8 flag)
{
return flag == INIT_EXPR_TYPE_I32_CONST || flag == INIT_EXPR_TYPE_I32_ADD
|| flag == INIT_EXPR_TYPE_I32_SUB || flag == INIT_EXPR_TYPE_I32_MUL;
}
/* check if table or data offset is valid for i64 offset */
static inline bool
is_valid_i64_offset(uint8 flag)
{
return flag == INIT_EXPR_TYPE_I64_CONST || flag == INIT_EXPR_TYPE_I64_ADD
|| flag == INIT_EXPR_TYPE_I64_SUB || flag == INIT_EXPR_TYPE_I64_MUL;
}
#if WASM_ENABLE_GC != 0
/**
* Reference type of (ref null ht) or (ref ht),
* and heap type is defined type (type i), i >= 0
*/
typedef struct RefHeapType_TypeIdx {
/* ref_type is REF_TYPE_HT_NULLABLE or
REF_TYPE_HT_NON_NULLABLE, (0x63 or 0x64) */
uint8 ref_type;
/* true if ref_type is REF_TYPE_HT_NULLABLE */
bool nullable;
/* heap type is defined type: type_index >= 0 */
int32 type_idx;
} RefHeapType_TypeIdx;
/**
* Reference type of (ref null ht) or (ref ht),
* and heap type is non-defined type
*/
typedef struct RefHeapType_Common {
/* ref_type is REF_TYPE_HT_NULLABLE or
REF_TYPE_HT_NON_NULLABLE (0x63 or 0x64) */
uint8 ref_type;
/* true if ref_type is REF_TYPE_HT_NULLABLE */
bool nullable;
/* Common heap type (not defined type):
-0x10 (func), -0x11 (extern), -0x12 (any), -0x13 (eq),
-0x16 (i31), -0x17 (nofunc), -0x18 (noextern),
-0x19 (struct), -0x20 (array), -0x21 (none) */
int32 heap_type;
} RefHeapType_Common;
/**
* Reference type
*/
typedef union WASMRefType {
uint8 ref_type;
RefHeapType_TypeIdx ref_ht_typeidx;
RefHeapType_Common ref_ht_common;
} WASMRefType;
typedef struct WASMRefTypeMap {
/**
* The type index of a type array, which only stores
* the first byte of the type, e.g. WASMFuncType.types,
* WASMStructType.fields
*/
uint16 index;
/* The full type info if the type cannot be described
with one byte */
WASMRefType *ref_type;
} WASMRefTypeMap;
#endif /* end of WASM_ENABLE_GC */
#if WASM_ENABLE_GC == 0
typedef struct WASMFuncType WASMType;
typedef WASMType *WASMTypePtr;
#else
/**
* Common type, store the same fields of
* WASMFuncType, WASMStructType and WASMArrayType
*/
typedef struct WASMType {
/**
* type_flag must be WASM_TYPE_FUNC/STRUCT/ARRAY to
* denote that it is a WASMFuncType, WASMStructType or
* WASMArrayType
*/
uint16 type_flag;
bool is_sub_final;
/* How many types are referring to this type */
uint16 ref_count;
/* The inheritance depth */
uint16 inherit_depth;
/* The root type */
struct WASMType *root_type;
/* The parent type */
struct WASMType *parent_type;
uint32 parent_type_idx;
/* The number of internal types in the current rec group, and if
the type is not in a recursive group, rec_count is 1 since a
single type definition is reinterpreted as a short-hand for a
recursive group containing just one type */
uint16 rec_count;
uint16 rec_idx;
/* The index of the begin type of this group */
uint32 rec_begin_type_idx;
} WASMType, *WASMTypePtr;
#endif /* end of WASM_ENABLE_GC */
/* Function type */
typedef struct WASMFuncType {
#if WASM_ENABLE_GC != 0
WASMType base_type;
#endif
uint16 param_count;
uint16 result_count;
uint16 param_cell_num;
uint16 ret_cell_num;
#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
&& WASM_ENABLE_LAZY_JIT != 0
/* Code block to call llvm jit functions of this
kind of function type from fast jit jitted code */
void *call_to_llvm_jit_from_fast_jit;
#endif
#if WASM_ENABLE_GC != 0
uint16 ref_type_map_count;
WASMRefTypeMap *ref_type_maps;
WASMRefTypeMap *result_ref_type_maps;
#else
uint16 ref_count;
#endif
#if WASM_ENABLE_QUICK_AOT_ENTRY != 0
/* Quick AOT/JIT entry of this func type */
void *quick_aot_entry;
#endif
/* types of params and results, only store the first byte
* of the type, if it cannot be described with one byte,
* then the full type info is stored in ref_type_maps */
uint8 types[1];
} WASMFuncType;
#if WASM_ENABLE_GC != 0
typedef struct WASMStructFieldType {
uint16 field_flags;
uint8 field_type;
uint8 field_size;
uint32 field_offset;
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
/*
* The field size and field offset of a wasm struct may vary
* in 32-bit target and 64-bit target, e.g., the size of a
* GC reference is 4 bytes in the former and 8 bytes in the
* latter, the AOT compiler needs to use the correct field
* offset according to the target info.
*/
uint8 field_size_64bit;
uint8 field_size_32bit;
uint32 field_offset_64bit;
uint32 field_offset_32bit;
#endif
} WASMStructFieldType;
typedef struct WASMStructType {
WASMType base_type;
/* total size of this struct object */
uint32 total_size;
uint16 field_count;
uint16 ref_type_map_count;
WASMRefTypeMap *ref_type_maps;
/* Offsets of reference fields that need to be traced during GC.
The first element of the table is the number of such offsets. */
uint16 *reference_table;
/* Field info, note that fields[i]->field_type only stores
* the first byte of the field type, if it cannot be described
* with one byte, then the full field type info is stored in
* ref_type_maps */
WASMStructFieldType fields[1];
} WASMStructType;
typedef struct WASMArrayType {
WASMType base_type;
uint16 elem_flags;
uint8 elem_type;
/* The full elem type info if the elem type cannot be
described with one byte */
WASMRefType *elem_ref_type;
} WASMArrayType;
#if WASM_ENABLE_STRINGREF != 0
/* stringref representation, we define it as a void * pointer here, the
* stringref implementation can use any structure */
/*
WasmGC heap
+-----------------------+
| |
| stringref |
| +----------+ | external string representation
| | host_ptr |--------o------+----->+------------+
| +----------+ | | | |
| | | +------------+
| stringview_wtf8/16 | |
| +----------+ | |
| | host_ptr |--------o------+
| +----------+ | |
| | |
| stringview_iter | |
| +----------+ | |
| | host_ptr |--------o------+
| +----------+ |
| | pos | |
| +----------+ |
| |
+-----------------------+
*/
typedef void *WASMString;
#endif /* end of WASM_ENABLE_STRINGREF != 0 */
#endif /* end of WASM_ENABLE_GC != 0 */
typedef struct WASMTableType {
uint8 elem_type;
/**
* 0: no max size and not shared
* 1: has max size
* 2: shared
* 4: table64
*/
uint8 flags;
bool possible_grow;
uint32 init_size;
/* specified if (flags & 1), else it is 0x10000 */
uint32 max_size;
#if WASM_ENABLE_GC != 0
WASMRefType *elem_ref_type;
#endif
} WASMTableType;
typedef struct WASMTable {
WASMTableType table_type;
#if WASM_ENABLE_GC != 0
/* init expr for the whole table */
InitializerExpression init_expr;
#endif
} WASMTable;
#if WASM_ENABLE_MEMORY64 != 0
typedef uint64 mem_offset_t;
#define PR_MEM_OFFSET PRIu64
#else
typedef uint32 mem_offset_t;
#define PR_MEM_OFFSET PRIu32
#endif
typedef mem_offset_t tbl_elem_idx_t;
typedef struct WASMMemory {
uint32 flags;
uint32 num_bytes_per_page;
uint32 init_page_count;
uint32 max_page_count;
} WASMMemory;
#ifndef WASM_MEMORY_T_DEFINED
#define WASM_MEMORY_T_DEFINED
typedef struct WASMMemory WASMMemoryType;
#endif
typedef struct WASMTableImport {
char *module_name;
char *field_name;
WASMTableType table_type;
#if WASM_ENABLE_MULTI_MODULE != 0
WASMModule *import_module;
WASMTable *import_table_linked;
#endif
} WASMTableImport;
typedef struct WASMMemoryImport {
char *module_name;
char *field_name;
WASMMemoryType mem_type;
#if WASM_ENABLE_MULTI_MODULE != 0
WASMModule *import_module;
WASMMemory *import_memory_linked;
#endif
} WASMMemoryImport;
typedef struct WASMFunctionImport {
char *module_name;
char *field_name;
/* function type */
WASMFuncType *func_type;
/* native function pointer after linked */
void *func_ptr_linked;
/* signature from registered native symbols */
const char *signature;
/* attachment */
void *attachment;
#if WASM_ENABLE_GC != 0
/* the type index of this function's func_type */
uint32 type_idx;
#endif
#if WASM_ENABLE_INVOKE_NATIVE != 0
bool call_conv_raw;
#endif
bool call_conv_wasm_c_api;
#if WASM_ENABLE_MULTI_MODULE != 0
WASMModule *import_module;
WASMFunction *import_func_linked;
#endif
} WASMFunctionImport;
#if WASM_ENABLE_TAGS != 0
typedef struct WASMTagImport {
char *module_name;
char *field_name;
uint8 attribute; /* the type of the tag (numerical) */
uint32 type; /* the type of the catch function (numerical)*/
WASMFuncType *tag_type;
void *tag_ptr_linked;
#if WASM_ENABLE_MULTI_MODULE != 0
/* imported tag pointer after linked */
WASMModule *import_module;
WASMTag *import_tag_linked;
uint32 import_tag_index_linked;
#endif
} WASMTagImport;
#endif
typedef struct WASMGlobalType {
uint8 val_type;
bool is_mutable;
} WASMGlobalType;
typedef struct WASMGlobalImport {
char *module_name;
char *field_name;
WASMGlobalType type;
bool is_linked;
/* global data after linked */
WASMValue global_data_linked;
#if WASM_ENABLE_GC != 0
WASMRefType *ref_type;
#endif
#if WASM_ENABLE_MULTI_MODULE != 0
/* imported function pointer after linked */
/* TODO: remove if not needed */
WASMModule *import_module;
WASMGlobal *import_global_linked;
#endif
#if WASM_ENABLE_FAST_JIT != 0
/* The data offset of current global in global data */
uint32 data_offset;
#endif
} WASMGlobalImport;
typedef struct WASMImport {
uint8 kind;
union {
WASMFunctionImport function;
WASMTableImport table;
WASMMemoryImport memory;
#if WASM_ENABLE_TAGS != 0
WASMTagImport tag;
#endif
WASMGlobalImport global;
struct {
char *module_name;
char *field_name;
} names;
} u;
} WASMImport;
struct WASMFunction {
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
char *field_name;
#endif
/* the type of function */
WASMFuncType *func_type;
uint32 local_count;
uint8 *local_types;
#if WASM_ENABLE_GC != 0
uint16 local_ref_type_map_count;
WASMRefTypeMap *local_ref_type_maps;
#endif
/* cell num of parameters */
uint16 param_cell_num;
/* cell num of return type */
uint16 ret_cell_num;
/* cell num of local variables */
uint16 local_cell_num;
/* offset of each local, including function parameters
and local variables */
uint16 *local_offsets;
uint32 max_stack_cell_num;
uint32 max_block_num;
uint32 code_size;
uint8 *code;
#if WASM_ENABLE_FAST_INTERP != 0
uint32 code_compiled_size;
uint8 *code_compiled;
uint8 *consts;
uint32 const_cell_num;
#endif
#if WASM_ENABLE_GC != 0
/* the type index of this function's func_type */
uint32 type_idx;
#endif
#if WASM_ENABLE_EXCE_HANDLING != 0
uint32 exception_handler_count;
#endif
#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
|| WASM_ENABLE_WAMR_COMPILER != 0
/* Whether function has opcode memory.grow */
bool has_op_memory_grow;
/* Whether function has opcode call or call_indirect */
bool has_op_func_call;
#endif
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
/* Whether function has memory operation opcodes */
bool has_memory_operations;
/* Whether function has opcode call_indirect */
bool has_op_call_indirect;
/* Whether function has opcode set_global_aux_stack */
bool has_op_set_global_aux_stack;
#endif
#if WASM_ENABLE_FAST_JIT != 0
/* The compiled fast jit jitted code block of this function */
void *fast_jit_jitted_code;
#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0
/* The compiled llvm jit func ptr of this function */
void *llvm_jit_func_ptr;
/* Code block to call fast jit jitted code of this function
from the llvm jit jitted code */
void *call_to_fast_jit_from_llvm_jit;
#endif
#endif
#if WASM_ENABLE_BRANCH_HINTS != 0
uint8 *code_body_begin;
#endif
};
#if WASM_ENABLE_TAGS != 0
struct WASMTag {
uint8 attribute; /* the attribute property of the tag (expected to be 0) */
uint32 type; /* the type of the tag (expected valid inden in type table) */
WASMFuncType *tag_type;
};
#endif
#if WASM_ENABLE_BRANCH_HINTS != 0
enum WASMCompilationHintType {
DUMMY = 0,
WASM_COMPILATION_BRANCH_HINT = 0,
};
struct WASMCompilationHint {
struct WASMCompilationHint *next;
enum WASMCompilationHintType type;
};
struct WASMCompilationHintBranchHint {
struct WASMCompilationHint *next;
enum WASMCompilationHintType type;
uint32 offset;
bool is_likely;
};
#endif
struct WASMGlobal {
WASMGlobalType type;
#if WASM_ENABLE_GC != 0
WASMRefType *ref_type;
#endif
InitializerExpression init_expr;
#if WASM_ENABLE_FAST_JIT != 0
/* The data offset of current global in global data */
uint32 data_offset;
#endif
};
typedef struct WASMExport {
char *name;
uint8 kind;
uint32 index;
} WASMExport;
typedef struct WASMTableSeg {
/* 0 to 7 */
uint32 mode;
/* funcref or externref, elemkind will be considered as funcref */
uint32 elem_type;
#if WASM_ENABLE_GC != 0
WASMRefType *elem_ref_type;
#endif
/* optional, only for active */
uint32 table_index;
InitializerExpression base_offset;
uint32 value_count;
InitializerExpression *init_values;
} WASMTableSeg;
typedef struct WASMDataSeg {
uint32 memory_index;
InitializerExpression base_offset;
uint32 data_length;
#if WASM_ENABLE_BULK_MEMORY != 0
bool is_passive;
#endif
uint8 *data;
bool is_data_cloned;
} WASMDataSeg;
typedef struct BlockAddr {
const uint8 *start_addr;
uint8 *else_addr;
uint8 *end_addr;
} BlockAddr;
#if WASM_ENABLE_LIBC_WASI != 0
typedef struct WASIArguments {
const char **dir_list;
uint32 dir_count;
const char **map_dir_list;
uint32 map_dir_count;
const char **env;
uint32 env_count;
/* in CIDR notation */
const char **addr_pool;
uint32 addr_count;
const char **ns_lookup_pool;
uint32 ns_lookup_count;
char **argv;
uint32 argc;
os_raw_file_handle stdio[3];
} WASIArguments;
#endif
typedef struct StringNode {
struct StringNode *next;
char *str;
} StringNode, *StringList;
typedef struct BrTableCache {
struct BrTableCache *next;
/* Address of br_table opcode */
uint8 *br_table_op_addr;
uint32 br_count;
uint32 br_depths[1];
} BrTableCache;
#if WASM_ENABLE_DEBUG_INTERP != 0
typedef struct WASMFastOPCodeNode {
struct WASMFastOPCodeNode *next;
uint64 offset;
uint8 orig_op;
} WASMFastOPCodeNode;
#endif
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
typedef struct WASMCustomSection {
struct WASMCustomSection *next;
/* Start address of the section name */
char *name_addr;
/* Length of the section name decoded from leb */
uint32 name_len;
/* Start address of the content (name len and name skipped) */
uint8 *content_addr;
uint32 content_len;
} WASMCustomSection;
#endif
#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0
struct AOTCompData;
struct AOTCompContext;
/* Orc JIT thread arguments */
typedef struct OrcJitThreadArg {
#if WASM_ENABLE_JIT != 0
struct AOTCompContext *comp_ctx;
#endif
struct WASMModule *module;
uint32 group_idx;
} OrcJitThreadArg;
#endif
struct WASMModuleInstance;
struct WASMModule {
/* Module type, for module loaded from WASM bytecode binary,
this field is Wasm_Module_Bytecode;
for module loaded from AOT file, this field is
Wasm_Module_AoT, and this structure should be treated as
AOTModule structure. */
uint32 module_type;
/* the package version read from the WASM file */
uint32 package_version;
uint32 type_count;
uint32 import_count;
uint32 function_count;
uint32 table_count;
uint32 memory_count;
#if WASM_ENABLE_TAGS != 0
uint32 tag_count;
#endif
uint32 global_count;
uint32 export_count;
uint32 table_seg_count;
/* data seg count read from data segment section */
uint32 data_seg_count;
#if WASM_ENABLE_BULK_MEMORY != 0
/* data count read from datacount section */
uint32 data_seg_count1;
#endif
#if WASM_ENABLE_GC != 0
#if WASM_ENABLE_STRINGREF != 0
uint32 string_literal_count;
uint32 *string_literal_lengths;
const uint8 **string_literal_ptrs;
#endif
#endif
uint32 import_function_count;
uint32 import_table_count;
uint32 import_memory_count;
#if WASM_ENABLE_TAGS != 0
uint32 import_tag_count;
#endif
uint32 import_global_count;
WASMImport *import_functions;
WASMImport *import_tables;
WASMImport *import_memories;
#if WASM_ENABLE_TAGS != 0
WASMImport *import_tags;
#endif
WASMImport *import_globals;
WASMType **types;
WASMImport *imports;
WASMFunction **functions;
WASMTable *tables;
WASMMemory *memories;
#if WASM_ENABLE_TAGS != 0
WASMTag **tags;
#endif
WASMGlobal *globals;
WASMExport *exports;
WASMTableSeg *table_segments;
WASMDataSeg **data_segments;
uint32 start_function;
/* total global variable size */
uint32 global_data_size;
/* the index of auxiliary __data_end global,
-1 means unexported */
uint32 aux_data_end_global_index;
/* auxiliary __data_end exported by wasm app */
uint64 aux_data_end;
/* the index of auxiliary __heap_base global,
-1 means unexported */
uint32 aux_heap_base_global_index;
/* auxiliary __heap_base exported by wasm app */
uint64 aux_heap_base;
/* the index of auxiliary stack top global,
-1 means unexported */
uint32 aux_stack_top_global_index;
/* auxiliary stack bottom resolved */
uint64 aux_stack_bottom;
/* auxiliary stack size resolved */
uint32 aux_stack_size;
/* the index of malloc/free function,
-1 means unexported */
uint32 malloc_function;
uint32 free_function;
/* the index of __retain function,