module.h

Include dependency graph for module.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="stdbool.h" tooltip="stdbool.h"]
    "4" [label="atom.h" tooltip="atom.h"]
    "12" [label="assert.h" tooltip="assert.h"]
    "17" [label="synclist.h" tooltip="synclist.h"]
    "3" [label="stdint.h" tooltip="stdint.h"]
    "5" [label="stdlib.h" tooltip="stdlib.h"]
    "30" [label="valueshashtable.h" tooltip="valueshashtable.h"]
    "29" [label="exportedfunction.h" tooltip="exportedfunction.h"]
    "8" [label="context.h" tooltip="context.h"]
    "23" [label="utils.h" tooltip="utils.h"]
    "15" [label="ets.h" tooltip="ets.h"]
    "6" [label="atom_table.h" tooltip="atom_table.h"]
    "11" [label="term_typedef.h" tooltip="term_typedef.h"]
    "24" [label="stddef.h" tooltip="stddef.h"]
    "13" [label="limits.h" tooltip="limits.h"]
    "25" [label="refc_binary.h" tooltip="refc_binary.h"]
    "21" [label="string.h" tooltip="string.h"]
    "27" [label="mailbox.h" tooltip="mailbox.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h" fillcolor="#BFBFBF"]
    "20" [label="term.h" tooltip="term.h"]
    "10" [label="erl_nif.h" tooltip="erl_nif.h"]
    "26" [label="resources.h" tooltip="resources.h"]
    "19" [label="smp.h" tooltip="smp.h"]
    "7" [label="atomshashtable.h" tooltip="atomshashtable.h"]
    "9" [label="globalcontext.h" tooltip="globalcontext.h"]
    "22" [label="memory.h" tooltip="memory.h"]
    "18" [label="stdio.h" tooltip="stdio.h"]
    "28" [label="timer_list.h" tooltip="timer_list.h"]
    "16" [label="list.h" tooltip="list.h"]
    "14" [label="inttypes.h" tooltip="inttypes.h"]
    "4" -> "3" [dir=forward tooltip="include"]
    "4" -> "5" [dir=forward tooltip="include"]
    "17" -> "18" [dir=forward tooltip="include"]
    "17" -> "16" [dir=forward tooltip="include"]
    "17" -> "19" [dir=forward tooltip="include"]
    "29" -> "20" [dir=forward tooltip="include"]
    "8" -> "9" [dir=forward tooltip="include"]
    "8" -> "16" [dir=forward tooltip="include"]
    "8" -> "27" [dir=forward tooltip="include"]
    "8" -> "19" [dir=forward tooltip="include"]
    "8" -> "20" [dir=forward tooltip="include"]
    "8" -> "28" [dir=forward tooltip="include"]
    "23" -> "24" [dir=forward tooltip="include"]
    "23" -> "18" [dir=forward tooltip="include"]
    "23" -> "5" [dir=forward tooltip="include"]
    "15" -> "16" [dir=forward tooltip="include"]
    "15" -> "17" [dir=forward tooltip="include"]
    "15" -> "20" [dir=forward tooltip="include"]
    "6" -> "2" [dir=forward tooltip="include"]
    "6" -> "4" [dir=forward tooltip="include"]
    "11" -> "12" [dir=forward tooltip="include"]
    "11" -> "13" [dir=forward tooltip="include"]
    "11" -> "14" [dir=forward tooltip="include"]
    "11" -> "3" [dir=forward tooltip="include"]
    "25" -> "2" [dir=forward tooltip="include"]
    "25" -> "5" [dir=forward tooltip="include"]
    "25" -> "16" [dir=forward tooltip="include"]
    "25" -> "26" [dir=forward tooltip="include"]
    "27" -> "2" [dir=forward tooltip="include"]
    "27" -> "16" [dir=forward tooltip="include"]
    "27" -> "11" [dir=forward tooltip="include"]
    "27" -> "23" [dir=forward tooltip="include"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "4" [dir=forward tooltip="include"]
    "1" -> "6" [dir=forward tooltip="include"]
    "1" -> "7" [dir=forward tooltip="include"]
    "1" -> "8" [dir=forward tooltip="include"]
    "1" -> "29" [dir=forward tooltip="include"]
    "1" -> "9" [dir=forward tooltip="include"]
    "1" -> "20" [dir=forward tooltip="include"]
    "1" -> "30" [dir=forward tooltip="include"]
    "20" -> "2" [dir=forward tooltip="include"]
    "20" -> "3" [dir=forward tooltip="include"]
    "20" -> "18" [dir=forward tooltip="include"]
    "20" -> "5" [dir=forward tooltip="include"]
    "20" -> "21" [dir=forward tooltip="include"]
    "20" -> "22" [dir=forward tooltip="include"]
    "20" -> "25" [dir=forward tooltip="include"]
    "20" -> "23" [dir=forward tooltip="include"]
    "20" -> "11" [dir=forward tooltip="include"]
    "10" -> "11" [dir=forward tooltip="include"]
    "26" -> "5" [dir=forward tooltip="include"]
    "26" -> "10" [dir=forward tooltip="include"]
    "26" -> "16" [dir=forward tooltip="include"]
    "26" -> "22" [dir=forward tooltip="include"]
    "19" -> "2" [dir=forward tooltip="include"]
    "7" -> "4" [dir=forward tooltip="include"]
    "9" -> "3" [dir=forward tooltip="include"]
    "9" -> "4" [dir=forward tooltip="include"]
    "9" -> "6" [dir=forward tooltip="include"]
    "9" -> "10" [dir=forward tooltip="include"]
    "9" -> "15" [dir=forward tooltip="include"]
    "9" -> "16" [dir=forward tooltip="include"]
    "9" -> "27" [dir=forward tooltip="include"]
    "9" -> "19" [dir=forward tooltip="include"]
    "9" -> "17" [dir=forward tooltip="include"]
    "9" -> "20" [dir=forward tooltip="include"]
    "9" -> "28" [dir=forward tooltip="include"]
    "22" -> "3" [dir=forward tooltip="include"]
    "22" -> "5" [dir=forward tooltip="include"]
    "22" -> "10" [dir=forward tooltip="include"]
    "22" -> "11" [dir=forward tooltip="include"]
    "22" -> "23" [dir=forward tooltip="include"]
    "28" -> "2" [dir=forward tooltip="include"]
    "28" -> "3" [dir=forward tooltip="include"]
    "28" -> "16" [dir=forward tooltip="include"]
    "16" -> "2" [dir=forward tooltip="include"]
}

