context.c
Include dependency graph for context.c:
digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"5" [label="atom.h" tooltip="atom.h"]
"7" [label="atom_table.h" tooltip="atom_table.h"]
"32" [label="bitstring.h" tooltip="bitstring.h"]
"1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/context.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/context.c" fillcolor="#BFBFBF"]
"2" [label="context.h" tooltip="context.h"]
"37" [label="defaultatoms.h" tooltip="defaultatoms.h"]
"39" [label="dictionary.h" tooltip="dictionary.h"]
"13" [label="erl_nif.h" tooltip="erl_nif.h"]
"40" [label="erl_nif_priv.h" tooltip="erl_nif_priv.h"]
"17" [label="ets.h" tooltip="ets.h"]
"34" [label="exportedfunction.h" tooltip="exportedfunction.h"]
"3" [label="globalcontext.h" tooltip="globalcontext.h"]
"24" [label="intn.h" tooltip="intn.h"]
"31" [label="jit.h" tooltip="jit.h"]
"18" [label="list.h" tooltip="list.h"]
"28" [label="mailbox.h" tooltip="mailbox.h"]
"25" [label="memory.h" tooltip="memory.h"]
"42" [label="module.h" tooltip="module.h"]
"26" [label="refc_binary.h" tooltip="refc_binary.h"]
"27" [label="resources.h" tooltip="resources.h"]
"20" [label="smp.h" tooltip="smp.h"]
"19" [label="synclist.h" tooltip="synclist.h"]
"41" [label="sys.h" tooltip="sys.h"]
"21" [label="term.h" tooltip="term.h"]
"14" [label="term_typedef.h" tooltip="term_typedef.h"]
"29" [label="timer_list.h" tooltip="timer_list.h"]
"33" [label="unicode.h" tooltip="unicode.h"]
"9" [label="utils.h" tooltip="utils.h"]
"30" [label="valueshashtable.h" tooltip="valueshashtable.h"]
"15" [label="assert.h" tooltip="assert.h"]
"38" [label="defaultatoms.def" tooltip="defaultatoms.def"]
"35" [label="fenv.h" tooltip="fenv.h"]
"10" [label="inttypes.h" tooltip="inttypes.h"]
"16" [label="limits.h" tooltip="limits.h"]
"36" [label="math.h" tooltip="math.h"]
"44" [label="opcodesswitch.h" tooltip="opcodesswitch.h"]
"8" [label="stdbool.h" tooltip="stdbool.h"]
"11" [label="stddef.h" tooltip="stddef.h"]
"4" [label="stdint.h" tooltip="stdint.h"]
"12" [label="stdio.h" tooltip="stdio.h"]
"6" [label="stdlib.h" tooltip="stdlib.h"]
"23" [label="string.h" tooltip="string.h"]
"22" [label="sys/types.h" tooltip="sys/types.h"]
"43" [label="time.h" tooltip="time.h"]
"5" -> "4" [dir=forward tooltip="include"]
"5" -> "6" [dir=forward tooltip="include"]
"7" -> "8" [dir=forward tooltip="include"]
"7" -> "5" [dir=forward tooltip="include"]
"7" -> "9" [dir=forward tooltip="include"]
"32" -> "24" [dir=forward tooltip="include"]
"32" -> "21" [dir=forward tooltip="include"]
"32" -> "33" [dir=forward tooltip="include"]
"32" -> "8" [dir=forward tooltip="include"]
"32" -> "4" [dir=forward tooltip="include"]
"1" -> "2" [dir=forward tooltip="include"]
"1" -> "35" [dir=forward tooltip="include"]
"1" -> "36" [dir=forward tooltip="include"]
"1" -> "37" [dir=forward tooltip="include"]
"1" -> "39" [dir=forward tooltip="include"]
"1" -> "13" [dir=forward tooltip="include"]
"1" -> "40" [dir=forward tooltip="include"]
"1" -> "3" [dir=forward tooltip="include"]
"1" -> "18" [dir=forward tooltip="include"]
"1" -> "28" [dir=forward tooltip="include"]
"1" -> "25" [dir=forward tooltip="include"]
"1" -> "20" [dir=forward tooltip="include"]
"1" -> "19" [dir=forward tooltip="include"]
"1" -> "41" [dir=forward tooltip="include"]
"1" -> "21" [dir=forward tooltip="include"]
"1" -> "9" [dir=forward tooltip="include"]
"1" -> "44" [dir=forward tooltip="include"]
"2" -> "3" [dir=forward tooltip="include"]
"2" -> "31" [dir=forward tooltip="include"]
"2" -> "18" [dir=forward tooltip="include"]
"2" -> "28" [dir=forward tooltip="include"]
"2" -> "20" [dir=forward tooltip="include"]
"2" -> "21" [dir=forward tooltip="include"]
"2" -> "29" [dir=forward tooltip="include"]
"37" -> "3" [dir=forward tooltip="include"]
"37" -> "38" [dir=forward tooltip="include"]
"39" -> "18" [dir=forward tooltip="include"]
"39" -> "21" [dir=forward tooltip="include"]
"13" -> "14" [dir=forward tooltip="include"]
"40" -> "2" [dir=forward tooltip="include"]
"40" -> "25" [dir=forward tooltip="include"]
"40" -> "27" [dir=forward tooltip="include"]
"17" -> "18" [dir=forward tooltip="include"]
"17" -> "19" [dir=forward tooltip="include"]
"17" -> "21" [dir=forward tooltip="include"]
"34" -> "21" [dir=forward tooltip="include"]
"3" -> "4" [dir=forward tooltip="include"]
"3" -> "5" [dir=forward tooltip="include"]
"3" -> "7" [dir=forward tooltip="include"]
"3" -> "13" [dir=forward tooltip="include"]
"3" -> "17" [dir=forward tooltip="include"]
"3" -> "18" [dir=forward tooltip="include"]
"3" -> "28" [dir=forward tooltip="include"]
"3" -> "20" [dir=forward tooltip="include"]
"3" -> "19" [dir=forward tooltip="include"]
"3" -> "21" [dir=forward tooltip="include"]
"3" -> "29" [dir=forward tooltip="include"]
"3" -> "30" [dir=forward tooltip="include"]
"24" -> "8" [dir=forward tooltip="include"]
"24" -> "23" [dir=forward tooltip="include"]
"24" -> "9" [dir=forward tooltip="include"]
"31" -> "32" [dir=forward tooltip="include"]
"31" -> "34" [dir=forward tooltip="include"]
"31" -> "21" [dir=forward tooltip="include"]
"31" -> "14" [dir=forward tooltip="include"]
"31" -> "8" [dir=forward tooltip="include"]
"18" -> "8" [dir=forward tooltip="include"]
"28" -> "8" [dir=forward tooltip="include"]
"28" -> "18" [dir=forward tooltip="include"]
"28" -> "14" [dir=forward tooltip="include"]
"28" -> "9" [dir=forward tooltip="include"]
"25" -> "4" [dir=forward tooltip="include"]
"25" -> "6" [dir=forward tooltip="include"]
"25" -> "13" [dir=forward tooltip="include"]
"25" -> "14" [dir=forward tooltip="include"]
"25" -> "9" [dir=forward tooltip="include"]
"42" -> "8" [dir=forward tooltip="include"]
"42" -> "4" [dir=forward tooltip="include"]
"42" -> "5" [dir=forward tooltip="include"]
"42" -> "7" [dir=forward tooltip="include"]
"42" -> "2" [dir=forward tooltip="include"]
"42" -> "34" [dir=forward tooltip="include"]
"42" -> "3" [dir=forward tooltip="include"]
"42" -> "31" [dir=forward tooltip="include"]
"42" -> "21" [dir=forward tooltip="include"]
"26" -> "8" [dir=forward tooltip="include"]
"26" -> "6" [dir=forward tooltip="include"]
"26" -> "18" [dir=forward tooltip="include"]
"26" -> "27" [dir=forward tooltip="include"]
"27" -> "6" [dir=forward tooltip="include"]
"27" -> "13" [dir=forward tooltip="include"]
"27" -> "18" [dir=forward tooltip="include"]
"27" -> "28" [dir=forward tooltip="include"]
"27" -> "25" [dir=forward tooltip="include"]
"27" -> "19" [dir=forward tooltip="include"]
"20" -> "8" [dir=forward tooltip="include"]
"19" -> "12" [dir=forward tooltip="include"]
"19" -> "18" [dir=forward tooltip="include"]
"19" -> "20" [dir=forward tooltip="include"]
"41" -> "3" [dir=forward tooltip="include"]
"41" -> "42" [dir=forward tooltip="include"]
"41" -> "4" [dir=forward tooltip="include"]
"41" -> "43" [dir=forward tooltip="include"]
"21" -> "22" [dir=forward tooltip="include"]
"21" -> "8" [dir=forward tooltip="include"]
"21" -> "4" [dir=forward tooltip="include"]
"21" -> "12" [dir=forward tooltip="include"]
"21" -> "6" [dir=forward tooltip="include"]
"21" -> "23" [dir=forward tooltip="include"]
"21" -> "5" [dir=forward tooltip="include"]
"21" -> "24" [dir=forward tooltip="include"]
"21" -> "25" [dir=forward tooltip="include"]
"21" -> "26" [dir=forward tooltip="include"]
"21" -> "9" [dir=forward tooltip="include"]
"21" -> "14" [dir=forward tooltip="include"]
"14" -> "15" [dir=forward tooltip="include"]
"14" -> "16" [dir=forward tooltip="include"]
"14" -> "10" [dir=forward tooltip="include"]
"14" -> "4" [dir=forward tooltip="include"]
"29" -> "8" [dir=forward tooltip="include"]
"29" -> "4" [dir=forward tooltip="include"]
"29" -> "18" [dir=forward tooltip="include"]
"33" -> "8" [dir=forward tooltip="include"]
"33" -> "11" [dir=forward tooltip="include"]
"33" -> "4" [dir=forward tooltip="include"]
"9" -> "10" [dir=forward tooltip="include"]
"9" -> "8" [dir=forward tooltip="include"]
"9" -> "11" [dir=forward tooltip="include"]
"9" -> "12" [dir=forward tooltip="include"]
"9" -> "6" [dir=forward tooltip="include"]
"30" -> "11" [dir=forward tooltip="include"]
"30" -> "4" [dir=forward tooltip="include"]
}
Defines
IMPL_EXECUTE_LOOP
DEFAULT_STACK_SIZE 8
BYTES_PER_TERM ( TERM_BITS / 8)
Functions
static struct Monitor * context_monitors_handle_terminate ( Context * ctx )
static void context_distribution_handle_terminate ( Context * ctx )
static void destroy_extended_registers ( Context * ctx , unsigned int live )
Context * context_new ( GlobalContext * glb )
Creates a new context.
Allocates a new Context struct and initialize it. The newly created context is also inserted into the processes table, however it is not scheduled, allowing for further initialization.
Parameters:
Returns:
created context.
void context_destroy ( Context * ctx )
Destroys a context.
Frees context resources and memory and removes it from the processes table. This should be called from the scheduler only. To actually delete a context that was created with context_new, use scheduler_terminate.
Parameters:
static inline term term_pid_or_port_from_context ( const Context * ctx )
void context_process_kill_signal ( Context * ctx , struct TermSignal * signal )
Process a kill signal, setting the exit reason and changing the killed flag.
Parameters:
void context_process_process_info_request_signal ( Context * ctx , struct BuiltInAtomRequestSignal * signal , bool process_table_locked )
Process a process info request signal.
Parameters:
ctx – the context being executed
signal – the process info signal
process_table_locked – whether process table is already locked
bool context_process_signal_trap_answer ( Context * ctx , struct TermSignal * signal )
Process a trap answer signal.
Parameters:
Returns:
true if successful, false in case of memory error
bool context_process_signal_set_group_leader ( Context * ctx , const struct TermSignal * signal )
Process set group leader signal.
Parameters:
Returns:
true if successful, false in case of memory error
void context_process_flush_monitor_signal ( Context * ctx , uint64_t ref_ticks , bool info )
Process a flush monitor signal.
Parameters:
ctx – the context being executed
ref_ticks – the monitor reference
info – whether to return FALSE_ATOM if no message was flushed.
bool context_process_link_exit_signal ( Context * ctx , struct TermSignal * signal )
Process a link exit signal.
Parameters:
Returns:
true if the process is trapping exit and info tuple was enqueued as a message;
void context_process_monitor_down_signal ( Context * ctx , struct TermSignal * signal )
Process a monitor down signal.
Parameters:
void context_process_code_server_resume_signal ( Context * ctx )
Resume execution after module has been loaded.
Parameters:
void context_update_flags ( Context * ctx , int mask , int value )
Set or clear a flag on another context.
atomically update flags <- (flags & mask) | value
Parameters:
size_t context_message_queue_len ( Context * ctx )
Returns number of messages in the process’s mailbox.
Parameters:
Returns:
the number of messages in the process’s mailbox
size_t context_size ( Context * ctx )
Returns total amount of size (in byes) occupied by the process.
Parameters:
Returns:
total amount of size (in byes) occupied by the process
bool context_get_process_info ( Context * ctx , term * out , size_t * term_size , term atom_key , Heap * heap )
Get process information.
Parameters:
ctx – the context being executed
out – the answer term. Can be NULL if only the size matters.
term_size – the size of the answer term, in words.
atom_key – the key representing the info to get
heap – the heap to allocate the answer to
Returns:
true if successful, false in case of an error in which case *out is filled with an exception atom if it was not NULL
struct Monitor * monitor_link_new ( term link_pid )
Half-link process to another process.
Parameters:
Returns:
the allocated monitor or NULL if allocation failed
struct Monitor * monitor_new ( term monitor_pid , uint64_t ref_ticks , bool is_monitoring )
Create a monitor on a process.
Parameters:
monitor_pid – monitored process
ref_ticks – reference of the monitor
is_monitoring – if ctx is the monitoring process
Returns:
the allocated monitor or NULL if allocation failed
struct Monitor * monitor_registeredname_monitor_new ( int32_t monitor_process_id , term monitor_name , uint64_t ref_ticks )
Create a monitor on a process by registered name.
Parameters:
monitor_process_id – monitored process id
monitor_name – name of the monitor (atom)
ref_ticks – reference of the monitor
is_monitoring – if ctx is the monitoring process
Returns:
the allocated monitor or NULL if allocation failed
struct Monitor * monitor_resource_monitor_new ( void * resource , uint64_t ref_ticks )
Create a resource monitor.
Parameters:
Returns:
the allocated resource monitor or NULL if allocation failed
bool context_add_monitor ( Context * ctx , struct Monitor * new_monitor )
Add a monitor on a process.
Called within the process only. This function is called from MonitorSignal. Monitor is not added if it already exists. Monitors are identified by a reference, but links have no reference and a link can only exist once.
Parameters:
Returns:
true if the monitor was added, false if it already existed and new_monitor waw freed.
bool context_set_unlink_id ( Context * ctx , term link_pid , uint64_t * unlink_id )
Half-unlink process to another process.
If process is found, an unlink id is generated and the link is deactivated.
Parameters:
ctx – the context being executed
link_pid – process to unlink from
unlink_id – on output, unlink id to send to the target process
Returns:
true if process was found
void context_ack_unlink ( Context * ctx , term link_pid , uint64_t unlink_id , bool process_table_locked )
Half-unlink process to another process.
Called within the process only when an UnlinkID signal is received. If link is found, remove it and sends an UnlinkIDAck signal to the linked process.
Parameters:
ctx – the context being executed
link_pid – process to unlink from
unlink_id – unlink id from the signal
process_table_locked – whether process table is already locked
void context_unlink_ack ( Context * ctx , term link_pid , uint64_t unlink_id )
Half-unlink process to another process.
Called within the process only when an UnlinkIDAck signal is received. If link is found and matches, remove it.
Parameters:
ctx – the context being executed
link_pid – process to unlink from
unlink_id – unlink id from the signal
void context_demonitor ( Context * ctx , uint64_t ref_ticks )
Destroy a monitor on a process (monitoring, monitored or resource)
Called within the process only. This function is called from DemonitorSignal as well as demonitor nif on monitoring process.
Parameters:
term context_get_monitor_pid ( Context * ctx , uint64_t ref_ticks , bool * is_monitoring )
Get target of a monitor.
Parameters:
ctx – the context being executed
ref_ticks – reference of the monitor to remove
is_monitoring – whether ctx is the monitoring process.
Returns:
pid of monitored or monitoring process or term_invalid() if no monitor could be found.
int context_get_catch_label ( Context * ctx , Module * * mod )
Get catch label from stack.
Parameters:
Returns:
the found label or 0 if no catch label was found in the stack
void context_dump ( Context * ctx )
Dump context to stderr.
Parameters: