avmpack.h
Include dependency graph for avmpack.h:
digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"4" [label="atom.h" tooltip="atom.h"]
"6" [label="atom_table.h" tooltip="atom_table.h"]
"1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.h" fillcolor="#BFBFBF"]
"12" [label="erl_nif.h" tooltip="erl_nif.h"]
"16" [label="ets.h" tooltip="ets.h"]
"2" [label="globalcontext.h" tooltip="globalcontext.h"]
"23" [label="intn.h" tooltip="intn.h"]
"18" [label="list.h" tooltip="list.h"]
"27" [label="mailbox.h" tooltip="mailbox.h"]
"24" [label="memory.h" tooltip="memory.h"]
"25" [label="refc_binary.h" tooltip="refc_binary.h"]
"26" [label="resources.h" tooltip="resources.h"]
"19" [label="smp.h" tooltip="smp.h"]
"17" [label="synclist.h" tooltip="synclist.h"]
"20" [label="term.h" tooltip="term.h"]
"13" [label="term_typedef.h" tooltip="term_typedef.h"]
"28" [label="timer_list.h" tooltip="timer_list.h"]
"8" [label="utils.h" tooltip="utils.h"]
"29" [label="valueshashtable.h" tooltip="valueshashtable.h"]
"14" [label="assert.h" tooltip="assert.h"]
"9" [label="inttypes.h" tooltip="inttypes.h"]
"15" [label="limits.h" tooltip="limits.h"]
"7" [label="stdbool.h" tooltip="stdbool.h"]
"10" [label="stddef.h" tooltip="stddef.h"]
"3" [label="stdint.h" tooltip="stdint.h"]
"11" [label="stdio.h" tooltip="stdio.h"]
"5" [label="stdlib.h" tooltip="stdlib.h"]
"22" [label="string.h" tooltip="string.h"]
"21" [label="sys/types.h" tooltip="sys/types.h"]
"4" -> "3" [dir=forward tooltip="include"]
"4" -> "5" [dir=forward tooltip="include"]
"6" -> "7" [dir=forward tooltip="include"]
"6" -> "4" [dir=forward tooltip="include"]
"6" -> "8" [dir=forward tooltip="include"]
"1" -> "2" [dir=forward tooltip="include"]
"1" -> "18" [dir=forward tooltip="include"]
"1" -> "7" [dir=forward tooltip="include"]
"1" -> "10" [dir=forward tooltip="include"]
"1" -> "3" [dir=forward tooltip="include"]
"12" -> "13" [dir=forward tooltip="include"]
"16" -> "7" [dir=forward tooltip="include"]
"16" -> "17" [dir=forward tooltip="include"]
"16" -> "20" [dir=forward tooltip="include"]
"2" -> "3" [dir=forward tooltip="include"]
"2" -> "4" [dir=forward tooltip="include"]
"2" -> "6" [dir=forward tooltip="include"]
"2" -> "12" [dir=forward tooltip="include"]
"2" -> "16" [dir=forward tooltip="include"]
"2" -> "18" [dir=forward tooltip="include"]
"2" -> "27" [dir=forward tooltip="include"]
"2" -> "19" [dir=forward tooltip="include"]
"2" -> "17" [dir=forward tooltip="include"]
"2" -> "20" [dir=forward tooltip="include"]
"2" -> "28" [dir=forward tooltip="include"]
"2" -> "29" [dir=forward tooltip="include"]
"23" -> "7" [dir=forward tooltip="include"]
"23" -> "22" [dir=forward tooltip="include"]
"23" -> "8" [dir=forward tooltip="include"]
"18" -> "7" [dir=forward tooltip="include"]
"27" -> "7" [dir=forward tooltip="include"]
"27" -> "18" [dir=forward tooltip="include"]
"27" -> "13" [dir=forward tooltip="include"]
"27" -> "8" [dir=forward tooltip="include"]
"24" -> "3" [dir=forward tooltip="include"]
"24" -> "5" [dir=forward tooltip="include"]
"24" -> "12" [dir=forward tooltip="include"]
"24" -> "13" [dir=forward tooltip="include"]
"24" -> "8" [dir=forward tooltip="include"]
"25" -> "7" [dir=forward tooltip="include"]
"25" -> "5" [dir=forward tooltip="include"]
"25" -> "18" [dir=forward tooltip="include"]
"25" -> "26" [dir=forward tooltip="include"]
"26" -> "5" [dir=forward tooltip="include"]
"26" -> "12" [dir=forward tooltip="include"]
"26" -> "18" [dir=forward tooltip="include"]
"26" -> "27" [dir=forward tooltip="include"]
"26" -> "24" [dir=forward tooltip="include"]
"26" -> "17" [dir=forward tooltip="include"]
"19" -> "7" [dir=forward tooltip="include"]
"17" -> "11" [dir=forward tooltip="include"]
"17" -> "18" [dir=forward tooltip="include"]
"17" -> "19" [dir=forward tooltip="include"]
"20" -> "21" [dir=forward tooltip="include"]
"20" -> "7" [dir=forward tooltip="include"]
"20" -> "3" [dir=forward tooltip="include"]
"20" -> "11" [dir=forward tooltip="include"]
"20" -> "5" [dir=forward tooltip="include"]
"20" -> "22" [dir=forward tooltip="include"]
"20" -> "4" [dir=forward tooltip="include"]
"20" -> "23" [dir=forward tooltip="include"]
"20" -> "24" [dir=forward tooltip="include"]
"20" -> "25" [dir=forward tooltip="include"]
"20" -> "26" [dir=forward tooltip="include"]
"20" -> "8" [dir=forward tooltip="include"]
"20" -> "13" [dir=forward tooltip="include"]
"13" -> "14" [dir=forward tooltip="include"]
"13" -> "15" [dir=forward tooltip="include"]
"13" -> "9" [dir=forward tooltip="include"]
"13" -> "3" [dir=forward tooltip="include"]
"28" -> "7" [dir=forward tooltip="include"]
"28" -> "3" [dir=forward tooltip="include"]
"28" -> "18" [dir=forward tooltip="include"]
"8" -> "9" [dir=forward tooltip="include"]
"8" -> "7" [dir=forward tooltip="include"]
"8" -> "10" [dir=forward tooltip="include"]
"8" -> "11" [dir=forward tooltip="include"]
"8" -> "5" [dir=forward tooltip="include"]
"29" -> "10" [dir=forward tooltip="include"]
"29" -> "3" [dir=forward tooltip="include"]
}
This graph shows which files directly or indirectly include avmpack.h:
digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"2" [label="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.c"]
"1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.h" fillcolor="#BFBFBF"]
"3" [label="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.c"]
"4" [label="/__w/AtomVM/AtomVM/src/libAtomVM/jit_stream_flash.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/jit_stream_flash.c"]
"5" [label="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c"]
"1" -> "2" [dir=back tooltip="include"]
"1" -> "3" [dir=back tooltip="include"]
"1" -> "4" [dir=back tooltip="include"]
"1" -> "5" [dir=back tooltip="include"]
}
AVM Pack file format parsing function.
Defines
END_OF_FILE 0
BEAM_START_FLAG 1
BEAM_CODE_FLAG 2
END_OF_FILE_MASK 255
Typedefs
typedef void * ( * avmpack_fold_fun ) ( void * accum , const void * section_ptr , uint32_t section_size , const void * beam_ptr , uint32_t flags , const char * section_name )
callback function for AVMPack section fold.
Instances of this function are supplied to the avmpack_fold function, in order to provide a callback mechanism for folding over the contents of the AVM binary.
Param accum:
The accumulator supplied by the application.
Param section_ptr:
a pointer to the start of the AVM section (including the module header).
Param section_size:
the size of the entire section (including the module header).
Param beam_ptr:
the start of the beam module portion of the section. This pointers starts immediately after the (aligned) header.
Param flags:
the section flags, as defined in the module header.
Param section_name:
the section name, as defined in the module header.
Return:
an accumulator, which will be supplied to the next call to this function, and eventually returned from the avmpack_fold function.
Functions
static inline void avmpack_data_init ( struct AVMPackData * avm_pack_data , const struct AVMPackInfo * info , uint32_t size )
static inline void avmpack_data_destroy ( struct AVMPackData * avm_pack_data , GlobalContext * global )
int avmpack_find_section_by_flag ( const void * avmpack_binary , uint32_t avmpack_size , uint32_t flags_mask , uint32_t flags_value , const void * * ptr , uint32_t * size , const char * * name )
Finds an AVM Pack section that has certain flags set.
Finds an AVM Pack section that has certain flags set and returns a pointer to it, its size and its name. The scan is bounded by avmpack_size .
Parameters:
avmpack_binary – a pointer to valid AVM Pack file data.
avmpack_size – the size in bytes of the AVM Pack.
flags_mask – that will be matched against file sections.
flags_value – that will be matched against file sections.
ptr – [out] will point to the found file section.
size – [out] the payload size at ptr , without the section header and the padded name; not updated if the section has not been found.
name – [out] the section name, as defined in the module header.
Returns:
1 if the file section has been found, 0 otherwise.
int avmpack_find_section_by_name ( const void * avmpack_binary , uint32_t avmpack_size , const char * name , const void * * ptr , uint32_t * size )
Finds an AVM Pack section that has certain name.
Finds an AVM Pack section with a certain name and returns a pointer to it and its size. The scan is bounded by avmpack_size .
Parameters:
avmpack_binary – a pointer to valid AVM Pack file data.
avmpack_size – the size in bytes of the AVM Pack.
name – the file section name that will be searched.
ptr – [out] will point to the found file section; not updated if the section has not been found.
size – [out] the payload size at ptr , without the section header and the padded name; not updated if the section has not been found.
Returns:
1 if the file section has been found, 0 otherwise.
bool avmpack_is_valid ( const void * avmpack_binary , uint32_t size )
Returns true if the pointed binary starts with a valid AVM Pack header.
Checks the 24-byte magic header only; see avmpack_is_complete and avmpack_compute_size for truncation.
Parameters:
Returns:
true if it is a valid AVM Pack binary, false otherwise.
bool avmpack_is_complete ( const void * avmpack_binary , size_t exact_size )
Returns true if an AVM Pack of exactly known size ends with its end terminator.
Reads the header and the last 16 bytes only, so a memory-mapped pack stays lazily paged. Trailing bytes after the terminator and sizes above UINT32_MAX are rejected.
Parameters:
Returns:
true if the pack is complete, false otherwise.
bool avmpack_compute_size ( const void * avmpack_binary , uint32_t max_size , uint32_t * real_size )
Finds the end of an AVM Pack within a region and returns its real size.
Walks the section chain, validating every header, until the end terminator or max_size is reached.
Parameters:
avmpack_binary – a pointer to an AVM Pack binary.
max_size – the size in bytes of the region containing the AVM Pack.
real_size – [out] set to the size in bytes of the AVM Pack on success.
Returns:
true if the terminator was found within max_size , false otherwise.
void * avmpack_fold ( void * accum , const void * avmpack_binary , uint32_t avmpack_size , avmpack_fold_fun fold_fun )
Fold over all the sections in an AVM Pack.
This function will call the callback on each section of the AVM Pack, passing in the current section of each module in the AVM binary to the supplied fold function. The scan is bounded by avmpack_size and stops on the terminator or on the first invalid section header.
Parameters:
accum – The accumulator supplied by the application.
avmpack_binary – a pointer to an AVM Pack binary.
avmpack_size – the size in bytes of the AVM Pack.
fold_fun – function that will be called for each AVM section.
struct AVMPackInfo
#include <avmpack.h>
struct AVMPackData
#include <avmpack.h>
Collaboration diagram for AVMPackData:
digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"1" [label="AVMPackData" tooltip="AVMPackData" fillcolor="#BFBFBF"]
"2" [label="AVMPackInfo" tooltip="AVMPackInfo"]
"3" [label="ListHead" tooltip="ListHead"]
"1" -> "2" [dir=forward tooltip="usage"]
"1" -> "3" [dir=forward tooltip="usage"]
"3" -> "3" [dir=forward tooltip="usage"]
}
Public Members
const struct AVMPackInfo * obj_info
struct ListHead avmpack_head
bool in_use
int name_atom_id
const void * data
uint32_t size
struct InMemoryAVMPack
#include <avmpack.h>
Collaboration diagram for InMemoryAVMPack:
digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"2" [label="AVMPackData" tooltip="AVMPackData"]
"3" [label="AVMPackInfo" tooltip="AVMPackInfo"]
"1" [label="InMemoryAVMPack" tooltip="InMemoryAVMPack" fillcolor="#BFBFBF"]
"4" [label="ListHead" tooltip="ListHead"]
"2" -> "3" [dir=forward tooltip="usage"]
"2" -> "4" [dir=forward tooltip="usage"]
"1" -> "2" [dir=forward tooltip="usage"]
"4" -> "4" [dir=forward tooltip="usage"]
}
struct ConstAVMPack
#include <avmpack.h>
Collaboration diagram for ConstAVMPack:
digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"2" [label="AVMPackData" tooltip="AVMPackData"]
"3" [label="AVMPackInfo" tooltip="AVMPackInfo"]
"1" [label="ConstAVMPack" tooltip="ConstAVMPack" fillcolor="#BFBFBF"]
"4" [label="ListHead" tooltip="ListHead"]
"2" -> "3" [dir=forward tooltip="usage"]
"2" -> "4" [dir=forward tooltip="usage"]
"1" -> "2" [dir=forward tooltip="usage"]
"4" -> "4" [dir=forward tooltip="usage"]
}