infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
infix_internals.h File Reference

Declarations for internal-only functions, types, and constants. More...

#include "common/infix_config.h"
#include <infix/infix.h>
Include dependency graph for infix_internals.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  infix_executable_t
 
struct  infix_protected_t
 
struct  infix_forward_t
 
struct  infix_reverse_t
 
struct  infix_arena_t
 
struct  _infix_registry_entry_t
 
struct  infix_registry_t
 
struct  code_buffer
 
struct  infix_arg_location
 
struct  infix_call_frame_layout
 
struct  infix_reverse_call_frame_layout
 
struct  infix_forward_abi_spec
 
struct  infix_reverse_abi_spec
 

Macros

#define INFIX_MAX_STACK_ALLOC   (1024 * 1024 * 4)
 
#define INFIX_MAX_ARG_SIZE   (1024 * 64)
 
#define EMIT_BYTES(buf, ...)
 A macro for emitting a sequence of literal bytes into a code buffer.
 

Typedefs

typedef void(* infix_internal_dispatch_callback_fn) (infix_reverse_t *, void *, void **)
 
typedef struct _infix_registry_entry_t _infix_registry_entry_t
 

Enumerations

enum  infix_arg_location_type {
  ARG_LOCATION_GPR , ARG_LOCATION_XMM , ARG_LOCATION_GPR_PAIR , ARG_LOCATION_SSE_SSE_PAIR ,
  ARG_LOCATION_INTEGER_SSE_PAIR , ARG_LOCATION_SSE_INTEGER_PAIR , ARG_LOCATION_STACK
}
 

Functions

void _infix_set_error (infix_error_category_t, infix_error_code_t, size_t)
 Sets the thread-local error details for a library-internal error.
 
void _infix_set_system_error (infix_error_category_t, infix_error_code_t, long, const char *)
 Sets the thread-local error details for an error originating from the OS.
 
void _infix_clear_error (void)
 Resets the thread-local error state. Called at the start of every public API function.
 
infix_type_copy_type_graph_to_arena (infix_arena_t *, const infix_type *)
 Performs a deep copy of a type graph from one arena to another.
 
c23_nodiscard infix_status _infix_resolve_type_graph (infix_type **, infix_registry_t *)
 Walks a type graph, replacing all @Name placeholders with their concrete definitions from a registry.
 
c23_nodiscard infix_status _infix_parse_type_internal (infix_type **, infix_arena_t **, const char *, infix_registry_t *)
 The core, non-resolving entry point for the signature parser.
 
const infix_forward_abi_specget_current_forward_abi_spec (void)
 Gets the ABI v-table for the current target platform (forward calls).
 
const infix_reverse_abi_specget_current_reverse_abi_spec (void)
 Gets the ABI v-table for the current target platform (reverse calls).
 
void code_buffer_init (code_buffer *, infix_arena_t *)
 Initializes a code buffer for JIT code generation.
 
void code_buffer_append (code_buffer *, const void *, size_t)
 Appends raw bytes to a code buffer, reallocating if necessary.
 
void emit_byte (code_buffer *, uint8_t)
 Appends a single byte to a code buffer.
 
void emit_int32 (code_buffer *, int32_t)
 Appends a 32-bit integer to a code buffer.
 
void emit_int64 (code_buffer *, int64_t)
 Appends a 64-bit integer to a code buffer.
 
c23_nodiscard infix_status _infix_forward_create_internal (infix_forward_t **, infix_type *, infix_type **, size_t, size_t, infix_arena_t *, void *)
 The internal core logic for creating a forward trampoline.
 
c23_nodiscard infix_executable_t infix_executable_alloc (size_t)
 Allocates a page-aligned block of W^X-compliant executable memory.
 
void infix_executable_free (infix_executable_t)
 Frees executable memory, creating a guard page to prevent use-after-free.
 
c23_nodiscard bool infix_executable_make_executable (infix_executable_t)
 Makes a JIT memory region readable and executable (and non-writable).
 
c23_nodiscard infix_protected_t infix_protected_alloc (size_t)
 Allocates a page-aligned block of data memory.
 
void infix_protected_free (infix_protected_t)
 Frees a block of protected data memory.
 
c23_nodiscard bool infix_protected_make_readonly (infix_protected_t)
 Hardens a block of protected data memory to be read-only.
 
void infix_internal_dispatch_callback_fn_impl (infix_reverse_t *, void *, void **)
 The high-level C dispatcher function called by reverse trampoline stubs.
 
static size_t _infix_align_up (size_t value, size_t alignment)
 
static bool is_float (const infix_type *type)
 Convenience helper to check if an infix_type is a float.
 
static bool is_double (const infix_type *type)
 Convenience helper to check if an infix_type is a double.
 
static bool is_long_double (const infix_type *type)
 Convenience helper to check if an infix_type is a longdouble.
 

Detailed Description

Declarations for internal-only functions, types, and constants.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

Macro Definition Documentation

◆ EMIT_BYTES

#define EMIT_BYTES (   buf,
  ... 
)
Value:
do { \
const uint8_t bytes[] = {__VA_ARGS__}; \
code_buffer_append((buf), bytes, sizeof(bytes)); \
} while (0)

A macro for emitting a sequence of literal bytes into a code buffer.

◆ INFIX_MAX_ARG_SIZE

#define INFIX_MAX_ARG_SIZE   (1024 * 64)

◆ INFIX_MAX_STACK_ALLOC

#define INFIX_MAX_STACK_ALLOC   (1024 * 1024 * 4)

