Trait wasmtime_environ::PtrSize
source · pub trait PtrSize {
Show 16 methods
fn size(&self) -> u8;
fn vmcaller_checked_anyfunc_func_ptr(&self) -> u8 { ... }
fn vmcaller_checked_anyfunc_type_index(&self) -> u8 { ... }
fn vmcaller_checked_anyfunc_vmctx(&self) -> u8 { ... }
fn size_of_vmcaller_checked_anyfunc(&self) -> u8 { ... }
fn size_of_vmglobal_definition(&self) -> u8 { ... }
fn vmruntime_limits_stack_limit(&self) -> u8 { ... }
fn vmruntime_limits_fuel_consumed(&self) -> u8 { ... }
fn vmruntime_limits_epoch_deadline(&self) -> u8 { ... }
fn vmruntime_limits_last_wasm_exit_fp(&self) -> u8 { ... }
fn vmruntime_limits_last_wasm_exit_pc(&self) -> u8 { ... }
fn vmruntime_limits_last_wasm_entry_sp(&self) -> u8 { ... }
fn vmmemory_definition_base(&self) -> u8 { ... }
fn vmmemory_definition_current_length(&self) -> u8 { ... }
fn size_of_vmmemory_definition(&self) -> u8 { ... }
fn size_of_vmmemory_pointer(&self) -> u8 { ... }
}
Expand description
Trait used for the ptr
representation of the field of VMOffsets
Required Methods§
Provided Methods§
sourcefn vmcaller_checked_anyfunc_func_ptr(&self) -> u8
fn vmcaller_checked_anyfunc_func_ptr(&self) -> u8
The offset of the func_ptr
field.
sourcefn vmcaller_checked_anyfunc_type_index(&self) -> u8
fn vmcaller_checked_anyfunc_type_index(&self) -> u8
The offset of the type_index
field.
sourcefn vmcaller_checked_anyfunc_vmctx(&self) -> u8
fn vmcaller_checked_anyfunc_vmctx(&self) -> u8
The offset of the vmctx
field.
sourcefn size_of_vmcaller_checked_anyfunc(&self) -> u8
fn size_of_vmcaller_checked_anyfunc(&self) -> u8
Return the size of VMCallerCheckedAnyfunc
.
Examples found in repository?
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
fn from(fields: VMOffsetsFields<P>) -> VMOffsets<P> {
let mut ret = Self {
ptr: fields.ptr,
num_imported_functions: fields.num_imported_functions,
num_imported_tables: fields.num_imported_tables,
num_imported_memories: fields.num_imported_memories,
num_imported_globals: fields.num_imported_globals,
num_defined_tables: fields.num_defined_tables,
num_defined_memories: fields.num_defined_memories,
num_owned_memories: fields.num_owned_memories,
num_defined_globals: fields.num_defined_globals,
num_escaped_funcs: fields.num_escaped_funcs,
magic: 0,
runtime_limits: 0,
callee: 0,
epoch_ptr: 0,
externref_activations_table: 0,
store: 0,
builtin_functions: 0,
signature_ids: 0,
imported_functions: 0,
imported_tables: 0,
imported_memories: 0,
imported_globals: 0,
defined_tables: 0,
defined_memories: 0,
owned_memories: 0,
defined_globals: 0,
defined_anyfuncs: 0,
size: 0,
};
// Convenience functions for checked addition and multiplication.
// As side effect this reduces binary size by using only a single
// `#[track_caller]` location for each function instead of one for
// each individual invocation.
#[inline]
fn cadd(count: u32, size: u32) -> u32 {
count.checked_add(size).unwrap()
}
#[inline]
fn cmul(count: u32, size: u8) -> u32 {
count.checked_mul(u32::from(size)).unwrap()
}
let mut next_field_offset = 0;
macro_rules! fields {
(size($field:ident) = $size:expr, $($rest:tt)*) => {
ret.$field = next_field_offset;
next_field_offset = cadd(next_field_offset, u32::from($size));
fields!($($rest)*);
};
(align($align:expr), $($rest:tt)*) => {
next_field_offset = align(next_field_offset, $align);
fields!($($rest)*);
};
() => {};
}
fields! {
size(magic) = 4u32,
align(u32::from(ret.ptr.size())),
size(runtime_limits) = ret.ptr.size(),
size(callee) = ret.ptr.size(),
size(epoch_ptr) = ret.ptr.size(),
size(externref_activations_table) = ret.ptr.size(),
size(store) = ret.ptr.size() * 2,
size(builtin_functions) = ret.pointer_size(),
size(signature_ids) = ret.ptr.size(),
size(imported_functions)
= cmul(ret.num_imported_functions, ret.size_of_vmfunction_import()),
size(imported_tables)
= cmul(ret.num_imported_tables, ret.size_of_vmtable_import()),
size(imported_memories)
= cmul(ret.num_imported_memories, ret.size_of_vmmemory_import()),
size(imported_globals)
= cmul(ret.num_imported_globals, ret.size_of_vmglobal_import()),
size(defined_tables)
= cmul(ret.num_defined_tables, ret.size_of_vmtable_definition()),
size(defined_memories)
= cmul(ret.num_defined_memories, ret.ptr.size_of_vmmemory_pointer()),
size(owned_memories)
= cmul(ret.num_owned_memories, ret.ptr.size_of_vmmemory_definition()),
align(16),
size(defined_globals)
= cmul(ret.num_defined_globals, ret.ptr.size_of_vmglobal_definition()),
size(defined_anyfuncs) = cmul(
ret.num_escaped_funcs,
ret.ptr.size_of_vmcaller_checked_anyfunc(),
),
}
ret.size = next_field_offset;
// This is required by the implementation of `VMContext::instance` and
// `VMContext::instance_mut`. If this value changes then those locations
// need to be updated.
assert_eq!(ret.magic, 0);
return ret;
}
}
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `body` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmfunction_import_body(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmfunction_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMFunctionImport`.
#[inline]
pub fn size_of_vmfunction_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `*const VMFunctionBody`.
impl<P: PtrSize> VMOffsets<P> {
/// The size of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn size_of_vmfunction_body_ptr(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMTableImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmtable_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMTableImport`.
#[inline]
pub fn size_of_vmtable_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMTableDefinition`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `base` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_definition_base(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn vmtable_definition_current_elements(&self) -> u8 {
1 * self.pointer_size()
}
/// The size of the `current_elements` field.
#[inline]
pub fn size_of_vmtable_definition_current_elements(&self) -> u8 {
4
}
/// Return the size of `VMTableDefinition`.
#[inline]
pub fn size_of_vmtable_definition(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMMemoryImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmmemory_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmmemory_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMMemoryImport`.
#[inline]
pub fn size_of_vmmemory_import(&self) -> u8 {
3 * self.pointer_size()
}
}
/// Offsets for `VMGlobalImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmglobal_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// Return the size of `VMGlobalImport`.
#[allow(clippy::identity_op)]
#[inline]
pub fn size_of_vmglobal_import(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMSharedSignatureIndex`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the size of `VMSharedSignatureIndex`.
#[inline]
pub fn size_of_vmshared_signature_index(&self) -> u8 {
4
}
}
/// Offsets for `VMContext`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the offset to the `magic` value in this `VMContext`.
#[inline]
pub fn vmctx_magic(&self) -> u32 {
self.magic
}
/// Return the offset to the `VMRuntimeLimits` structure
#[inline]
pub fn vmctx_runtime_limits(&self) -> u32 {
self.runtime_limits
}
/// Return the offset to the `callee` member in this `VMContext`.
pub fn vmctx_callee(&self) -> u32 {
self.callee
}
/// Return the offset to the `*const AtomicU64` epoch-counter
/// pointer.
#[inline]
pub fn vmctx_epoch_ptr(&self) -> u32 {
self.epoch_ptr
}
/// The offset of the `*mut VMExternRefActivationsTable` member.
#[inline]
pub fn vmctx_externref_activations_table(&self) -> u32 {
self.externref_activations_table
}
/// The offset of the `*const dyn Store` member.
#[inline]
pub fn vmctx_store(&self) -> u32 {
self.store
}
/// The offset of the `signature_ids` array pointer.
#[inline]
pub fn vmctx_signature_ids_array(&self) -> u32 {
self.signature_ids
}
/// The offset of the `tables` array.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmctx_imported_functions_begin(&self) -> u32 {
self.imported_functions
}
/// The offset of the `tables` array.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmctx_imported_tables_begin(&self) -> u32 {
self.imported_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_imported_memories_begin(&self) -> u32 {
self.imported_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_imported_globals_begin(&self) -> u32 {
self.imported_globals
}
/// The offset of the `tables` array.
#[inline]
pub fn vmctx_tables_begin(&self) -> u32 {
self.defined_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_memories_begin(&self) -> u32 {
self.defined_memories
}
/// The offset of the `owned_memories` array.
#[inline]
pub fn vmctx_owned_memories_begin(&self) -> u32 {
self.owned_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_globals_begin(&self) -> u32 {
self.defined_globals
}
/// The offset of the `anyfuncs` array.
#[inline]
pub fn vmctx_anyfuncs_begin(&self) -> u32 {
self.defined_anyfuncs
}
/// The offset of the builtin functions array.
#[inline]
pub fn vmctx_builtin_functions(&self) -> u32 {
self.builtin_functions
}
/// Return the size of the `VMContext` allocation.
#[inline]
pub fn size_of_vmctx(&self) -> u32 {
self.size
}
/// Return the offset to `VMFunctionImport` index `index`.
#[inline]
pub fn vmctx_vmfunction_import(&self, index: FuncIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_functions);
self.vmctx_imported_functions_begin()
+ index.as_u32() * u32::from(self.size_of_vmfunction_import())
}
/// Return the offset to `VMTableImport` index `index`.
#[inline]
pub fn vmctx_vmtable_import(&self, index: TableIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_tables);
self.vmctx_imported_tables_begin()
+ index.as_u32() * u32::from(self.size_of_vmtable_import())
}
/// Return the offset to `VMMemoryImport` index `index`.
#[inline]
pub fn vmctx_vmmemory_import(&self, index: MemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_memories);
self.vmctx_imported_memories_begin()
+ index.as_u32() * u32::from(self.size_of_vmmemory_import())
}
/// Return the offset to `VMGlobalImport` index `index`.
#[inline]
pub fn vmctx_vmglobal_import(&self, index: GlobalIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_globals);
self.vmctx_imported_globals_begin()
+ index.as_u32() * u32::from(self.size_of_vmglobal_import())
}
/// Return the offset to `VMTableDefinition` index `index`.
#[inline]
pub fn vmctx_vmtable_definition(&self, index: DefinedTableIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_tables);
self.vmctx_tables_begin() + index.as_u32() * u32::from(self.size_of_vmtable_definition())
}
/// Return the offset to the `*mut VMMemoryDefinition` at index `index`.
#[inline]
pub fn vmctx_vmmemory_pointer(&self, index: DefinedMemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_memories);
self.vmctx_memories_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmmemory_pointer())
}
/// Return the offset to the owned `VMMemoryDefinition` at index `index`.
#[inline]
pub fn vmctx_vmmemory_definition(&self, index: OwnedMemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_owned_memories);
self.vmctx_owned_memories_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmmemory_definition())
}
/// Return the offset to the `VMGlobalDefinition` index `index`.
#[inline]
pub fn vmctx_vmglobal_definition(&self, index: DefinedGlobalIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_globals);
self.vmctx_globals_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmglobal_definition())
}
/// Return the offset to the `VMCallerCheckedAnyfunc` for the given function
/// index (either imported or defined).
#[inline]
pub fn vmctx_anyfunc(&self, index: AnyfuncIndex) -> u32 {
assert!(!index.is_reserved_value());
assert!(index.as_u32() < self.num_escaped_funcs);
self.vmctx_anyfuncs_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmcaller_checked_anyfunc())
}
sourcefn size_of_vmglobal_definition(&self) -> u8
fn size_of_vmglobal_definition(&self) -> u8
Return the size of VMGlobalDefinition
; this is the size of the largest value type (i.e. a
V128).
Examples found in repository?
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
fn from(fields: VMOffsetsFields<P>) -> VMOffsets<P> {
let mut ret = Self {
ptr: fields.ptr,
num_imported_functions: fields.num_imported_functions,
num_imported_tables: fields.num_imported_tables,
num_imported_memories: fields.num_imported_memories,
num_imported_globals: fields.num_imported_globals,
num_defined_tables: fields.num_defined_tables,
num_defined_memories: fields.num_defined_memories,
num_owned_memories: fields.num_owned_memories,
num_defined_globals: fields.num_defined_globals,
num_escaped_funcs: fields.num_escaped_funcs,
magic: 0,
runtime_limits: 0,
callee: 0,
epoch_ptr: 0,
externref_activations_table: 0,
store: 0,
builtin_functions: 0,
signature_ids: 0,
imported_functions: 0,
imported_tables: 0,
imported_memories: 0,
imported_globals: 0,
defined_tables: 0,
defined_memories: 0,
owned_memories: 0,
defined_globals: 0,
defined_anyfuncs: 0,
size: 0,
};
// Convenience functions for checked addition and multiplication.
// As side effect this reduces binary size by using only a single
// `#[track_caller]` location for each function instead of one for
// each individual invocation.
#[inline]
fn cadd(count: u32, size: u32) -> u32 {
count.checked_add(size).unwrap()
}
#[inline]
fn cmul(count: u32, size: u8) -> u32 {
count.checked_mul(u32::from(size)).unwrap()
}
let mut next_field_offset = 0;
macro_rules! fields {
(size($field:ident) = $size:expr, $($rest:tt)*) => {
ret.$field = next_field_offset;
next_field_offset = cadd(next_field_offset, u32::from($size));
fields!($($rest)*);
};
(align($align:expr), $($rest:tt)*) => {
next_field_offset = align(next_field_offset, $align);
fields!($($rest)*);
};
() => {};
}
fields! {
size(magic) = 4u32,
align(u32::from(ret.ptr.size())),
size(runtime_limits) = ret.ptr.size(),
size(callee) = ret.ptr.size(),
size(epoch_ptr) = ret.ptr.size(),
size(externref_activations_table) = ret.ptr.size(),
size(store) = ret.ptr.size() * 2,
size(builtin_functions) = ret.pointer_size(),
size(signature_ids) = ret.ptr.size(),
size(imported_functions)
= cmul(ret.num_imported_functions, ret.size_of_vmfunction_import()),
size(imported_tables)
= cmul(ret.num_imported_tables, ret.size_of_vmtable_import()),
size(imported_memories)
= cmul(ret.num_imported_memories, ret.size_of_vmmemory_import()),
size(imported_globals)
= cmul(ret.num_imported_globals, ret.size_of_vmglobal_import()),
size(defined_tables)
= cmul(ret.num_defined_tables, ret.size_of_vmtable_definition()),
size(defined_memories)
= cmul(ret.num_defined_memories, ret.ptr.size_of_vmmemory_pointer()),
size(owned_memories)
= cmul(ret.num_owned_memories, ret.ptr.size_of_vmmemory_definition()),
align(16),
size(defined_globals)
= cmul(ret.num_defined_globals, ret.ptr.size_of_vmglobal_definition()),
size(defined_anyfuncs) = cmul(
ret.num_escaped_funcs,
ret.ptr.size_of_vmcaller_checked_anyfunc(),
),
}
ret.size = next_field_offset;
// This is required by the implementation of `VMContext::instance` and
// `VMContext::instance_mut`. If this value changes then those locations
// need to be updated.
assert_eq!(ret.magic, 0);
return ret;
}
}
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `body` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmfunction_import_body(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmfunction_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMFunctionImport`.
#[inline]
pub fn size_of_vmfunction_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `*const VMFunctionBody`.
impl<P: PtrSize> VMOffsets<P> {
/// The size of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn size_of_vmfunction_body_ptr(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMTableImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmtable_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMTableImport`.
#[inline]
pub fn size_of_vmtable_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMTableDefinition`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `base` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_definition_base(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn vmtable_definition_current_elements(&self) -> u8 {
1 * self.pointer_size()
}
/// The size of the `current_elements` field.
#[inline]
pub fn size_of_vmtable_definition_current_elements(&self) -> u8 {
4
}
/// Return the size of `VMTableDefinition`.
#[inline]
pub fn size_of_vmtable_definition(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMMemoryImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmmemory_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmmemory_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMMemoryImport`.
#[inline]
pub fn size_of_vmmemory_import(&self) -> u8 {
3 * self.pointer_size()
}
}
/// Offsets for `VMGlobalImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmglobal_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// Return the size of `VMGlobalImport`.
#[allow(clippy::identity_op)]
#[inline]
pub fn size_of_vmglobal_import(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMSharedSignatureIndex`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the size of `VMSharedSignatureIndex`.
#[inline]
pub fn size_of_vmshared_signature_index(&self) -> u8 {
4
}
}
/// Offsets for `VMContext`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the offset to the `magic` value in this `VMContext`.
#[inline]
pub fn vmctx_magic(&self) -> u32 {
self.magic
}
/// Return the offset to the `VMRuntimeLimits` structure
#[inline]
pub fn vmctx_runtime_limits(&self) -> u32 {
self.runtime_limits
}
/// Return the offset to the `callee` member in this `VMContext`.
pub fn vmctx_callee(&self) -> u32 {
self.callee
}
/// Return the offset to the `*const AtomicU64` epoch-counter
/// pointer.
#[inline]
pub fn vmctx_epoch_ptr(&self) -> u32 {
self.epoch_ptr
}
/// The offset of the `*mut VMExternRefActivationsTable` member.
#[inline]
pub fn vmctx_externref_activations_table(&self) -> u32 {
self.externref_activations_table
}
/// The offset of the `*const dyn Store` member.
#[inline]
pub fn vmctx_store(&self) -> u32 {
self.store
}
/// The offset of the `signature_ids` array pointer.
#[inline]
pub fn vmctx_signature_ids_array(&self) -> u32 {
self.signature_ids
}
/// The offset of the `tables` array.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmctx_imported_functions_begin(&self) -> u32 {
self.imported_functions
}
/// The offset of the `tables` array.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmctx_imported_tables_begin(&self) -> u32 {
self.imported_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_imported_memories_begin(&self) -> u32 {
self.imported_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_imported_globals_begin(&self) -> u32 {
self.imported_globals
}
/// The offset of the `tables` array.
#[inline]
pub fn vmctx_tables_begin(&self) -> u32 {
self.defined_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_memories_begin(&self) -> u32 {
self.defined_memories
}
/// The offset of the `owned_memories` array.
#[inline]
pub fn vmctx_owned_memories_begin(&self) -> u32 {
self.owned_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_globals_begin(&self) -> u32 {
self.defined_globals
}
/// The offset of the `anyfuncs` array.
#[inline]
pub fn vmctx_anyfuncs_begin(&self) -> u32 {
self.defined_anyfuncs
}
/// The offset of the builtin functions array.
#[inline]
pub fn vmctx_builtin_functions(&self) -> u32 {
self.builtin_functions
}
/// Return the size of the `VMContext` allocation.
#[inline]
pub fn size_of_vmctx(&self) -> u32 {
self.size
}
/// Return the offset to `VMFunctionImport` index `index`.
#[inline]
pub fn vmctx_vmfunction_import(&self, index: FuncIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_functions);
self.vmctx_imported_functions_begin()
+ index.as_u32() * u32::from(self.size_of_vmfunction_import())
}
/// Return the offset to `VMTableImport` index `index`.
#[inline]
pub fn vmctx_vmtable_import(&self, index: TableIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_tables);
self.vmctx_imported_tables_begin()
+ index.as_u32() * u32::from(self.size_of_vmtable_import())
}
/// Return the offset to `VMMemoryImport` index `index`.
#[inline]
pub fn vmctx_vmmemory_import(&self, index: MemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_memories);
self.vmctx_imported_memories_begin()
+ index.as_u32() * u32::from(self.size_of_vmmemory_import())
}
/// Return the offset to `VMGlobalImport` index `index`.
#[inline]
pub fn vmctx_vmglobal_import(&self, index: GlobalIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_globals);
self.vmctx_imported_globals_begin()
+ index.as_u32() * u32::from(self.size_of_vmglobal_import())
}
/// Return the offset to `VMTableDefinition` index `index`.
#[inline]
pub fn vmctx_vmtable_definition(&self, index: DefinedTableIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_tables);
self.vmctx_tables_begin() + index.as_u32() * u32::from(self.size_of_vmtable_definition())
}
/// Return the offset to the `*mut VMMemoryDefinition` at index `index`.
#[inline]
pub fn vmctx_vmmemory_pointer(&self, index: DefinedMemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_memories);
self.vmctx_memories_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmmemory_pointer())
}
/// Return the offset to the owned `VMMemoryDefinition` at index `index`.
#[inline]
pub fn vmctx_vmmemory_definition(&self, index: OwnedMemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_owned_memories);
self.vmctx_owned_memories_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmmemory_definition())
}
/// Return the offset to the `VMGlobalDefinition` index `index`.
#[inline]
pub fn vmctx_vmglobal_definition(&self, index: DefinedGlobalIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_globals);
self.vmctx_globals_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmglobal_definition())
}
sourcefn vmruntime_limits_stack_limit(&self) -> u8
fn vmruntime_limits_stack_limit(&self) -> u8
Return the offset of the stack_limit
field of VMRuntimeLimits
sourcefn vmruntime_limits_fuel_consumed(&self) -> u8
fn vmruntime_limits_fuel_consumed(&self) -> u8
Return the offset of the fuel_consumed
field of VMRuntimeLimits
sourcefn vmruntime_limits_epoch_deadline(&self) -> u8
fn vmruntime_limits_epoch_deadline(&self) -> u8
Return the offset of the epoch_deadline
field of VMRuntimeLimits
sourcefn vmruntime_limits_last_wasm_exit_fp(&self) -> u8
fn vmruntime_limits_last_wasm_exit_fp(&self) -> u8
Return the offset of the last_wasm_exit_fp
field of VMRuntimeLimits
.
sourcefn vmruntime_limits_last_wasm_exit_pc(&self) -> u8
fn vmruntime_limits_last_wasm_exit_pc(&self) -> u8
Return the offset of the last_wasm_exit_pc
field of VMRuntimeLimits
.
sourcefn vmruntime_limits_last_wasm_entry_sp(&self) -> u8
fn vmruntime_limits_last_wasm_entry_sp(&self) -> u8
Return the offset of the last_enty_sp
field of VMRuntimeLimits
.
sourcefn vmmemory_definition_base(&self) -> u8
fn vmmemory_definition_base(&self) -> u8
The offset of the base
field.
sourcefn vmmemory_definition_current_length(&self) -> u8
fn vmmemory_definition_current_length(&self) -> u8
The offset of the current_length
field.
sourcefn size_of_vmmemory_definition(&self) -> u8
fn size_of_vmmemory_definition(&self) -> u8
Return the size of VMMemoryDefinition
.
Examples found in repository?
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
fn from(fields: VMOffsetsFields<P>) -> VMOffsets<P> {
let mut ret = Self {
ptr: fields.ptr,
num_imported_functions: fields.num_imported_functions,
num_imported_tables: fields.num_imported_tables,
num_imported_memories: fields.num_imported_memories,
num_imported_globals: fields.num_imported_globals,
num_defined_tables: fields.num_defined_tables,
num_defined_memories: fields.num_defined_memories,
num_owned_memories: fields.num_owned_memories,
num_defined_globals: fields.num_defined_globals,
num_escaped_funcs: fields.num_escaped_funcs,
magic: 0,
runtime_limits: 0,
callee: 0,
epoch_ptr: 0,
externref_activations_table: 0,
store: 0,
builtin_functions: 0,
signature_ids: 0,
imported_functions: 0,
imported_tables: 0,
imported_memories: 0,
imported_globals: 0,
defined_tables: 0,
defined_memories: 0,
owned_memories: 0,
defined_globals: 0,
defined_anyfuncs: 0,
size: 0,
};
// Convenience functions for checked addition and multiplication.
// As side effect this reduces binary size by using only a single
// `#[track_caller]` location for each function instead of one for
// each individual invocation.
#[inline]
fn cadd(count: u32, size: u32) -> u32 {
count.checked_add(size).unwrap()
}
#[inline]
fn cmul(count: u32, size: u8) -> u32 {
count.checked_mul(u32::from(size)).unwrap()
}
let mut next_field_offset = 0;
macro_rules! fields {
(size($field:ident) = $size:expr, $($rest:tt)*) => {
ret.$field = next_field_offset;
next_field_offset = cadd(next_field_offset, u32::from($size));
fields!($($rest)*);
};
(align($align:expr), $($rest:tt)*) => {
next_field_offset = align(next_field_offset, $align);
fields!($($rest)*);
};
() => {};
}
fields! {
size(magic) = 4u32,
align(u32::from(ret.ptr.size())),
size(runtime_limits) = ret.ptr.size(),
size(callee) = ret.ptr.size(),
size(epoch_ptr) = ret.ptr.size(),
size(externref_activations_table) = ret.ptr.size(),
size(store) = ret.ptr.size() * 2,
size(builtin_functions) = ret.pointer_size(),
size(signature_ids) = ret.ptr.size(),
size(imported_functions)
= cmul(ret.num_imported_functions, ret.size_of_vmfunction_import()),
size(imported_tables)
= cmul(ret.num_imported_tables, ret.size_of_vmtable_import()),
size(imported_memories)
= cmul(ret.num_imported_memories, ret.size_of_vmmemory_import()),
size(imported_globals)
= cmul(ret.num_imported_globals, ret.size_of_vmglobal_import()),
size(defined_tables)
= cmul(ret.num_defined_tables, ret.size_of_vmtable_definition()),
size(defined_memories)
= cmul(ret.num_defined_memories, ret.ptr.size_of_vmmemory_pointer()),
size(owned_memories)
= cmul(ret.num_owned_memories, ret.ptr.size_of_vmmemory_definition()),
align(16),
size(defined_globals)
= cmul(ret.num_defined_globals, ret.ptr.size_of_vmglobal_definition()),
size(defined_anyfuncs) = cmul(
ret.num_escaped_funcs,
ret.ptr.size_of_vmcaller_checked_anyfunc(),
),
}
ret.size = next_field_offset;
// This is required by the implementation of `VMContext::instance` and
// `VMContext::instance_mut`. If this value changes then those locations
// need to be updated.
assert_eq!(ret.magic, 0);
return ret;
}
}
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `body` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmfunction_import_body(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmfunction_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMFunctionImport`.
#[inline]
pub fn size_of_vmfunction_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `*const VMFunctionBody`.
impl<P: PtrSize> VMOffsets<P> {
/// The size of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn size_of_vmfunction_body_ptr(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMTableImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmtable_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMTableImport`.
#[inline]
pub fn size_of_vmtable_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMTableDefinition`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `base` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_definition_base(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn vmtable_definition_current_elements(&self) -> u8 {
1 * self.pointer_size()
}
/// The size of the `current_elements` field.
#[inline]
pub fn size_of_vmtable_definition_current_elements(&self) -> u8 {
4
}
/// Return the size of `VMTableDefinition`.
#[inline]
pub fn size_of_vmtable_definition(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMMemoryImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmmemory_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmmemory_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMMemoryImport`.
#[inline]
pub fn size_of_vmmemory_import(&self) -> u8 {
3 * self.pointer_size()
}
}
/// Offsets for `VMGlobalImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmglobal_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// Return the size of `VMGlobalImport`.
#[allow(clippy::identity_op)]
#[inline]
pub fn size_of_vmglobal_import(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMSharedSignatureIndex`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the size of `VMSharedSignatureIndex`.
#[inline]
pub fn size_of_vmshared_signature_index(&self) -> u8 {
4
}
}
/// Offsets for `VMContext`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the offset to the `magic` value in this `VMContext`.
#[inline]
pub fn vmctx_magic(&self) -> u32 {
self.magic
}
/// Return the offset to the `VMRuntimeLimits` structure
#[inline]
pub fn vmctx_runtime_limits(&self) -> u32 {
self.runtime_limits
}
/// Return the offset to the `callee` member in this `VMContext`.
pub fn vmctx_callee(&self) -> u32 {
self.callee
}
/// Return the offset to the `*const AtomicU64` epoch-counter
/// pointer.
#[inline]
pub fn vmctx_epoch_ptr(&self) -> u32 {
self.epoch_ptr
}
/// The offset of the `*mut VMExternRefActivationsTable` member.
#[inline]
pub fn vmctx_externref_activations_table(&self) -> u32 {
self.externref_activations_table
}
/// The offset of the `*const dyn Store` member.
#[inline]
pub fn vmctx_store(&self) -> u32 {
self.store
}
/// The offset of the `signature_ids` array pointer.
#[inline]
pub fn vmctx_signature_ids_array(&self) -> u32 {
self.signature_ids
}
/// The offset of the `tables` array.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmctx_imported_functions_begin(&self) -> u32 {
self.imported_functions
}
/// The offset of the `tables` array.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmctx_imported_tables_begin(&self) -> u32 {
self.imported_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_imported_memories_begin(&self) -> u32 {
self.imported_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_imported_globals_begin(&self) -> u32 {
self.imported_globals
}
/// The offset of the `tables` array.
#[inline]
pub fn vmctx_tables_begin(&self) -> u32 {
self.defined_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_memories_begin(&self) -> u32 {
self.defined_memories
}
/// The offset of the `owned_memories` array.
#[inline]
pub fn vmctx_owned_memories_begin(&self) -> u32 {
self.owned_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_globals_begin(&self) -> u32 {
self.defined_globals
}
/// The offset of the `anyfuncs` array.
#[inline]
pub fn vmctx_anyfuncs_begin(&self) -> u32 {
self.defined_anyfuncs
}
/// The offset of the builtin functions array.
#[inline]
pub fn vmctx_builtin_functions(&self) -> u32 {
self.builtin_functions
}
/// Return the size of the `VMContext` allocation.
#[inline]
pub fn size_of_vmctx(&self) -> u32 {
self.size
}
/// Return the offset to `VMFunctionImport` index `index`.
#[inline]
pub fn vmctx_vmfunction_import(&self, index: FuncIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_functions);
self.vmctx_imported_functions_begin()
+ index.as_u32() * u32::from(self.size_of_vmfunction_import())
}
/// Return the offset to `VMTableImport` index `index`.
#[inline]
pub fn vmctx_vmtable_import(&self, index: TableIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_tables);
self.vmctx_imported_tables_begin()
+ index.as_u32() * u32::from(self.size_of_vmtable_import())
}
/// Return the offset to `VMMemoryImport` index `index`.
#[inline]
pub fn vmctx_vmmemory_import(&self, index: MemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_memories);
self.vmctx_imported_memories_begin()
+ index.as_u32() * u32::from(self.size_of_vmmemory_import())
}
/// Return the offset to `VMGlobalImport` index `index`.
#[inline]
pub fn vmctx_vmglobal_import(&self, index: GlobalIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_globals);
self.vmctx_imported_globals_begin()
+ index.as_u32() * u32::from(self.size_of_vmglobal_import())
}
/// Return the offset to `VMTableDefinition` index `index`.
#[inline]
pub fn vmctx_vmtable_definition(&self, index: DefinedTableIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_tables);
self.vmctx_tables_begin() + index.as_u32() * u32::from(self.size_of_vmtable_definition())
}
/// Return the offset to the `*mut VMMemoryDefinition` at index `index`.
#[inline]
pub fn vmctx_vmmemory_pointer(&self, index: DefinedMemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_memories);
self.vmctx_memories_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmmemory_pointer())
}
/// Return the offset to the owned `VMMemoryDefinition` at index `index`.
#[inline]
pub fn vmctx_vmmemory_definition(&self, index: OwnedMemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_owned_memories);
self.vmctx_owned_memories_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmmemory_definition())
}
sourcefn size_of_vmmemory_pointer(&self) -> u8
fn size_of_vmmemory_pointer(&self) -> u8
Return the size of *mut VMMemoryDefinition
.
Examples found in repository?
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
fn from(fields: VMOffsetsFields<P>) -> VMOffsets<P> {
let mut ret = Self {
ptr: fields.ptr,
num_imported_functions: fields.num_imported_functions,
num_imported_tables: fields.num_imported_tables,
num_imported_memories: fields.num_imported_memories,
num_imported_globals: fields.num_imported_globals,
num_defined_tables: fields.num_defined_tables,
num_defined_memories: fields.num_defined_memories,
num_owned_memories: fields.num_owned_memories,
num_defined_globals: fields.num_defined_globals,
num_escaped_funcs: fields.num_escaped_funcs,
magic: 0,
runtime_limits: 0,
callee: 0,
epoch_ptr: 0,
externref_activations_table: 0,
store: 0,
builtin_functions: 0,
signature_ids: 0,
imported_functions: 0,
imported_tables: 0,
imported_memories: 0,
imported_globals: 0,
defined_tables: 0,
defined_memories: 0,
owned_memories: 0,
defined_globals: 0,
defined_anyfuncs: 0,
size: 0,
};
// Convenience functions for checked addition and multiplication.
// As side effect this reduces binary size by using only a single
// `#[track_caller]` location for each function instead of one for
// each individual invocation.
#[inline]
fn cadd(count: u32, size: u32) -> u32 {
count.checked_add(size).unwrap()
}
#[inline]
fn cmul(count: u32, size: u8) -> u32 {
count.checked_mul(u32::from(size)).unwrap()
}
let mut next_field_offset = 0;
macro_rules! fields {
(size($field:ident) = $size:expr, $($rest:tt)*) => {
ret.$field = next_field_offset;
next_field_offset = cadd(next_field_offset, u32::from($size));
fields!($($rest)*);
};
(align($align:expr), $($rest:tt)*) => {
next_field_offset = align(next_field_offset, $align);
fields!($($rest)*);
};
() => {};
}
fields! {
size(magic) = 4u32,
align(u32::from(ret.ptr.size())),
size(runtime_limits) = ret.ptr.size(),
size(callee) = ret.ptr.size(),
size(epoch_ptr) = ret.ptr.size(),
size(externref_activations_table) = ret.ptr.size(),
size(store) = ret.ptr.size() * 2,
size(builtin_functions) = ret.pointer_size(),
size(signature_ids) = ret.ptr.size(),
size(imported_functions)
= cmul(ret.num_imported_functions, ret.size_of_vmfunction_import()),
size(imported_tables)
= cmul(ret.num_imported_tables, ret.size_of_vmtable_import()),
size(imported_memories)
= cmul(ret.num_imported_memories, ret.size_of_vmmemory_import()),
size(imported_globals)
= cmul(ret.num_imported_globals, ret.size_of_vmglobal_import()),
size(defined_tables)
= cmul(ret.num_defined_tables, ret.size_of_vmtable_definition()),
size(defined_memories)
= cmul(ret.num_defined_memories, ret.ptr.size_of_vmmemory_pointer()),
size(owned_memories)
= cmul(ret.num_owned_memories, ret.ptr.size_of_vmmemory_definition()),
align(16),
size(defined_globals)
= cmul(ret.num_defined_globals, ret.ptr.size_of_vmglobal_definition()),
size(defined_anyfuncs) = cmul(
ret.num_escaped_funcs,
ret.ptr.size_of_vmcaller_checked_anyfunc(),
),
}
ret.size = next_field_offset;
// This is required by the implementation of `VMContext::instance` and
// `VMContext::instance_mut`. If this value changes then those locations
// need to be updated.
assert_eq!(ret.magic, 0);
return ret;
}
}
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `body` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmfunction_import_body(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmfunction_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMFunctionImport`.
#[inline]
pub fn size_of_vmfunction_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `*const VMFunctionBody`.
impl<P: PtrSize> VMOffsets<P> {
/// The size of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn size_of_vmfunction_body_ptr(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMTableImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmtable_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMTableImport`.
#[inline]
pub fn size_of_vmtable_import(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMTableDefinition`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `base` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmtable_definition_base(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `current_elements` field.
#[allow(clippy::identity_op)]
pub fn vmtable_definition_current_elements(&self) -> u8 {
1 * self.pointer_size()
}
/// The size of the `current_elements` field.
#[inline]
pub fn size_of_vmtable_definition_current_elements(&self) -> u8 {
4
}
/// Return the size of `VMTableDefinition`.
#[inline]
pub fn size_of_vmtable_definition(&self) -> u8 {
2 * self.pointer_size()
}
}
/// Offsets for `VMMemoryImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmmemory_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// The offset of the `vmctx` field.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmmemory_import_vmctx(&self) -> u8 {
1 * self.pointer_size()
}
/// Return the size of `VMMemoryImport`.
#[inline]
pub fn size_of_vmmemory_import(&self) -> u8 {
3 * self.pointer_size()
}
}
/// Offsets for `VMGlobalImport`.
impl<P: PtrSize> VMOffsets<P> {
/// The offset of the `from` field.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmglobal_import_from(&self) -> u8 {
0 * self.pointer_size()
}
/// Return the size of `VMGlobalImport`.
#[allow(clippy::identity_op)]
#[inline]
pub fn size_of_vmglobal_import(&self) -> u8 {
1 * self.pointer_size()
}
}
/// Offsets for `VMSharedSignatureIndex`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the size of `VMSharedSignatureIndex`.
#[inline]
pub fn size_of_vmshared_signature_index(&self) -> u8 {
4
}
}
/// Offsets for `VMContext`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the offset to the `magic` value in this `VMContext`.
#[inline]
pub fn vmctx_magic(&self) -> u32 {
self.magic
}
/// Return the offset to the `VMRuntimeLimits` structure
#[inline]
pub fn vmctx_runtime_limits(&self) -> u32 {
self.runtime_limits
}
/// Return the offset to the `callee` member in this `VMContext`.
pub fn vmctx_callee(&self) -> u32 {
self.callee
}
/// Return the offset to the `*const AtomicU64` epoch-counter
/// pointer.
#[inline]
pub fn vmctx_epoch_ptr(&self) -> u32 {
self.epoch_ptr
}
/// The offset of the `*mut VMExternRefActivationsTable` member.
#[inline]
pub fn vmctx_externref_activations_table(&self) -> u32 {
self.externref_activations_table
}
/// The offset of the `*const dyn Store` member.
#[inline]
pub fn vmctx_store(&self) -> u32 {
self.store
}
/// The offset of the `signature_ids` array pointer.
#[inline]
pub fn vmctx_signature_ids_array(&self) -> u32 {
self.signature_ids
}
/// The offset of the `tables` array.
#[allow(clippy::erasing_op)]
#[inline]
pub fn vmctx_imported_functions_begin(&self) -> u32 {
self.imported_functions
}
/// The offset of the `tables` array.
#[allow(clippy::identity_op)]
#[inline]
pub fn vmctx_imported_tables_begin(&self) -> u32 {
self.imported_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_imported_memories_begin(&self) -> u32 {
self.imported_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_imported_globals_begin(&self) -> u32 {
self.imported_globals
}
/// The offset of the `tables` array.
#[inline]
pub fn vmctx_tables_begin(&self) -> u32 {
self.defined_tables
}
/// The offset of the `memories` array.
#[inline]
pub fn vmctx_memories_begin(&self) -> u32 {
self.defined_memories
}
/// The offset of the `owned_memories` array.
#[inline]
pub fn vmctx_owned_memories_begin(&self) -> u32 {
self.owned_memories
}
/// The offset of the `globals` array.
#[inline]
pub fn vmctx_globals_begin(&self) -> u32 {
self.defined_globals
}
/// The offset of the `anyfuncs` array.
#[inline]
pub fn vmctx_anyfuncs_begin(&self) -> u32 {
self.defined_anyfuncs
}
/// The offset of the builtin functions array.
#[inline]
pub fn vmctx_builtin_functions(&self) -> u32 {
self.builtin_functions
}
/// Return the size of the `VMContext` allocation.
#[inline]
pub fn size_of_vmctx(&self) -> u32 {
self.size
}
/// Return the offset to `VMFunctionImport` index `index`.
#[inline]
pub fn vmctx_vmfunction_import(&self, index: FuncIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_functions);
self.vmctx_imported_functions_begin()
+ index.as_u32() * u32::from(self.size_of_vmfunction_import())
}
/// Return the offset to `VMTableImport` index `index`.
#[inline]
pub fn vmctx_vmtable_import(&self, index: TableIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_tables);
self.vmctx_imported_tables_begin()
+ index.as_u32() * u32::from(self.size_of_vmtable_import())
}
/// Return the offset to `VMMemoryImport` index `index`.
#[inline]
pub fn vmctx_vmmemory_import(&self, index: MemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_memories);
self.vmctx_imported_memories_begin()
+ index.as_u32() * u32::from(self.size_of_vmmemory_import())
}
/// Return the offset to `VMGlobalImport` index `index`.
#[inline]
pub fn vmctx_vmglobal_import(&self, index: GlobalIndex) -> u32 {
assert!(index.as_u32() < self.num_imported_globals);
self.vmctx_imported_globals_begin()
+ index.as_u32() * u32::from(self.size_of_vmglobal_import())
}
/// Return the offset to `VMTableDefinition` index `index`.
#[inline]
pub fn vmctx_vmtable_definition(&self, index: DefinedTableIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_tables);
self.vmctx_tables_begin() + index.as_u32() * u32::from(self.size_of_vmtable_definition())
}
/// Return the offset to the `*mut VMMemoryDefinition` at index `index`.
#[inline]
pub fn vmctx_vmmemory_pointer(&self, index: DefinedMemoryIndex) -> u32 {
assert!(index.as_u32() < self.num_defined_memories);
self.vmctx_memories_begin()
+ index.as_u32() * u32::from(self.ptr.size_of_vmmemory_pointer())
}