183 {
184#define DECLARE(Name, value) k##Name = value,
186#undef DECLARE
187};
188
189
204
205
211};
212
213
219};
220
221
228};
229
230
237};
238
239
242};
243
244
248};
249
250
253};
254
255
258};
259
260
263};
264
265
268};
269
270
276};
277
282
284
285class Reader : public ValueObject {
286 public:
287 explicit Reader(const TypedDataBase& typed_data)
288 : thread_(Thread::Current()), typed_data_(&typed_data) {
290 }
291
292 uint32_t ReadFromIndex(intptr_t end_offset,
293 intptr_t fields_before,
294 intptr_t list_size,
295 intptr_t list_index) {
296 intptr_t org_offset =
offset();
298 ReadFromIndexNoReset(end_offset, fields_before, list_size, list_index);
299 offset_ = org_offset;
301 }
302
303 uint32_t ReadUInt32At(intptr_t
offset)
const {
306 LoadUnaligned(
reinterpret_cast<const uint32_t*
>(raw_buffer_ +
offset));
307 return Utils::BigEndianToHost32(value);
308 }
309
310 uint32_t ReadFromIndexNoReset(intptr_t end_offset,
311 intptr_t fields_before,
312 intptr_t list_size,
313 intptr_t list_index) {
314 offset_ = end_offset - (fields_before + list_size - list_index) * 4;
316 }
317
319 uint32_t
value = ReadUInt32At(offset_);
320 offset_ += 4;
322 }
323
324 double ReadDouble() {
325 ASSERT((size_ >= 8) && (offset_ >= 0) && (offset_ <= size_ - 8));
327 LoadUnaligned(reinterpret_cast<const double*>(&raw_buffer_[offset_]));
328 offset_ += 8;
330 }
331
332 uint32_t ReadUInt() {
333 ASSERT((size_ >= 1) && (offset_ >= 0) && (offset_ <= size_ - 1));
334
335 const uint8_t*
buffer = raw_buffer_;
337 if ((byte0 & 0x80) == 0) {
338
339 offset_++;
340 return byte0;
341 } else if ((byte0 & 0xc0) == 0x80) {
342
343 ASSERT((size_ >= 2) && (offset_ >= 0) && (offset_ <= size_ - 2));
345 ((byte0 & ~static_cast<uword>(0x80)) << 8) | (
buffer[offset_ + 1]);
346 offset_ += 2;
348 } else {
349
350 ASSERT((size_ >= 4) && (offset_ >= 0) && (offset_ <= size_ - 4));
351 uint32_t
value = ((byte0 & ~static_cast<uword>(0xc0)) << 24) |
352 (
buffer[offset_ + 1] << 16) |
353 (
buffer[offset_ + 2] << 8) | (
buffer[offset_ + 3] << 0);
354 offset_ += 4;
356 }
357 }
358
359 intptr_t ReadSLEB128() {
360 ReadStream
stream(raw_buffer_, size_, offset_);
362 offset_ =
stream.Position();
364 }
365
366 int64_t ReadSLEB128AsInt64() {
367 ReadStream
stream(raw_buffer_, size_, offset_);
369 offset_ =
stream.Position();
371 }
372
373
374
375
376 TokenPosition ReadPosition() {
377
378
379 intptr_t
value = ReadUInt() - 1;
380 TokenPosition
result = TokenPosition::Deserialize(value);
381 max_position_ = TokenPosition::Max(max_position_,
result);
382 min_position_ = TokenPosition::Min(min_position_,
result);
384 }
385
386 intptr_t ReadListLength() { return ReadUInt(); }
387
388 uint8_t ReadByte() { return raw_buffer_[offset_++]; }
389
390 uint8_t
PeekByte() {
return raw_buffer_[offset_]; }
391
392 void ReadBytes(uint8_t*
buffer, uint8_t size) {
393 for (
int i = 0; i <
size; i++) {
395 }
396 }
397
398 bool ReadBool() { return (ReadByte() & 1) == 1; }
399
400 uint8_t ReadFlags() { return ReadByte(); }
401
402 static const char* TagName(Tag tag);
403
404 Tag ReadTag(uint8_t* payload =
nullptr) {
405 uint8_t byte = ReadByte();
406 bool has_payload =
408 if (has_payload) {
409 if (payload != nullptr) {
411 }
413 } else {
414 return static_cast<Tag>(byte);
415 }
416 }
417
418 Tag PeekTag(uint8_t* payload =
nullptr) {
420 bool has_payload =
422 if (has_payload) {
423 if (payload != nullptr) {
425 }
427 } else {
428 return static_cast<Tag>(byte);
429 }
430 }
431
432 static Nullability ConvertNullability(KernelNullability kernel_nullability) {
433 switch (kernel_nullability) {
434 case KernelNullability::kNullable:
435 return Nullability::kNullable;
436 case KernelNullability::kLegacy:
437 return Nullability::kLegacy;
438 case KernelNullability::kNonNullable:
439 case KernelNullability::kUndetermined:
440 return Nullability::kNonNullable;
441 }
443 }
444
446 const uint8_t byte = ReadByte();
448 }
449
451 uint8_t byte = ReadByte();
453 }
454
455 void EnsureEnd() {
456 if (offset_ != size_) {
458 "Reading Kernel file: Expected to be at EOF "
459 "(offset: %" Pd ", size: %" Pd ")",
460 offset_, size_);
461 }
462 }
463
464
465
466
467 TokenPosition max_position() { return max_position_; }
468
469
470
471 TokenPosition min_position() { return min_position_; }
472
473
474
475 NameIndex ReadCanonicalNameReference() { return NameIndex(ReadUInt() - 1); }
476
477 const TypedDataBase* typed_data() { return typed_data_; }
478
479 intptr_t
offset()
const {
return offset_; }
480 void set_offset(intptr_t
offset) {
483 }
484 intptr_t
size()
const {
return size_; }
485
486 TypedDataViewPtr ViewFromTo(intptr_t
start, intptr_t
end) {
487 return typed_data_->ViewFromTo(
start,
end, Heap::kOld);
488 }
489
490 const uint8_t* BufferAt(intptr_t
offset) {
492 return &raw_buffer_[
offset];
493 }
494
495 TypedDataPtr ReadLineStartsData(intptr_t line_start_count);
496
497 private:
498 friend class Program;
499 friend class AlternativeReadingScopeWithNewData;
500 friend class AlternativeReadingScope;
501
502 Reader(
const uint8_t*
buffer, intptr_t size)
503 : thread_(nullptr), raw_buffer_(
buffer), size_(
size) {}
504
506 ASSERT(typed_data_->IsExternalOrExternalView());
507 raw_buffer_ = reinterpret_cast<uint8_t*>(typed_data_->DataAddr(0));
508 size_ = typed_data_->LengthInBytes();
509 offset_ = 0;
510 }
511
512 Thread* thread_ = nullptr;
513
514
515 const TypedDataBase* typed_data_ = nullptr;
516
517
518 const uint8_t* raw_buffer_ = nullptr;
519 intptr_t size_ = 0;
520
521 intptr_t offset_ = 0;
522 TokenPosition max_position_ = TokenPosition::kNoSource;
523 TokenPosition min_position_ = TokenPosition::kNoSource;
524 intptr_t current_script_id_ = -1;
525
526 friend class PositionScope;
527 friend class Program;
528};
529
530
531
532class AlternativeReadingScope {
533 public:
534 AlternativeReadingScope(Reader* reader, intptr_t new_position)
535 : reader_(reader), saved_offset_(reader_->offset_) {
536 reader_->offset_ = new_position;
537 }
538
539 explicit AlternativeReadingScope(Reader* reader)
540 : reader_(reader), saved_offset_(reader_->offset_) {}
541
542 ~AlternativeReadingScope() { reader_->offset_ = saved_offset_; }
543
544 intptr_t saved_offset() { return saved_offset_; }
545
546 private:
547 Reader* const reader_;
548 const intptr_t saved_offset_;
549
551};
552
553
554
555class AlternativeReadingScopeWithNewData {
556 public:
557 AlternativeReadingScopeWithNewData(Reader* reader,
558 const TypedDataBase* new_typed_data,
559 intptr_t new_position)
560 : reader_(reader),
561 saved_size_(reader_->size_),
562 saved_raw_buffer_(reader_->raw_buffer_),
563 saved_typed_data_(reader_->typed_data_),
564 saved_offset_(reader_->offset_) {
565 reader_->typed_data_ = new_typed_data;
566 reader_->Init();
567 reader_->offset_ = new_position;
568 }
569
570 ~AlternativeReadingScopeWithNewData() {
571 reader_->raw_buffer_ = saved_raw_buffer_;
572 reader_->typed_data_ = saved_typed_data_;
573 reader_->size_ = saved_size_;
574 reader_->offset_ = saved_offset_;
575 }
576
577 intptr_t saved_offset() { return saved_offset_; }
578
579 private:
580 Reader* reader_;
581 intptr_t saved_size_;
582 const uint8_t* saved_raw_buffer_;
583 const TypedDataBase* saved_typed_data_;
584 intptr_t saved_offset_;
585
587};
588
589
590
591
592
593
594class PositionScope {
595 public:
596 explicit PositionScope(Reader* reader)
597 : reader_(reader),
598 min_(reader->min_position_),
599 max_(reader->max_position_) {
600 reader->min_position_ = reader->max_position_ = TokenPosition::kNoSource;
601 }
602
603 ~PositionScope() {
604 reader_->min_position_ = TokenPosition::Min(reader_->min_position_,
min_);
605 reader_->max_position_ = TokenPosition::Max(reader_->max_position_,
max_);
606 }
607
608 private:
609 Reader* reader_;
612
614};
615
616}
617}
618
619#endif
620#endif
static uint8_t PeekByte(unsigned long location, CFDataRef data)
static const uint8_t buffer[]
#define DECLARE(Name, value)
#define KERNEL_TAG_LIST(V)
@ kIsExpressionFlagForLegacy
@ kTypedefTearOffConstant
@ kConstructorTearOffConstant
@ kRedirectingFactoryTearOffConstant
static constexpr int SpecializedIntLiteralBias
@ kYieldStatementFlagYieldStar
static constexpr int SourceTableFieldCountFromFirstLibraryOffset
static constexpr int LibraryCountFieldCountFromEnd
static constexpr intptr_t kSpecializedPayloadMask
static constexpr intptr_t kSpecializedTagHighBits
@ kDynamicInvocationFlagImplicitCall
static constexpr intptr_t kSpecializedTagMask
@ kInstanceInvocationFlagBoundsSafe
@ kInstanceInvocationFlagInvariant
static constexpr int HeaderSize
@ kAsExpressionFlagForLegacy
@ kAsExpressionFlagUnchecked
@ kAsExpressionFlagCovarianceCheck
@ kAsExpressionFlagForDynamic
@ kAsExpressionFlagTypeError
static constexpr int KernelFormatVersionOffset
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size