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

Implements the FFI logic for the Windows x64 calling convention. More...

#include "arch/x64/abi_x64_common.h"
#include "arch/x64/abi_x64_emitters.h"
#include "common/infix_internals.h"
#include "common/utility.h"
#include <stdbool.h>
#include <stdlib.h>
Include dependency graph for abi_win_x64.c:

Macros

#define NUM_GPR_ARGS   4
 
#define NUM_XMM_ARGS   4
 
#define SHADOW_SPACE   32
 

Functions

static infix_status prepare_forward_call_frame_win_x64 (infix_arena_t *arena, infix_call_frame_layout **out_layout, infix_type *ret_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args, void *target_fn)
 The v-table of Windows x64 functions for generating forward trampolines.
 
static infix_status generate_forward_prologue_win_x64 (code_buffer *buf, infix_call_frame_layout *layout)
 
static infix_status generate_forward_argument_moves_win_x64 (code_buffer *buf, infix_call_frame_layout *layout, infix_type **arg_types, size_t num_args, size_t num_fixed_args)
 
static infix_status generate_forward_call_instruction_win_x64 (code_buffer *, infix_call_frame_layout *)
 
static infix_status generate_forward_epilogue_win_x64 (code_buffer *buf, infix_call_frame_layout *layout, infix_type *ret_type)
 
static infix_status prepare_reverse_call_frame_win_x64 (infix_arena_t *arena, infix_reverse_call_frame_layout **out_layout, infix_reverse_t *context)
 The v-table of Windows x64 functions for generating reverse trampolines.
 
static infix_status generate_reverse_prologue_win_x64 (code_buffer *buf, infix_reverse_call_frame_layout *layout)
 
