Crate crate_metadata
source ·Expand description
Defines types that contain metadata about crates loaded in Theseus and their dependencies.
Representing dependencies between sections
If one section A
references or uses another section B
,
then we colloquially say that A
depends on B
.
In this scenario, A
has a StrongDependency
on B
,
and B
has a WeakDependent
pointing back to A
.
Assuming A
and B
are both LoadedSection
objects,
then A.sections_i_depend_on
includes a StrongDependency(B)
and B.sections_dependent_on_me
includes a WeakDependent(A)
.
In this way, the dependency graphs are fully associative,
allowing a given LoadedSection
to easily find
both its dependencies and its dependents instantly.
More importantly, it allows A
to be dropped before B
,
but not the other way around.
This correctly avoids dependency violations by ensuring that a section B
is never dropped while any other section A
relies on it.
When swapping crates, the WeakDependent
s are actually more useful.
For example, if we want to swap the crate that contains section B1
with a new one B2
,
then we can immediately find all of the section A
s that depend on B1
by iterating over B1.sections_dependent_on_me
.
To complete the swap and fully replace B1
with B2
,
we would do the following (pseudocode):
for secA in B1.sections_dependent_on_me {
change secA's relocation to point to B1
add WeakDependent(secA) to B2.sections_dependent_on_me
remove StrongDependency(B1) from secA.sections_i_depend_on
add StrongDependency(B2) to secA.sections_i_depend_on
remove WeakDependent(secA) from B1.sections_dependent_on_me (current iterator)
}
Structs
CrateNamespace
.LoadedCrate
.
The containing SectionType
enum determines which type of section it is.LoadedSection
that may be mutable, i.e.,
only the parts that could change after a section is initially loaded and linked.Arc<str>
: an immutable shared reference to a string slice.A
of (a LoadedSection
object containing) this struct
depends on the given section
B
in this struct.
The dependent section A
is not specifically included here;
since it’s the owner of this struct, it’s implicit that it’s the dependent one.section
A
in this struct
depends on the owner B
of (the LoadedSection
object containing) this struct.
The target dependency B
is not specifically included here;
it’s implicitly the owner of this struct.Enums
Constants
.data
and .bss
sections are read-write and non-executable..rodata
sections are read-only and non-executable."my_crate::section_name::h<hash>"
..text
sections are read-only and executable.Functions
SectionType
as a StrRef
.Type Definitions
u16
,
its decoded form can exceed the max size of u16
.LoadedCrate
.Arc
) to a LoadedSection
.LoadedCrate
.Weak
) to a LoadedSection
.