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"]
    "8" [label="stdbool.h" tooltip="stdbool.h"]
    "30" [label="dictionary.h" tooltip="dictionary.h"]
    "5" [label="atom.h" tooltip="atom.h"]
    "11" [label="assert.h" tooltip="assert.h"]
    "16" [label="synclist.h" tooltip="synclist.h"]
    "28" [label="fenv.h" tooltip="fenv.h"]
    "4" [label="stdint.h" tooltip="stdint.h"]
    "6" [label="stdlib.h" tooltip="stdlib.h"]
    "36" [label="valueshashtable.h" tooltip="valueshashtable.h"]
    "35" [label="exportedfunction.h" tooltip="exportedfunction.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c" fillcolor="#BFBFBF"]
    "2" [label="context.h" tooltip="context.h"]
    "22" [label="utils.h" tooltip="utils.h"]
    "14" [label="ets.h" tooltip="ets.h"]
    "7" [label="atom_table.h" tooltip="atom_table.h"]
    "10" [label="term_typedef.h" tooltip="term_typedef.h"]
    "23" [label="stddef.h" tooltip="stddef.h"]
    "12" [label="limits.h" tooltip="limits.h"]
    "24" [label="refc_binary.h" tooltip="refc_binary.h"]
    "20" [label="string.h" tooltip="string.h"]
    "26" [label="mailbox.h" tooltip="mailbox.h"]
    "33" [label="module.h" tooltip="module.h"]
    "19" [label="term.h" tooltip="term.h"]
    "9" [label="erl_nif.h" tooltip="erl_nif.h"]
    "38" [label="opcodesswitch.h" tooltip="opcodesswitch.h"]
    "37" [label="time.h" tooltip="time.h"]
    "29" [label="math.h" tooltip="math.h"]
    "25" [label="resources.h" tooltip="resources.h"]
    "18" [label="smp.h" tooltip="smp.h"]
    "31" [label="erl_nif_priv.h" tooltip="erl_nif_priv.h"]
    "32" [label="sys.h" tooltip="sys.h"]
    "34" [label="atomshashtable.h" tooltip="atomshashtable.h"]
    "3" [label="globalcontext.h" tooltip="globalcontext.h"]
    "21" [label="memory.h" tooltip="memory.h"]
    "17" [label="stdio.h" tooltip="stdio.h"]
    "27" [label="timer_list.h" tooltip="timer_list.h"]
    "15" [label="list.h" tooltip="list.h"]
    "13" [label="inttypes.h" tooltip="inttypes.h"]
    "30" -> "15" [dir=forward tooltip="include"]
    "30" -> "19" [dir=forward tooltip="include"]
    "5" -> "4" [dir=forward tooltip="include"]
    "5" -> "6" [dir=forward tooltip="include"]
    "16" -> "17" [dir=forward tooltip="include"]
    "16" -> "15" [dir=forward tooltip="include"]
    "16" -> "18" [dir=forward tooltip="include"]
    "35" -> "19" [dir=forward tooltip="include"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "28" [dir=forward tooltip="include"]
    "1" -> "29" [dir=forward tooltip="include"]
    "1" -> "30" [dir=forward tooltip="include"]
    "1" -> "9" [dir=forward tooltip="include"]
    "1" -> "31" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "15" [dir=forward tooltip="include"]
    "1" -> "26" [dir=forward tooltip="include"]
    "1" -> "18" [dir=forward tooltip="include"]
    "1" -> "16" [dir=forward tooltip="include"]
    "1" -> "32" [dir=forward tooltip="include"]
    "1" -> "19" [dir=forward tooltip="include"]
    "1" -> "22" [dir=forward tooltip="include"]
    "1" -> "38" [dir=forward tooltip="include"]
    "2" -> "3" [dir=forward tooltip="include"]
    "2" -> "15" [dir=forward tooltip="include"]
    "2" -> "26" [dir=forward tooltip="include"]
    "2" -> "18" [dir=forward tooltip="include"]
    "2" -> "19" [dir=forward tooltip="include"]
    "2" -> "27" [dir=forward tooltip="include"]
    "22" -> "23" [dir=forward tooltip="include"]
    "22" -> "17" [dir=forward tooltip="include"]
    "22" -> "6" [dir=forward tooltip="include"]
    "14" -> "15" [dir=forward tooltip="include"]
    "14" -> "16" [dir=forward tooltip="include"]
    "14" -> "19" [dir=forward tooltip="include"]
    "7" -> "8" [dir=forward tooltip="include"]
    "7" -> "5" [dir=forward tooltip="include"]
    "10" -> "11" [dir=forward tooltip="include"]
    "10" -> "12" [dir=forward tooltip="include"]
    "10" -> "13" [dir=forward tooltip="include"]
    "10" -> "4" [dir=forward tooltip="include"]
    "24" -> "8" [dir=forward tooltip="include"]
    "24" -> "6" [dir=forward tooltip="include"]
    "24" -> "15" [dir=forward tooltip="include"]
    "24" -> "25" [dir=forward tooltip="include"]
    "26" -> "8" [dir=forward tooltip="include"]
    "26" -> "15" [dir=forward tooltip="include"]
    "26" -> "10" [dir=forward tooltip="include"]
    "26" -> "22" [dir=forward tooltip="include"]
    "33" -> "8" [dir=forward tooltip="include"]
    "33" -> "4" [dir=forward tooltip="include"]
    "33" -> "5" [dir=forward tooltip="include"]
    "33" -> "7" [dir=forward tooltip="include"]
    "33" -> "34" [dir=forward tooltip="include"]
    "33" -> "2" [dir=forward tooltip="include"]
    "33" -> "35" [dir=forward tooltip="include"]
    "33" -> "3" [dir=forward tooltip="include"]
    "33" -> "19" [dir=forward tooltip="include"]
    "33" -> "36" [dir=forward tooltip="include"]
    "19" -> "8" [dir=forward tooltip="include"]
    "19" -> "4" [dir=forward tooltip="include"]
    "19" -> "17" [dir=forward tooltip="include"]
    "19" -> "6" [dir=forward tooltip="include"]
    "19" -> "20" [dir=forward tooltip="include"]
    "19" -> "21" [dir=forward tooltip="include"]
    "19" -> "24" [dir=forward tooltip="include"]
    "19" -> "22" [dir=forward tooltip="include"]
    "19" -> "10" [dir=forward tooltip="include"]
    "9" -> "10" [dir=forward tooltip="include"]
    "25" -> "6" [dir=forward tooltip="include"]
    "25" -> "9" [dir=forward tooltip="include"]
    "25" -> "15" [dir=forward tooltip="include"]
    "25" -> "21" [dir=forward tooltip="include"]
    "18" -> "8" [dir=forward tooltip="include"]
    "31" -> "2" [dir=forward tooltip="include"]
    "31" -> "21" [dir=forward tooltip="include"]
    "32" -> "3" [dir=forward tooltip="include"]
    "32" -> "33" [dir=forward tooltip="include"]
    "32" -> "4" [dir=forward tooltip="include"]
    "32" -> "37" [dir=forward tooltip="include"]
    "34" -> "5" [dir=forward tooltip="include"]
    "3" -> "4" [dir=forward tooltip="include"]
    "3" -> "5" [dir=forward tooltip="include"]
    "3" -> "7" [dir=forward tooltip="include"]
    "3" -> "9" [dir=forward tooltip="include"]
    "3" -> "14" [dir=forward tooltip="include"]
    "3" -> "15" [dir=forward tooltip="include"]
    "3" -> "26" [dir=forward tooltip="include"]
    "3" -> "18" [dir=forward tooltip="include"]
    "3" -> "16" [dir=forward tooltip="include"]
    "3" -> "19" [dir=forward tooltip="include"]
    "3" -> "27" [dir=forward tooltip="include"]
    "21" -> "4" [dir=forward tooltip="include"]
    "21" -> "6" [dir=forward tooltip="include"]
    "21" -> "9" [dir=forward tooltip="include"]
    "21" -> "10" [dir=forward tooltip="include"]
    "21" -> "22" [dir=forward tooltip="include"]
    "27" -> "8" [dir=forward tooltip="include"]
    "27" -> "4" [dir=forward tooltip="include"]
    "27" -> "15" [dir=forward tooltip="include"]
    "15" -> "8" [dir=forward tooltip="include"]
}