static infix_status generate_reverse_argument_marshalling_win_x64 (code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
 
static infix_status generate_reverse_dispatcher_call_win_x64 (code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
 
static infix_status generate_reverse_epilogue_win_x64 (code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
 
static infix_status prepare_direct_forward_call_frame_win_x64 (infix_arena_t *arena, infix_direct_call_frame_layout **out_layout, infix_type *ret_type, infix_type **arg_types, size_t num_args, infix_direct_arg_handler_t *handlers, void *target_fn)
 The v-table for the new Direct Marshalling ABI.
 
static infix_status generate_direct_forward_prologue_win_x64 (code_buffer *buf, infix_direct_call_frame_layout *layout)
 
static infix_status generate_direct_forward_argument_moves_win_x64 (code_buffer *buf, infix_direct_call_frame_layout *layout)
 
static infix_status generate_direct_forward_call_instruction_win_x64 (code_buffer *buf, infix_direct_call_frame_layout *layout)
 
static infix_status generate_direct_forward_epilogue_win_x64 (code_buffer *buf, infix_direct_call_frame_layout *layout, infix_type *ret_type)
 
static bool return_value_is_by_reference (const infix_type *type)
 
static bool is_passed_by_reference (const infix_type *type)
 
static infix_status generate_forward_call_instruction_win_x64 (code_buffer *buf, c23_maybe_unused infix_call_frame_layout *layout)
 

Variables

static const x64_gpr GPR_ARGS [] = {RCX_REG, RDX_REG, R8_REG, R9_REG}
 
static const x64_xmm XMM_ARGS [] = {XMM0_REG, XMM1_REG, XMM2_REG, XMM3_REG}
 
const infix_forward_abi_spec g_win_x64_forward_spec
 
const infix_reverse_abi_spec g_win_x64_reverse_spec
 
const infix_direct_forward_abi_spec g_win_x64_direct_forward_spec
 

Detailed Description

Implements the FFI logic for the Windows x64 calling convention.

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

◆ NUM_GPR_ARGS

#define NUM_GPR_ARGS   4

The number of register "slots" available for arguments.

◆ NUM_XMM_ARGS

#define NUM_XMM_ARGS   4

The number of XMM registers used for arguments.

◆ SHADOW_SPACE

#define SHADOW_SPACE   32

The size in bytes of the mandatory stack space reserved by the caller for the callee.

Function Documentation

◆ generate_direct_forward_argument_moves_win_x64()

static infix_status generate_direct_forward_argument_moves_win_x64 ( code_buffer buf,
infix_direct_call_frame_layout layout 
)
static

◆ generate_direct_forward_call_instruction_win_x64()

static infix_status generate_direct_forward_call_instruction_win_x64 ( code_buffer buf,
infix_direct_call_frame_layout layout 
)
static

◆ generate_direct_forward_epilogue_win_x64()

static infix_status generate_direct_forward_epilogue_win_x64 ( code_buffer buf,
infix_direct_call_frame_layout layout,
infix_type ret_type 
)
static

◆ generate_direct_forward_prologue_win_x64()

static infix_status generate_direct_forward_prologue_win_x64 ( code_buffer buf,
infix_direct_call_frame_layout layout 
)
static

◆ generate_forward_argument_moves_win_x64()

static infix_status generate_forward_argument_moves_win_x64 ( code_buffer buf,
infix_call_frame_layout layout,
infix_type **  arg_types,
size_t  num_args,
size_t  num_fixed_args 
)
static

◆ generate_forward_call_instruction_win_x64() [1/2]

static infix_status generate_forward_call_instruction_win_x64 ( code_buffer ,
infix_call_frame_layout  
)
static

◆ generate_forward_call_instruction_win_x64() [2/2]

static infix_status generate_forward_call_instruction_win_x64 ( code_buffer buf,
c23_maybe_unused infix_call_frame_layout layout 
)
static

◆ generate_forward_epilogue_win_x64()

static infix_status generate_forward_epilogue_win_x64 ( code_buffer buf,
infix_call_frame_layout layout,
infix_type ret_type 
)
static

◆ generate_forward_prologue_win_x64()

static infix_status generate_forward_prologue_win_x64 ( code_buffer buf,
infix_call_frame_layout layout 
)
static

◆ generate_reverse_argument_marshalling_win_x64()

static infix_status generate_reverse_argument_marshalling_win_x64 ( code_buffer buf,
infix_reverse_call_frame_layout layout,
infix_reverse_t context 
)
static

◆ generate_reverse_dispatcher_call_win_x64()

static infix_status generate_reverse_dispatcher_call_win_x64 ( code_buffer buf,
infix_reverse_call_frame_layout layout,
infix_reverse_t context 
)
static

◆ generate_reverse_epilogue_win_x64()

static infix_status generate_reverse_epilogue_win_x64 ( code_buffer buf,
infix_reverse_call_frame_layout layout,
infix_reverse_t context 
)
static

◆ generate_reverse_prologue_win_x64()

static infix_status generate_reverse_prologue_win_x64 ( code_buffer buf,
infix_reverse_call_frame_layout layout 
)
static

◆ is_passed_by_reference()

static bool is_passed_by_reference ( const infix_type type)
static

◆ prepare_direct_forward_call_frame_win_x64()

static infix_status prepare_direct_forward_call_frame_win_x64 ( infix_arena_t arena,
infix_direct_call_frame_layout **  out_layout,
infix_type ret_type,
infix_type **  arg_types,
size_t  num_args,
infix_direct_arg_handler_t handlers,
void *  target_fn 
)
static

The v-table for the new Direct Marshalling ABI.

◆ prepare_forward_call_frame_win_x64()

static infix_status prepare_forward_call_frame_win_x64 ( infix_arena_t arena,
infix_call_frame_layout **  out_layout,
infix_type ret_type,
infix_type **  arg_types,
size_t  num_args,
size_t  num_fixed_args,
void *  target_fn 
)
static

The v-table of Windows x64 functions for generating forward trampolines.

◆ prepare_reverse_call_frame_win_x64()

static infix_status prepare_reverse_call_frame_win_x64 ( infix_arena_t arena,
infix_reverse_call_frame_layout **  out_layout,
infix_reverse_t context 
)
static

The v-table of Windows x64 functions for generating reverse trampolines.

◆ return_value_is_by_reference()

static bool return_value_is_by_reference ( const infix_type type)
static

Variable Documentation

◆ g_win_x64_direct_forward_spec

const infix_direct_forward_abi_spec g_win_x64_direct_forward_spec
Initial value:
= {
.prepare_direct_forward_call_frame = prepare_direct_forward_call_frame_win_x64,
.generate_direct_forward_prologue = generate_direct_forward_prologue_win_x64,
.generate_direct_forward_argument_moves = generate_direct_forward_argument_moves_win_x64,
.generate_direct_forward_call_instruction = generate_direct_forward_call_instruction_win_x64,
.generate_direct_forward_epilogue = generate_direct_forward_epilogue_win_x64}
static infix_status generate_direct_forward_epilogue_win_x64(code_buffer *buf, infix_direct_call_frame_layout *layout, infix_type *ret_type)
Definition abi_win_x64.c:1038
static infix_status generate_direct_forward_prologue_win_x64(code_buffer *buf, infix_direct_call_frame_layout *layout)
Definition abi_win_x64.c:894
static infix_status generate_direct_forward_argument_moves_win_x64(code_buffer *buf, infix_direct_call_frame_layout *layout)
Definition abi_win_x64.c:924
static infix_status prepare_direct_forward_call_frame_win_x64(infix_arena_t *arena, infix_direct_call_frame_layout **out_layout, infix_type *ret_type, infix_type **arg_types, size_t num_args, infix_direct_arg_handler_t *handlers, void *target_fn)
The v-table for the new Direct Marshalling ABI.
Definition abi_win_x64.c:780
static infix_status generate_direct_forward_call_instruction_win_x64(code_buffer *buf, infix_direct_call_frame_layout *layout)
Definition abi_win_x64.c:1024

◆ g_win_x64_forward_spec

const infix_forward_abi_spec g_win_x64_forward_spec
Initial value:
= {
.prepare_forward_call_frame = prepare_forward_call_frame_win_x64,
.generate_forward_prologue = generate_forward_prologue_win_x64,
.generate_forward_argument_moves = generate_forward_argument_moves_win_x64,
.generate_forward_call_instruction = generate_forward_call_instruction_win_x64,
.generate_forward_epilogue = generate_forward_epilogue_win_x64}
static infix_status generate_forward_prologue_win_x64(code_buffer *buf, infix_call_frame_layout *layout)
Definition abi_win_x64.c:280
static infix_status generate_forward_argument_moves_win_x64(code_buffer *buf, infix_call_frame_layout *layout, infix_type **arg_types, size_t num_args, size_t num_fixed_args)
Definition abi_win_x64.c:323
static infix_status generate_forward_call_instruction_win_x64(code_buffer *, infix_call_frame_layout *)
static infix_status prepare_forward_call_frame_win_x64(infix_arena_t *arena, infix_call_frame_layout **out_layout, infix_type *ret_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args, void *target_fn)
The v-table of Windows x64 functions for generating forward trampolines.
Definition abi_win_x64.c:188
static infix_status generate_forward_epilogue_win_x64(code_buffer *buf, infix_call_frame_layout *layout, infix_type *ret_type)
Definition abi_win_x64.c:448

◆ g_win_x64_reverse_spec

const infix_reverse_abi_spec g_win_x64_reverse_spec
Initial value:
= {
.prepare_reverse_call_frame = prepare_reverse_call_frame_win_x64,
.generate_reverse_prologue = generate_reverse_prologue_win_x64,
.generate_reverse_argument_marshalling = generate_reverse_argument_marshalling_win_x64,
.generate_reverse_dispatcher_call = generate_reverse_dispatcher_call_win_x64,
.generate_reverse_epilogue = generate_reverse_epilogue_win_x64}
static infix_status prepare_reverse_call_frame_win_x64(infix_arena_t *arena, infix_reverse_call_frame_layout **out_layout, infix_reverse_t *context)
The v-table of Windows x64 functions for generating reverse trampolines.
Definition abi_win_x64.c:508
static infix_status generate_reverse_epilogue_win_x64(code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
Definition abi_win_x64.c:737
static infix_status generate_reverse_prologue_win_x64(code_buffer *buf, infix_reverse_call_frame_layout *layout)
Definition abi_win_x64.c:573
static infix_status generate_reverse_dispatcher_call_win_x64(code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
Definition abi_win_x64.c:691
static infix_status generate_reverse_argument_marshalling_win_x64(code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
Definition abi_win_x64.c:611

◆ GPR_ARGS

const x64_gpr GPR_ARGS[] = {RCX_REG, RDX_REG, R8_REG, R9_REG}
static

An array of GPRs used for passing the first four integer/pointer arguments.

◆ XMM_ARGS

const x64_xmm XMM_ARGS[] = {XMM0_REG, XMM1_REG, XMM2_REG, XMM3_REG}
static

An array of XMM registers used for passing the first four floating-point arguments.