This graph shows which files directly or indirectly include module.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "3" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.c"]
    "2" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.h"]
    "6" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h"]
    "10" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c"]
    "8" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c"]
    "7" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h"]
    "4" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h" fillcolor="#BFBFBF"]
    "14" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c"]
    "13" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c"]
    "9" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/sys.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/sys.h"]
    "5" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.c"]
    "11" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c"]
    "12" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"]
    "2" -> "3" [dir=back tooltip="include"]
    "2" -> "4" [dir=back tooltip="include"]
    "2" -> "5" [dir=back tooltip="include"]
    "6" -> "5" [dir=back tooltip="include"]
    "7" -> "8" [dir=back tooltip="include"]
    "1" -> "2" [dir=back tooltip="include"]
    "1" -> "4" [dir=back tooltip="include"]
    "1" -> "5" [dir=back tooltip="include"]
    "1" -> "6" [dir=back tooltip="include"]
    "1" -> "7" [dir=back tooltip="include"]
    "1" -> "9" [dir=back tooltip="include"]
    "1" -> "14" [dir=back tooltip="include"]
    "9" -> "10" [dir=back tooltip="include"]
    "9" -> "11" [dir=back tooltip="include"]
    "9" -> "4" [dir=back tooltip="include"]
    "9" -> "5" [dir=back tooltip="include"]
    "9" -> "12" [dir=back tooltip="include"]
    "9" -> "13" [dir=back tooltip="include"]
}

Module loading functions.

This header defines all the module loading functions and the Module struct.

Defines

SMP_MODULE_LOCK(mod) smp_mutex_lock(mod->mutex)
SMP_MODULE_UNLOCK(mod) smp_mutex_unlock(mod->mutex)

Enums

enum ModuleLoadResult

Values:

enumerator MODULE_LOAD_OK = 0
enumerator MODULE_ERROR_FAILED_ALLOCATION = 1

Functions

void module_get_imported_function_module_and_name(const Module *this_module, int index, AtomString *module_atom, AtomString *function_atom)

Gets imported function module and name.

Gets imported function module and name given its import table index.

Parameters:
  • this_module – the module on which the function will be searched.

  • index – the modules import table offset to begin searching.

  • module_atom – module name atom string.

  • function_atom – function name atom string.

size_t module_get_exported_functions_count(Module *this_module)

Count exported functions of a given module.

Get the number of exported functions. This function is used to compute the required heap size of the list of exported functions.

Parameters:
  • this_module – the module to count exported functions of

Returns:

the number of exported functions

uint32_t module_search_exported_function(Module *this_module, AtomString func_name, int func_arity, GlobalContext *glb)

Gets exported function index by searching it by function name and arity.

Gets exported function index by searching it by function name and arity

Parameters:
  • this_module – the module on which the function will be searched.

  • func_name – function name atom string.

  • func_arity – function arity.

  • glb – the global context

static inline size_t module_get_exported_functions_list_size(Module *this_module)

Determine heap size of exported functions list.

Parameters:
  • this_module – the module to count exported functions of

Returns:

the size, in terms, of the exported function list

term module_get_exported_functions(Module *this_module, Heap *heap, GlobalContext *global)

Get the list of exported functions.

Create a list of exported functions of the form {FunctionName, Arity} To create this list, the heap must be grown by module_get_exported_functions_list_size terms.

Parameters:
  • this_module – the module to count exported functions of

  • heap – heap to allocate tuples

  • global – global context to fetch atoms

Returns:

