-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
dart_api.h
4186 lines (3842 loc) · 146 KB
/
dart_api.h
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) 2012, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
#ifndef RUNTIME_INCLUDE_DART_API_H_
#define RUNTIME_INCLUDE_DART_API_H_
/** \mainpage Dart Embedding API Reference
*
* This reference describes the Dart Embedding API, which is used to embed the
* Dart Virtual Machine within C/C++ applications.
*
* This reference is generated from the header include/dart_api.h.
*/
/* __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to
* enable platform independent printf format specifiers. */
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#if defined(__Fuchsia__)
#include <zircon/types.h>
#endif
#ifdef __cplusplus
#define DART_EXTERN_C extern "C"
#else
#define DART_EXTERN_C extern
#endif
#if defined(__CYGWIN__)
#error Tool chain and platform not supported.
#elif defined(_WIN32)
#if defined(DART_SHARED_LIB)
#define DART_EXPORT DART_EXTERN_C __declspec(dllexport)
#else
#define DART_EXPORT DART_EXTERN_C
#endif
#else
#if __GNUC__ >= 4
#if defined(DART_SHARED_LIB)
#define DART_EXPORT \
DART_EXTERN_C __attribute__((visibility("default"))) __attribute((used))
#else
#define DART_EXPORT DART_EXTERN_C
#endif
#else
#error Tool chain not supported.
#endif
#endif
#if __GNUC__
#define DART_API_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define DART_API_DEPRECATED(msg) __attribute__((deprecated(msg)))
#elif _MSC_VER
#define DART_API_WARN_UNUSED_RESULT _Check_return_
#define DART_API_DEPRECATED(msg) __declspec(deprecated(msg))
#else
#define DART_API_WARN_UNUSED_RESULT
#define DART_API_DEPRECATED(msg)
#endif
/*
* =======
* Handles
* =======
*/
/**
* An isolate is the unit of concurrency in Dart. Each isolate has
* its own memory and thread of control. No state is shared between
* isolates. Instead, isolates communicate by message passing.
*
* Each thread keeps track of its current isolate, which is the
* isolate which is ready to execute on the current thread. The
* current isolate may be NULL, in which case no isolate is ready to
* execute. Most of the Dart apis require there to be a current
* isolate in order to function without error. The current isolate is
* set by any call to Dart_CreateIsolateGroup or Dart_EnterIsolate.
*/
typedef struct _Dart_Isolate* Dart_Isolate;
typedef struct _Dart_IsolateGroup* Dart_IsolateGroup;
/**
* An object reference managed by the Dart VM garbage collector.
*
* Because the garbage collector may move objects, it is unsafe to
* refer to objects directly. Instead, we refer to objects through
* handles, which are known to the garbage collector and updated
* automatically when the object is moved. Handles should be passed
* by value (except in cases like out-parameters) and should never be
* allocated on the heap.
*
* Most functions in the Dart Embedding API return a handle. When a
* function completes normally, this will be a valid handle to an
* object in the Dart VM heap. This handle may represent the result of
* the operation or it may be a special valid handle used merely to
* indicate successful completion. Note that a valid handle may in
* some cases refer to the null object.
*
* --- Error handles ---
*
* When a function encounters a problem that prevents it from
* completing normally, it returns an error handle (See Dart_IsError).
* An error handle has an associated error message that gives more
* details about the problem (See Dart_GetError).
*
* There are four kinds of error handles that can be produced,
* depending on what goes wrong:
*
* - Api error handles are produced when an api function is misused.
* This happens when a Dart embedding api function is called with
* invalid arguments or in an invalid context.
*
* - Unhandled exception error handles are produced when, during the
* execution of Dart code, an exception is thrown but not caught.
* Prototypically this would occur during a call to Dart_Invoke, but
* it can occur in any function which triggers the execution of Dart
* code (for example, Dart_ToString).
*
* An unhandled exception error provides access to an exception and
* stacktrace via the functions Dart_ErrorGetException and
* Dart_ErrorGetStackTrace.
*
* - Compilation error handles are produced when, during the execution
* of Dart code, a compile-time error occurs. As above, this can
* occur in any function which triggers the execution of Dart code.
*
* - Fatal error handles are produced when the system wants to shut
* down the current isolate.
*
* --- Propagating errors ---
*
* When an error handle is returned from the top level invocation of
* Dart code in a program, the embedder must handle the error as they
* see fit. Often, the embedder will print the error message produced
* by Dart_Error and exit the program.
*
* When an error is returned while in the body of a native function,
* it can be propagated up the call stack by calling
* Dart_PropagateError, Dart_SetReturnValue, or Dart_ThrowException.
* Errors should be propagated unless there is a specific reason not
* to. If an error is not propagated then it is ignored. For
* example, if an unhandled exception error is ignored, that
* effectively "catches" the unhandled exception. Fatal errors must
* always be propagated.
*
* When an error is propagated, any current scopes created by
* Dart_EnterScope will be exited.
*
* Using Dart_SetReturnValue to propagate an exception is somewhat
* more convenient than using Dart_PropagateError, and should be
* preferred for reasons discussed below.
*
* Dart_PropagateError and Dart_ThrowException do not return. Instead
* they transfer control non-locally using a setjmp-like mechanism.
* This can be inconvenient if you have resources that you need to
* clean up before propagating the error.
*
* When relying on Dart_PropagateError, we often return error handles
* rather than propagating them from helper functions. Consider the
* following contrived example:
*
* 1 Dart_Handle isLongStringHelper(Dart_Handle arg) {
* 2 intptr_t* length = 0;
* 3 result = Dart_StringLength(arg, &length);
* 4 if (Dart_IsError(result)) {
* 5 return result;
* 6 }
* 7 return Dart_NewBoolean(length > 100);
* 8 }
* 9
* 10 void NativeFunction_isLongString(Dart_NativeArguments args) {
* 11 Dart_EnterScope();
* 12 AllocateMyResource();
* 13 Dart_Handle arg = Dart_GetNativeArgument(args, 0);
* 14 Dart_Handle result = isLongStringHelper(arg);
* 15 if (Dart_IsError(result)) {
* 16 FreeMyResource();
* 17 Dart_PropagateError(result);
* 18 abort(); // will not reach here
* 19 }
* 20 Dart_SetReturnValue(result);
* 21 FreeMyResource();
* 22 Dart_ExitScope();
* 23 }
*
* In this example, we have a native function which calls a helper
* function to do its work. On line 5, the helper function could call
* Dart_PropagateError, but that would not give the native function a
* chance to call FreeMyResource(), causing a leak. Instead, the
* helper function returns the error handle to the caller, giving the
* caller a chance to clean up before propagating the error handle.
*
* When an error is propagated by calling Dart_SetReturnValue, the
* native function will be allowed to complete normally and then the
* exception will be propagated only once the native call
* returns. This can be convenient, as it allows the C code to clean
* up normally.
*
* The example can be written more simply using Dart_SetReturnValue to
* propagate the error.
*
* 1 Dart_Handle isLongStringHelper(Dart_Handle arg) {
* 2 intptr_t* length = 0;
* 3 result = Dart_StringLength(arg, &length);
* 4 if (Dart_IsError(result)) {
* 5 return result
* 6 }
* 7 return Dart_NewBoolean(length > 100);
* 8 }
* 9
* 10 void NativeFunction_isLongString(Dart_NativeArguments args) {
* 11 Dart_EnterScope();
* 12 AllocateMyResource();
* 13 Dart_Handle arg = Dart_GetNativeArgument(args, 0);
* 14 Dart_SetReturnValue(isLongStringHelper(arg));
* 15 FreeMyResource();
* 16 Dart_ExitScope();
* 17 }
*
* In this example, the call to Dart_SetReturnValue on line 14 will
* either return the normal return value or the error (potentially
* generated on line 3). The call to FreeMyResource on line 15 will
* execute in either case.
*
* --- Local and persistent handles ---
*
* Local handles are allocated within the current scope (see
* Dart_EnterScope) and go away when the current scope exits. Unless
* otherwise indicated, callers should assume that all functions in
* the Dart embedding api return local handles.
*
* Persistent handles are allocated within the current isolate. They
* can be used to store objects across scopes. Persistent handles have
* the lifetime of the current isolate unless they are explicitly
* deallocated (see Dart_DeletePersistentHandle).
* The type Dart_Handle represents a handle (both local and persistent).
* The type Dart_PersistentHandle is a Dart_Handle and it is used to
* document that a persistent handle is expected as a parameter to a call
* or the return value from a call is a persistent handle.
*
* FinalizableHandles are persistent handles which are auto deleted when
* the object is garbage collected. It is never safe to use these handles
* unless you know the object is still reachable.
*
* WeakPersistentHandles are persistent handles which are automatically set
* to point Dart_Null when the object is garbage collected. They are not auto
* deleted, so it is safe to use them after the object has become unreachable.
*/
typedef struct _Dart_Handle* Dart_Handle;
typedef Dart_Handle Dart_PersistentHandle;
typedef struct _Dart_WeakPersistentHandle* Dart_WeakPersistentHandle;
typedef struct _Dart_FinalizableHandle* Dart_FinalizableHandle;
// These structs are versioned by DART_API_DL_MAJOR_VERSION, bump the
// version when changing this struct.
typedef void (*Dart_HandleFinalizer)(void* isolate_callback_data, void* peer);
/**
* Is this an error handle?
*
* Requires there to be a current isolate.
*/
DART_EXPORT bool Dart_IsError(Dart_Handle handle);
/**
* Is this an api error handle?
*
* Api error handles are produced when an api function is misused.
* This happens when a Dart embedding api function is called with
* invalid arguments or in an invalid context.
*
* Requires there to be a current isolate.
*/
DART_EXPORT bool Dart_IsApiError(Dart_Handle handle);
/**
* Is this an unhandled exception error handle?
*
* Unhandled exception error handles are produced when, during the
* execution of Dart code, an exception is thrown but not caught.
* This can occur in any function which triggers the execution of Dart
* code.
*
* See Dart_ErrorGetException and Dart_ErrorGetStackTrace.
*
* Requires there to be a current isolate.
*/
DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle handle);
/**
* Is this a compilation error handle?
*
* Compilation error handles are produced when, during the execution
* of Dart code, a compile-time error occurs. This can occur in any
* function which triggers the execution of Dart code.
*
* Requires there to be a current isolate.
*/
DART_EXPORT bool Dart_IsCompilationError(Dart_Handle handle);
/**
* Is this a fatal error handle?
*
* Fatal error handles are produced when the system wants to shut down
* the current isolate.
*
* Requires there to be a current isolate.
*/
DART_EXPORT bool Dart_IsFatalError(Dart_Handle handle);
/**
* Gets the error message from an error handle.
*
* Requires there to be a current isolate.
*
* \return A C string containing an error message if the handle is
* error. An empty C string ("") if the handle is valid. This C
* String is scope allocated and is only valid until the next call
* to Dart_ExitScope.
*/
DART_EXPORT const char* Dart_GetError(Dart_Handle handle);
/**
* Is this an error handle for an unhandled exception?
*/
DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle);
/**
* Gets the exception Object from an unhandled exception error handle.
*/
DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle);
/**
* Gets the stack trace Object from an unhandled exception error handle.
*/
DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle);
/**
* Produces an api error handle with the provided error message.
*
* Requires there to be a current isolate.
*
* \param error the error message.
*/
DART_EXPORT Dart_Handle Dart_NewApiError(const char* error);
DART_EXPORT Dart_Handle Dart_NewCompilationError(const char* error);
/**
* Produces a new unhandled exception error handle.
*
* Requires there to be a current isolate.
*
* \param exception An instance of a Dart object to be thrown or
* an ApiError or CompilationError handle.
* When an ApiError or CompilationError handle is passed in
* a string object of the error message is created and it becomes
* the Dart object to be thrown.
*/
DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception);
/**
* Propagates an error.
*
* If the provided handle is an unhandled exception error, this
* function will cause the unhandled exception to be rethrown. This
* will proceed in the standard way, walking up Dart frames until an
* appropriate 'catch' block is found, executing 'finally' blocks,
* etc.
*
* If the error is not an unhandled exception error, we will unwind
* the stack to the next C frame. Intervening Dart frames will be
* discarded; specifically, 'finally' blocks will not execute. This
* is the standard way that compilation errors (and the like) are
* handled by the Dart runtime.
*
* In either case, when an error is propagated any current scopes
* created by Dart_EnterScope will be exited.
*
* See the additional discussion under "Propagating Errors" at the
* beginning of this file.
*
* \param handle An error handle (See Dart_IsError)
*
* On success, this function does not return. On failure, the
* process is terminated.
*/
DART_EXPORT void Dart_PropagateError(Dart_Handle handle);
/**
* Converts an object to a string.
*
* May generate an unhandled exception error.
*
* \return The converted string if no error occurs during
* the conversion. If an error does occur, an error handle is
* returned.
*/
DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object);
/**
* Checks to see if two handles refer to identically equal objects.
*
* If both handles refer to instances, this is equivalent to using the top-level
* function identical() from dart:core. Otherwise, returns whether the two
* argument handles refer to the same object.
*
* \param obj1 An object to be compared.
* \param obj2 An object to be compared.
*
* \return True if the objects are identically equal. False otherwise.
*/
DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2);
/**
* Allocates a handle in the current scope from a persistent handle.
*/
DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object);
/**
* Allocates a handle in the current scope from a weak persistent handle.
*
* This will be a handle to Dart_Null if the object has been garbage collected.
*/
DART_EXPORT Dart_Handle
Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object);
/**
* Allocates a persistent handle for an object.
*
* This handle has the lifetime of the current isolate unless it is
* explicitly deallocated by calling Dart_DeletePersistentHandle.
*
* Requires there to be a current isolate.
*/
DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object);
/**
* Assign value of local handle to a persistent handle.
*
* Requires there to be a current isolate.
*
* \param obj1 A persistent handle whose value needs to be set.
* \param obj2 An object whose value needs to be set to the persistent handle.
*/
DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1,
Dart_Handle obj2);
/**
* Deallocates a persistent handle.
*
* Requires there to be a current isolate group.
*/
DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object);
/**
* Allocates a weak persistent handle for an object.
*
* This handle has the lifetime of the current isolate. The handle can also be
* explicitly deallocated by calling Dart_DeleteWeakPersistentHandle.
*
* If the object becomes unreachable the callback is invoked with the peer as
* argument. The callback can be executed on any thread, will have a current
* isolate group, but will not have a current isolate. The callback can only
* call Dart_DeletePersistentHandle or Dart_DeleteWeakPersistentHandle. This
* gives the embedder the ability to cleanup data associated with the object.
* The handle will point to the Dart_Null object after the finalizer has been
* run. It is illegal to call into the VM with any other Dart_* functions from
* the callback. If the handle is deleted before the object becomes
* unreachable, the callback is never invoked.
*
* Requires there to be a current isolate.
*
* \param object An object with identity.
* \param peer A pointer to a native object or NULL. This value is
* provided to callback when it is invoked.
* \param external_allocation_size The number of externally allocated
* bytes for peer. Used to inform the garbage collector.
* \param callback A function pointer that will be invoked sometime
* after the object is garbage collected, unless the handle has been deleted.
* A valid callback needs to be specified it cannot be NULL.
*
* \return The weak persistent handle or NULL. NULL is returned in case of bad
* parameters.
*/
DART_EXPORT Dart_WeakPersistentHandle
Dart_NewWeakPersistentHandle(Dart_Handle object,
void* peer,
intptr_t external_allocation_size,
Dart_HandleFinalizer callback);
/**
* Deletes the given weak persistent [object] handle.
*
* Requires there to be a current isolate group.
*/
DART_EXPORT void Dart_DeleteWeakPersistentHandle(
Dart_WeakPersistentHandle object);
/**
* Allocates a finalizable handle for an object.
*
* This handle has the lifetime of the current isolate group unless the object
* pointed to by the handle is garbage collected, in this case the VM
* automatically deletes the handle after invoking the callback associated
* with the handle. The handle can also be explicitly deallocated by
* calling Dart_DeleteFinalizableHandle.
*
* If the object becomes unreachable the callback is invoked with the
* the peer as argument. The callback can be executed on any thread, will have
* an isolate group, but will not have a current isolate. The callback can only
* call Dart_DeletePersistentHandle or Dart_DeleteWeakPersistentHandle.
* This gives the embedder the ability to cleanup data associated with the
* object and clear out any cached references to the handle. All references to
* this handle after the callback will be invalid. It is illegal to call into
* the VM with any other Dart_* functions from the callback. If the handle is
* deleted before the object becomes unreachable, the callback is never
* invoked.
*
* Requires there to be a current isolate.
*
* \param object An object with identity.
* \param peer A pointer to a native object or NULL. This value is
* provided to callback when it is invoked.
* \param external_allocation_size The number of externally allocated
* bytes for peer. Used to inform the garbage collector.
* \param callback A function pointer that will be invoked sometime
* after the object is garbage collected, unless the handle has been deleted.
* A valid callback needs to be specified it cannot be NULL.
*
* \return The finalizable handle or NULL. NULL is returned in case of bad
* parameters.
*/
DART_EXPORT Dart_FinalizableHandle
Dart_NewFinalizableHandle(Dart_Handle object,
void* peer,
intptr_t external_allocation_size,
Dart_HandleFinalizer callback);
/**
* Deletes the given finalizable [object] handle.
*
* The caller has to provide the actual Dart object the handle was created from
* to prove the object (and therefore the finalizable handle) is still alive.
*
* Requires there to be a current isolate.
*/
DART_EXPORT void Dart_DeleteFinalizableHandle(Dart_FinalizableHandle object,
Dart_Handle strong_ref_to_object);
/*
* ==========================
* Initialization and Globals
* ==========================
*/
/**
* Gets the version string for the Dart VM.
*
* The version of the Dart VM can be accessed without initializing the VM.
*
* \return The version string for the embedded Dart VM.
*/
DART_EXPORT const char* Dart_VersionString(void);
/**
* Isolate specific flags are set when creating a new isolate using the
* Dart_IsolateFlags structure.
*
* Current version of flags is encoded in a 32-bit integer with 16 bits used
* for each part.
*/
#define DART_FLAGS_CURRENT_VERSION (0x0000000d)
typedef struct {
int32_t version;
bool enable_asserts;
bool use_field_guards;
bool use_osr;
bool obfuscate;
bool load_vmservice_library;
bool null_safety;
bool is_system_isolate;
bool is_service_isolate;
bool is_kernel_isolate;
bool snapshot_is_dontneed_safe;
bool branch_coverage;
bool coverage;
} Dart_IsolateFlags;
/**
* Initialize Dart_IsolateFlags with correct version and default values.
*/
DART_EXPORT void Dart_IsolateFlagsInitialize(Dart_IsolateFlags* flags);
/**
* An isolate creation and initialization callback function.
*
* This callback, provided by the embedder, is called when the VM
* needs to create an isolate. The callback should create an isolate
* by calling Dart_CreateIsolateGroup and load any scripts required for
* execution.
*
* This callback may be called on a different thread than the one
* running the parent isolate.
*
* When the function returns NULL, it is the responsibility of this
* function to ensure that Dart_ShutdownIsolate has been called if
* required (for example, if the isolate was created successfully by
* Dart_CreateIsolateGroup() but the root library fails to load
* successfully, then the function should call Dart_ShutdownIsolate
* before returning).
*
* When the function returns NULL, the function should set *error to
* a malloc-allocated buffer containing a useful error message. The
* caller of this function (the VM) will make sure that the buffer is
* freed.
*
* \param script_uri The uri of the main source file or snapshot to load.
* Either the URI of the parent isolate set in Dart_CreateIsolateGroup for
* Isolate.spawn, or the argument to Isolate.spawnUri canonicalized by the
* library tag handler of the parent isolate.
* The callback is responsible for loading the program by a call to
* Dart_LoadScriptFromKernel.
* \param main The name of the main entry point this isolate will
* eventually run. This is provided for advisory purposes only to
* improve debugging messages. The main function is not invoked by
* this function.
* \param package_root Ignored.
* \param package_config Uri of the package configuration file (either in format
* of .packages or .dart_tool/package_config.json) for this isolate
* to resolve package imports against. If this parameter is not passed the
* package resolution of the parent isolate should be used.
* \param flags Default flags for this isolate being spawned. Either inherited
* from the spawning isolate or passed as parameters when spawning the
* isolate from Dart code.
* \param isolate_data The isolate data which was passed to the
* parent isolate when it was created by calling Dart_CreateIsolateGroup().
* \param error A structure into which the embedder can place a
* C string containing an error message in the case of failures.
*
* \return The embedder returns NULL if the creation and
* initialization was not successful and the isolate if successful.
*/
typedef Dart_Isolate (*Dart_IsolateGroupCreateCallback)(
const char* script_uri,
const char* main,
const char* package_root,
const char* package_config,
Dart_IsolateFlags* flags,
void* isolate_data,
char** error);
/**
* An isolate initialization callback function.
*
* This callback, provided by the embedder, is called when the VM has created an
* isolate within an existing isolate group (i.e. from the same source as an
* existing isolate).
*
* The callback should setup native resolvers and might want to set a custom
* message handler via [Dart_SetMessageNotifyCallback] and mark the isolate as
* runnable.
*
* This callback may be called on a different thread than the one
* running the parent isolate.
*
* When the function returns `false`, it is the responsibility of this
* function to ensure that `Dart_ShutdownIsolate` has been called.
*
* When the function returns `false`, the function should set *error to
* a malloc-allocated buffer containing a useful error message. The
* caller of this function (the VM) will make sure that the buffer is
* freed.
*
* \param child_isolate_data The callback data to associate with the new
* child isolate.
* \param error A structure into which the embedder can place a
* C string containing an error message in the case the initialization fails.
*
* \return The embedder returns true if the initialization was successful and
* false otherwise (in which case the VM will terminate the isolate).
*/
typedef bool (*Dart_InitializeIsolateCallback)(void** child_isolate_data,
char** error);
/**
* An isolate shutdown callback function.
*
* This callback, provided by the embedder, is called before the vm
* shuts down an isolate. The isolate being shutdown will be the current
* isolate. It is safe to run Dart code.
*
* This function should be used to dispose of native resources that
* are allocated to an isolate in order to avoid leaks.
*
* \param isolate_group_data The same callback data which was passed to the
* isolate group when it was created.
* \param isolate_data The same callback data which was passed to the isolate
* when it was created.
*/
typedef void (*Dart_IsolateShutdownCallback)(void* isolate_group_data,
void* isolate_data);
/**
* An isolate cleanup callback function.
*
* This callback, provided by the embedder, is called after the vm
* shuts down an isolate. There will be no current isolate and it is *not*
* safe to run Dart code.
*
* This function should be used to dispose of native resources that
* are allocated to an isolate in order to avoid leaks.
*
* \param isolate_group_data The same callback data which was passed to the
* isolate group when it was created.
* \param isolate_data The same callback data which was passed to the isolate
* when it was created.
*/
typedef void (*Dart_IsolateCleanupCallback)(void* isolate_group_data,
void* isolate_data);
/**
* An isolate group cleanup callback function.
*
* This callback, provided by the embedder, is called after the vm
* shuts down an isolate group.
*
* This function should be used to dispose of native resources that
* are allocated to an isolate in order to avoid leaks.
*
* \param isolate_group_data The same callback data which was passed to the
* isolate group when it was created.
*
*/
typedef void (*Dart_IsolateGroupCleanupCallback)(void* isolate_group_data);
/**
* A thread start callback function.
* This callback, provided by the embedder, is called after a thread in the
* vm thread pool starts.
* This function could be used to adjust thread priority or attach native
* resources to the thread.
*/
typedef void (*Dart_ThreadStartCallback)(void);
/**
* A thread death callback function.
* This callback, provided by the embedder, is called before a thread in the
* vm thread pool exits.
* This function could be used to dispose of native resources that
* are associated and attached to the thread, in order to avoid leaks.
*/
typedef void (*Dart_ThreadExitCallback)(void);
/**
* Opens a file for reading or writing.
*
* Callback provided by the embedder for file operations. If the
* embedder does not allow file operations this callback can be
* NULL.
*
* \param name The name of the file to open.
* \param write A boolean variable which indicates if the file is to
* opened for writing. If there is an existing file it needs to truncated.
*/
typedef void* (*Dart_FileOpenCallback)(const char* name, bool write);
/**
* Read contents of file.
*
* Callback provided by the embedder for file operations. If the
* embedder does not allow file operations this callback can be
* NULL.
*
* \param data Buffer allocated in the callback into which the contents
* of the file are read into. It is the responsibility of the caller to
* free this buffer.
* \param file_length A variable into which the length of the file is returned.
* In the case of an error this value would be -1.
* \param stream Handle to the opened file.
*/
typedef void (*Dart_FileReadCallback)(uint8_t** data,
intptr_t* file_length,
void* stream);
/**
* Write data into file.
*
* Callback provided by the embedder for file operations. If the
* embedder does not allow file operations this callback can be
* NULL.
*
* \param data Buffer which needs to be written into the file.
* \param length Length of the buffer.
* \param stream Handle to the opened file.
*/
typedef void (*Dart_FileWriteCallback)(const void* data,
intptr_t length,
void* stream);
/**
* Closes the opened file.
*
* Callback provided by the embedder for file operations. If the
* embedder does not allow file operations this callback can be
* NULL.
*
* \param stream Handle to the opened file.
*/
typedef void (*Dart_FileCloseCallback)(void* stream);
typedef bool (*Dart_EntropySource)(uint8_t* buffer, intptr_t length);
/**
* Callback provided by the embedder that is used by the vmservice isolate
* to request the asset archive. The asset archive must be an uncompressed tar
* archive that is stored in a Uint8List.
*
* If the embedder has no vmservice isolate assets, the callback can be NULL.
*
* \return The embedder must return a handle to a Uint8List containing an
* uncompressed tar archive or null.
*/
typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(void);
/**
* The current version of the Dart_InitializeFlags. Should be incremented every
* time Dart_InitializeFlags changes in a binary incompatible way.
*/
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000008)
/** Forward declaration */
struct Dart_CodeObserver;
/**
* Callback provided by the embedder that is used by the VM to notify on code
* object creation, *before* it is invoked the first time.
* This is useful for embedders wanting to e.g. keep track of PCs beyond
* the lifetime of the garbage collected code objects.
* Note that an address range may be used by more than one code object over the
* lifecycle of a process. Clients of this function should record timestamps for
* these compilation events and when collecting PCs to disambiguate reused
* address ranges.
*/
typedef void (*Dart_OnNewCodeCallback)(struct Dart_CodeObserver* observer,
const char* name,
uintptr_t base,
uintptr_t size);
typedef struct Dart_CodeObserver {
void* data;
Dart_OnNewCodeCallback on_new_code;
} Dart_CodeObserver;
/**
* Optional callback provided by the embedder that is used by the VM to
* implement registration of kernel blobs for the subsequent Isolate.spawnUri
* If no callback is provided, the registration of kernel blobs will throw
* an error.
*
* \param kernel_buffer A buffer which contains a kernel program. Callback
* should copy the contents of `kernel_buffer` as
* it may be freed immediately after registration.
* \param kernel_buffer_size The size of `kernel_buffer`.
*
* \return A C string representing URI which can be later used
* to spawn a new isolate. This C String should be scope allocated
* or owned by the embedder.
* Returns NULL if embedder runs out of memory.
*/
typedef const char* (*Dart_RegisterKernelBlobCallback)(
const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size);
/**
* Optional callback provided by the embedder that is used by the VM to
* unregister kernel blobs.
* If no callback is provided, the unregistration of kernel blobs will throw
* an error.
*
* \param kernel_blob_uri URI of the kernel blob to unregister.
*/
typedef void (*Dart_UnregisterKernelBlobCallback)(const char* kernel_blob_uri);
/**
* Describes how to initialize the VM. Used with Dart_Initialize.
*/
typedef struct {
/**
* Identifies the version of the struct used by the client.
* should be initialized to DART_INITIALIZE_PARAMS_CURRENT_VERSION.
*/
int32_t version;
/**
* A buffer containing snapshot data, or NULL if no snapshot is provided.
*
* If provided, the buffer must remain valid until Dart_Cleanup returns.
*/
const uint8_t* vm_snapshot_data;
/**
* A buffer containing a snapshot of precompiled instructions, or NULL if
* no snapshot is provided.
*
* If provided, the buffer must remain valid until Dart_Cleanup returns.
*/
const uint8_t* vm_snapshot_instructions;
/**
* A function to be called during isolate group creation.
* See Dart_IsolateGroupCreateCallback.
*/
Dart_IsolateGroupCreateCallback create_group;
/**
* A function to be called during isolate
* initialization inside an existing isolate group.
* See Dart_InitializeIsolateCallback.
*/
Dart_InitializeIsolateCallback initialize_isolate;
/**
* A function to be called right before an isolate is shutdown.
* See Dart_IsolateShutdownCallback.
*/
Dart_IsolateShutdownCallback shutdown_isolate;
/**
* A function to be called after an isolate was shutdown.
* See Dart_IsolateCleanupCallback.
*/
Dart_IsolateCleanupCallback cleanup_isolate;
/**
* A function to be called after an isolate group is
* shutdown. See Dart_IsolateGroupCleanupCallback.
*/
Dart_IsolateGroupCleanupCallback cleanup_group;
Dart_ThreadStartCallback thread_start;
Dart_ThreadExitCallback thread_exit;
Dart_FileOpenCallback file_open;
Dart_FileReadCallback file_read;
Dart_FileWriteCallback file_write;
Dart_FileCloseCallback file_close;
Dart_EntropySource entropy_source;
/**
* A function to be called by the service isolate when it requires the
* vmservice assets archive. See Dart_GetVMServiceAssetsArchive.
*/
Dart_GetVMServiceAssetsArchive get_service_assets;
bool start_kernel_isolate;
/**
* An external code observer callback function. The observer can be invoked
* as early as during the Dart_Initialize() call.
*/
Dart_CodeObserver* code_observer;
/**
* Kernel blob registration callback function. See Dart_RegisterKernelBlobCallback.
*/
Dart_RegisterKernelBlobCallback register_kernel_blob;
/**
* Kernel blob unregistration callback function. See Dart_UnregisterKernelBlobCallback.
*/
Dart_UnregisterKernelBlobCallback unregister_kernel_blob;
#if defined(__Fuchsia__)
/**
* The resource needed to use zx_vmo_replace_as_executable. Can be
* ZX_HANDLE_INVALID if the process has ambient-replace-as-executable or if
* executable memory is not needed (e.g., this is an AOT runtime).
*/
zx_handle_t vmex_resource;
#endif
} Dart_InitializeParams;
/**
* Initializes the VM.
*
* \param params A struct containing initialization information. The version
* field of the struct must be DART_INITIALIZE_PARAMS_CURRENT_VERSION.
*
* \return NULL if initialization is successful. Returns an error message