Defines

IMPL_EXECUTE_LOOP
DEFAULT_STACK_SIZE 8
BYTES_PER_TERM (TERM_BITS / 8)

Functions

static struct ResourceMonitor *context_monitors_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:
  • glb – The global context of this virtual machine instance.

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:
  • c – the context that will be destroyed.

void context_process_kill_signal(Context *ctx, struct TermSignal *signal)

Process a kill signal, setting the exit reason and changing the killed flag.

Parameters:
  • ctx – the context being executed

  • signal – the kill message

void context_process_process_info_request_signal(Context *ctx, struct BuiltInAtomRequestSignal *signal)

Process a process info request signal.

Parameters:
  • ctx – the context being executed

  • signal – the kill message

bool context_process_signal_trap_answer(Context *ctx, struct TermSignal *signal)

Process a trap answer signal.

Parameters:
  • ctx – the context being executed

  • signal – the answer message

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.

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:
  • ctx – the context to set/clear flag on.

  • mask – the mask to apply on flags

  • value – the value to set

size_t context_message_queue_len(Context *ctx)

Returns number of messages in the process’s mailbox.

Parameters:
  • ctx – a valid context.

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:
  • ctx – a valid context.

Returns:

total amount of size (in byes) occupied by the process

bool context_get_process_info(Context *ctx, term *out, term atom_key)

Get process information.

Parameters:
  • ctx – the context being executed

  • out – the answer term

  • atom_key – the key representing the info to get

Returns:

true if successful, false in case of an error in which case *out is filled with an exception atom

Half-link process to another process.

Caller must hold the global process lock. This creates one half of the link.

Parameters:
  • ctx – context to link

  • monitor_pid – process to link ctx to

Returns:

0 on success

uint64_t context_monitor(Context *ctx, term monitor_pid)

Create a monitor on a process.

Caller must hold the global process lock.

Parameters:
  • ctx – context to monitor

  • monitor_pid – monitoring process

Returns:

the ref ticks

struct ResourceMonitor *context_resource_monitor(Context *ctx, void *resource)

Create a resource monitor on a process.

Caller must hold the global process lock. The returned resource monitor is not added to the monitors list on the resource type.

Parameters:
  • ctx – context to monitor

  • resource – resource object

Returns:

the resource monitor

Remove a half-link from a process.

Caller must hold the global process lock. This removes one half of the link.

Parameters:
  • ctx – context to monitor

  • monitor_pid – process to unlink