a list of exported functions

void module_destroy(Module *module)
Module *module_new_from_iff_binary(GlobalContext *global, const void *iff_binary, unsigned long size)

Parse a BEAM file and returns a Module.

Parse a BEAM file a returns a newly allocated and initialized Module struct.

Parameters:
  • global – the global context.

  • iff_binary – the IFF file data.

  • size – the size of the buffer containing the IFF data.

term module_load_literal(Module *mod, int index, Context *ctx)

Gets a literal stored on the literal table of the specified module.

Loads and deserialize a term stored in the literal table and returns a term.

Parameters:
  • mod – The module that owns that is going to be loaded.

  • index – a valid literal index.

  • ctx – the target context.

static inline AtomString module_get_atom_string_by_id(const Module *mod, int local_atom_id, GlobalContext *glb)

Gets the AtomString for the given local atom id.

Gets an AtomString for the given local atom id from the global table.

Parameters:
  • mod – the module that owns the atom.

  • local_atom_id – module atom table index.

  • glb – the global context.

Returns:

the AtomString for the given module atom index.

static inline term module_get_atom_term_by_id(const Module *mod, int local_atom_id)

Gets a term for the given local atom id.

Gets the global atom id for the the given local atom id and casts it to a term.

Parameters:
  • mod – the module that owns the atom.

  • local_atom_id – module atom table index.

Returns:

a term for the given module atom index.

const struct ExportedFunction *module_resolve_function0(Module *mod, int import_table_index, struct UnresolvedFunctionCall *unresolved, GlobalContext *glb)
static inline term module_get_name(const Module *mod)

Get the module name, as an atom term.

Parameters:
  • mod – the module to get the name of

Returns:

a term for the given module atom index.

static inline const struct ExportedFunction *module_resolve_function(Module *mod, int import_table_index, GlobalContext *glb)

Resolves an unresolved function reference.

Resolves an unresolved function reference and it replaces the unresolved reference with a ModuleFunction struct, also it loads the referenced module if it hasn’t been loaded yet.

Parameters:
  • mod – the module containing the function to resolve.

  • import_table_index – the unresolved function index.

  • glb – the global context

static inline term module_address(unsigned int module_index, unsigned int instruction_index)
static inline uint32_t module_get_fun_freeze(const Module *this_module, int fun_index)
static inline void module_get_fun(const Module *this_module, int fun_index, uint32_t *label, uint32_t *arity, uint32_t *n_freeze)
static inline const uint8_t *module_get_str(Module *mod, size_t offset, size_t *remaining)
bool module_get_function_from_label(Module *this_module, int label, AtomString *function_name, int *arity, GlobalContext *glb)
void module_insert_line_ref_offset(Module *mod, int line_ref, int offset)
int module_find_line(Module *mod, unsigned int offset)
static inline bool module_has_line_chunk(Module *mod)
Returns:

true if the module has line information, false, otherwise.

struct __attribute__
#include <module.h>

Public Members

char magic[4]
uint32_t size
uint32_t info_size
uint32_t version
uint32_t opcode_max
uint32_t labels
uint32_t functions_count
uint8_t code[1]
struct LiteralEntry
#include <module.h>

Public Members

uint32_t size
void const *data
struct ModuleFilename
#include <module.h>

Public Members

uint8_t *data
size_t len
struct LineRefOffset
#include <module.h>

Collaboration diagram for LineRefOffset:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="LineRefOffset" tooltip="LineRefOffset" fillcolor="#BFBFBF"]
    "2" [label="ListHead" tooltip="ListHead"]
    "1" -> "2" [dir=forward tooltip="usage"]
    "2" -> "2" [dir=forward tooltip="usage"]
}

Public Members

struct ListHead head
unsigned int offset
uint16_t line_ref
struct Module
#include <module.h>

Collaboration diagram for Module:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Module" tooltip="Module" fillcolor="#BFBFBF"]
    "5" [label="ListHead" tooltip="ListHead"]
    "3" [label="ModuleFilename" tooltip="ModuleFilename"]
    "4" [label="LiteralEntry" tooltip="LiteralEntry"]
    "2" [label="ExportedFunction" tooltip="ExportedFunction"]
    "1" -> "2" [dir=forward tooltip="usage"]
    "1" -> "3" [dir=forward tooltip="usage"]
    "1" -> "4" [dir=forward tooltip="usage"]
    "1" -> "5" [dir=forward tooltip="usage"]
    "5" -> "5" [dir=forward tooltip="usage"]
}

Public Members

void *import_table
CodeChunk *code
void *export_table
void *local_table
void *atom_table
void *fun_table
void *str_table
size_t str_table_len
uint16_t *line_refs
struct ModuleFilename *filenames
struct ListHead line_ref_offsets
const struct ExportedFunction **imported_funcs
const uint8_t **labels
void *literals_data
struct LiteralEntry *literals_table
int *local_atoms_to_global_table
void *module_platform_data
int module_index
int end_instruction_ii
unsigned int free_literals_data
Mutex *mutex