Typedef Documentation

◆ _infix_registry_entry_t

◆ infix_internal_dispatch_callback_fn

typedef void(* infix_internal_dispatch_callback_fn) (infix_reverse_t *, void *, void **)

Enumeration Type Documentation

◆ infix_arg_location_type

Enumerator
ARG_LOCATION_GPR 

Argument is passed in a General-Purpose Register.

ARG_LOCATION_XMM 

Argument is passed in an XMM (SSE) register.

ARG_LOCATION_GPR_PAIR 

A struct passed in two GPRs (System V only).

ARG_LOCATION_SSE_SSE_PAIR 

A struct passed in two XMM registers (System V only).

ARG_LOCATION_INTEGER_SSE_PAIR 

A struct split between a GPR and an XMM register (System V only).

ARG_LOCATION_SSE_INTEGER_PAIR 

A struct split between an XMM and a GPR (System V only).

ARG_LOCATION_STACK 

Argument is passed on the stack.

Function Documentation

◆ _copy_type_graph_to_arena()

infix_type * _copy_type_graph_to_arena ( infix_arena_t dest_arena,
const infix_type src_type 
)

Performs a deep copy of a type graph from one arena to another.

◆ _infix_align_up()

static size_t _infix_align_up ( size_t  value,
size_t  alignment 
)
inlinestatic

◆ _infix_clear_error()

void _infix_clear_error ( void  )

Resets the thread-local error state. Called at the start of every public API function.

◆ _infix_forward_create_internal()

c23_nodiscard infix_status _infix_forward_create_internal ( infix_forward_t **  out_trampoline,
infix_type return_type,
infix_type **  arg_types,
size_t  num_args,
size_t  num_fixed_args,
infix_arena_t source_arena,
void *  target_fn 
)

The internal core logic for creating a forward trampoline.

◆ _infix_parse_type_internal()

c23_nodiscard infix_status _infix_parse_type_internal ( infix_type **  out_type,
infix_arena_t **  out_arena,
const char *  signature,
infix_registry_t registry 
)

The core, non-resolving entry point for the signature parser.

◆ _infix_resolve_type_graph()

c23_nodiscard infix_status _infix_resolve_type_graph ( infix_type **  type_ptr,
infix_registry_t registry 
)

Walks a type graph, replacing all @Name placeholders with their concrete definitions from a registry.

◆ _infix_set_error()

void _infix_set_error ( infix_error_category_t  category,
infix_error_code_t  code,
size_t  position 
)

Sets the thread-local error details for a library-internal error.

◆ _infix_set_system_error()

void _infix_set_system_error ( infix_error_category_t  category,
infix_error_code_t  code,
long  system_code,
const char *  msg 
)

Sets the thread-local error details for an error originating from the OS.

◆ code_buffer_append()

void code_buffer_append ( code_buffer buf,
const void *  data,
size_t  len 
)

Appends raw bytes to a code buffer, reallocating if necessary.

◆ code_buffer_init()

void code_buffer_init ( code_buffer buf,
infix_arena_t arena 
)

Initializes a code buffer for JIT code generation.

◆ emit_byte()

void emit_byte ( code_buffer buf,
uint8_t  byte 
)

Appends a single byte to a code buffer.

◆ emit_int32()

void emit_int32 ( code_buffer buf,
int32_t  value 
)

Appends a 32-bit integer to a code buffer.

◆ emit_int64()

void emit_int64 ( code_buffer buf,
int64_t  value 
)

Appends a 64-bit integer to a code buffer.

◆ get_current_forward_abi_spec()

const infix_forward_abi_spec * get_current_forward_abi_spec ( void  )

Gets the ABI v-table for the current target platform (forward calls).

◆ get_current_reverse_abi_spec()

const infix_reverse_abi_spec * get_current_reverse_abi_spec ( void  )

Gets the ABI v-table for the current target platform (reverse calls).

◆ infix_executable_alloc()

c23_nodiscard infix_executable_t infix_executable_alloc ( size_t  size)

Allocates a page-aligned block of W^X-compliant executable memory.

◆ infix_executable_free()

void infix_executable_free ( infix_executable_t  exec)

Frees executable memory, creating a guard page to prevent use-after-free.

◆ infix_executable_make_executable()

c23_nodiscard bool infix_executable_make_executable ( infix_executable_t  exec)

Makes a JIT memory region readable and executable (and non-writable).

◆ infix_internal_dispatch_callback_fn_impl()

void infix_internal_dispatch_callback_fn_impl ( infix_reverse_t context,
void *  return_value_ptr,
void **  args_array 
)

The high-level C dispatcher function called by reverse trampoline stubs.

◆ infix_protected_alloc()

c23_nodiscard infix_protected_t infix_protected_alloc ( size_t  size)

Allocates a page-aligned block of data memory.

◆ infix_protected_free()

void infix_protected_free ( infix_protected_t  prot)

Frees a block of protected data memory.

◆ infix_protected_make_readonly()

c23_nodiscard bool infix_protected_make_readonly ( infix_protected_t  prot)

Hardens a block of protected data memory to be read-only.

◆ is_double()

static bool is_double ( const infix_type type)
inlinestatic

Convenience helper to check if an infix_type is a double.

◆ is_float()

static bool is_float ( const infix_type type)
inlinestatic

Convenience helper to check if an infix_type is a float.

◆ is_long_double()

static bool is_long_double ( const infix_type type)
inlinestatic

Convenience helper to check if an infix_type is a longdouble.