context.h
Include dependency graph for context.h:
This graph shows which files directly or indirectly include context.h:
Context struct and related management functions.
A context represent the state of a running erlang process or port.
Defines
-
MAX_REG 16
Typedefs
-
typedef enum NativeHandlerResult NativeHandlerResult
-
typedef NativeHandlerResult (*native_handler_f)(Context *ctx)
Enums
Functions
-
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 *c)
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.
-
static inline void context_ensure_fpregs(Context *c)
Ensure we have FP registers, allocating them if necessary.
- Parameters:
c – context fo allocate FP registers for
-
int context_execute_loop(Context *ctx, Module *mod, const char *function_name, int arity)
Starts executing a function.
Start executing bytecode for the specified function, this function will block until it terminates. The outcome is saved to x[0] register.
- Parameters:
ctx – the context that will be used to run the specified functions, x registers must be set to function arguments.
mod – the module name C string.
function_name – the function name C string.
arity – the function arity (number of arguments that are required).
- Returns:
1 if an error occurred, otherwise 0 is always returned.
-
static inline int context_is_port_driver(const Context *ctx)
Returns 1 if the context is a port driver.
Checks if the given context has a native_handler or not.
- Parameters:
ctx – a valid context
- Returns:
1 if ctx is a port driver, otherwise 0 is returned.
-
static inline void context_clean_registers(Context *ctx, int live)
Cleans up unused registers.
Sets to NIL unused registers, x[0] - x[live - 1] will not be overwritten.
- Parameters:
ctx – a valid context
live – number of used registers
-
static inline term *context_stack_base(const Context *ctx)
Returns a context’s stack base.
Used for stack traces
- Parameters:
ctx – a valid context.
- Returns:
the stack base
-
static inline size_t context_stack_size(const Context *ctx)
Returns a context’s stack size.
Return the number of terms currently on the stack. Used for stack traces.
- Parameters:
ctx – a valid context.
- Returns:
stack size in terms
-
static inline size_t context_avail_free_memory(const Context *ctx)
Returns available free memory in term units.
Returns the number of terms that can fit either on the heap.
- Parameters:
ctx – a valid context.
- Returns:
available free memory that is avail_size_in_bytes / sizeof(term).
-
static inline bool context_is_term_equal_to_atom_string(Context *ctx, term atom_a, AtomString atom_string_b)
Compares a term with an AtomString.
Checks if the given term and the given AtomString refers to the same atom. This function is just a shortcut that uses the corresponding funtion from globalcontext.
- Parameters:
ctx – the current Context.
atom_a – any term of any type, when it is not an atom false is always returned.
atom_string_b – an atom string, which is the atom length followed by atom characters.
- Returns:
true if they both refer to the same atom, otherwise false.
-
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
-
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
-
static inline int context_get_flags(Context *ctx, int mask)
Get flags on a given context.
- Parameters:
ctx – the context to get flags on.
mask – the mask to apply on flags
-
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.
-
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
-
int context_link(Context *ctx, term monitor_pid)
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
-
struct Context
- #include <context.h>
Collaboration diagram for Context:
Public Members
-
GlobalContext *global
-
Heap heap
-
term *e
-
term x[16 + 1]
-
struct ListHead extended_x_regs
-
struct ListHead processes_list_head
-
struct ListHead processes_table_head
-
int32_t process_id
-
struct TimerListItem timer_list_head
-
struct ListHead monitors_head
-
avm_float_t *fr
-
size_t min_heap_size
-
size_t max_heap_size
-
enum HeapGrowthStrategy heap_growth_strategy
-
unsigned long cp
-
const void *saved_ip
-
void *restore_trap_handler
-
struct ListHead dictionary
-
native_handler_f native_handler
-
uint64_t reductions
-
unsigned int leader
-
unsigned int has_min_heap_size
-
unsigned int has_max_heap_size
-
bool trap_exit
-
unsigned int trace_calls
-
unsigned int trace_call_args
-
unsigned int trace_returns
-
unsigned int trace_send
-
unsigned int trace_receive
-
enum ContextFlags flags
-
void *platform_data
-
term group_leader
-
term bs
-
size_t bs_offset
-
term exit_reason
-
GlobalContext *global
-
struct Monitor
- #include <context.h>
Collaboration diagram for Monitor:
A regular monitor or a half link.
-
struct ResourceMonitor
- #include <context.h>
Collaboration diagram for ResourceMonitor:
A resource monitor.
-
struct ExtendedRegister
- #include <context.h>
Collaboration diagram for ExtendedRegister: