infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
trampoline.c
Go to the documentation of this file.
1
39#include "common/utility.h"
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#if defined(INFIX_OS_MACOS)
44#include <pthread.h>
45#endif
46#if defined(INFIX_OS_WINDOWS)
47#include <windows.h>
48#else
49#include <sys/mman.h>
50#include <unistd.h>
51#endif
52// Forward Declaration for Internal Creation Function
56 size_t num_args,
57 size_t num_fixed_args,
58 void * user_callback_fn,
59 void * user_data,
60 bool is_callback);
61// ABI Specification V-Table Declarations (extern to link to the specific implementations)
62#if defined(INFIX_ABI_WINDOWS_X64)
66#elif defined(INFIX_ABI_SYSV_X64)
70#elif defined(INFIX_ABI_AAPCS64)
74#endif
85#if defined(INFIX_ABI_WINDOWS_X64)
87#elif defined(INFIX_ABI_SYSV_X64)
89#elif defined(INFIX_ABI_AAPCS64)
91#else
92 return nullptr;
93#endif
94}
102#if defined(INFIX_ABI_WINDOWS_X64)
104#elif defined(INFIX_ABI_SYSV_X64)
106#elif defined(INFIX_ABI_AAPCS64)
107 return &g_arm64_reverse_spec;
108#else
109 return nullptr;
110#endif
111}
118#if defined(INFIX_ABI_WINDOWS_X64)
120#elif defined(INFIX_ABI_SYSV_X64)
122#elif defined(INFIX_ABI_AAPCS64)
124#else
125 return nullptr;
126#endif
127}
128// Code Buffer Implementation
136 buf->capacity = 64; // Start with a small initial capacity.
137 buf->arena = arena;
138 buf->code = infix_arena_alloc(arena, buf->capacity, 16);
139 buf->size = 0;
140 buf->error = (buf->code == nullptr);
141}
154void code_buffer_append(code_buffer * buf, const void * data, size_t len) {
155 if (buf->error)
156 return;
157 if (len > SIZE_MAX - buf->size) { // Overflow check
158 buf->error = true;
160 return;
161 }
162 if (buf->size + len > buf->capacity) {
163 size_t new_capacity = buf->capacity;
164 while (new_capacity < buf->size + len) {
165 if (new_capacity > SIZE_MAX / 2) { // Overflow check
166 buf->error = true;
168 return;
169 }
170 new_capacity *= 2;
171 }
172 void * new_code = infix_arena_alloc(buf->arena, new_capacity, 16);
173 if (new_code == nullptr) {
174 buf->error = true;
175 // infix_arena_alloc already sets INFIX_CODE_OUT_OF_MEMORY, so we don't need to override it here
176 return;
177 }
178 infix_memcpy(new_code, buf->code, buf->size);
179 buf->code = new_code;
180 buf->capacity = new_capacity;
181 }
182 infix_memcpy(buf->code + buf->size, data, len);
183 buf->size += len;
184}
186void emit_byte(code_buffer * buf, uint8_t byte) { code_buffer_append(buf, &byte, 1); }
188void emit_int32(code_buffer * buf, int32_t value) { code_buffer_append(buf, &value, 4); }
190void emit_int64(code_buffer * buf, int64_t value) { code_buffer_append(buf, &value, 8); }
191// Type Graph Validation
210 if (!type)
211 return true;
212 if (type->is_incomplete)
213 return false;
214 // Cycle detection: if we've seen this node before, we can assume it's resolved
215 // for the purpose of this check, as we'll validate it on the first visit.
216 for (visited_node_t * v = visited_head; v != NULL; v = v->next)
217 if (v->type == type)
218 return true;
219 visited_node_t current_visited_node = {.type = type, .next = visited_head};
220 switch (type->category) {
222 return false; // Base case: an unresolved reference.
225 case INFIX_TYPE_ARRAY:
226 return _is_type_graph_resolved_recursive(type->meta.array_info.element_type, &current_visited_node);
228 case INFIX_TYPE_UNION:
229 for (size_t i = 0; i < type->meta.aggregate_info.num_members; ++i)
230 if (!_is_type_graph_resolved_recursive(type->meta.aggregate_info.members[i].type, &current_visited_node))
231 return false;
232 return true;
235 return false;
236 for (size_t i = 0; i < type->meta.func_ptr_info.num_args; ++i)
237 if (!_is_type_graph_resolved_recursive(type->meta.func_ptr_info.args[i].type, &current_visited_node))
238 return false;
239 return true;
240 default:
241 return true; // Primitives, void, etc., are always resolved.
242 }
243}
263static size_t _estimate_metadata_size(infix_arena_t * temp_arena,
266 size_t num_args) {
267 size_t total_size = 0;
268 total_size += _infix_estimate_graph_size(temp_arena, return_type);
269 if (arg_types != nullptr) {
270 // Add space for the arg_types pointer array itself.
271 total_size += sizeof(infix_type *) * num_args;
272 for (size_t i = 0; i < num_args; ++i)
273 total_size += _infix_estimate_graph_size(temp_arena, arg_types[i]);
274 }
275 return total_size;
276}
277// Forward Trampoline API Implementation
279 if (trampoline == nullptr || trampoline->is_direct_trampoline || trampoline->target_fn != nullptr)
280 return nullptr;
281 return (infix_unbound_cif_func)trampoline->exec.rx_ptr;
282}
284 if (trampoline == nullptr || trampoline->is_direct_trampoline || trampoline->target_fn == nullptr)
285 return nullptr;
286 return (infix_cif_func)trampoline->exec.rx_ptr;
287}
289 if (trampoline == nullptr || !trampoline->is_direct_trampoline)
290 return nullptr;
291 return (infix_direct_cif_func)trampoline->exec.rx_ptr;
292}
317 infix_arena_t * target_arena,
320 size_t num_args,
321 size_t num_fixed_args,
322 void * target_fn) {
323 if (out_trampoline == nullptr || return_type == nullptr || (arg_types == nullptr && num_args > 0)) {
326 }
327 // Pre-flight check: ensure all types are resolved before passing to ABI layer.
331 }
332 for (size_t i = 0; i < num_args; ++i) {
333 if (arg_types[i] == nullptr || !_is_type_graph_resolved(arg_types[i])) {
336 }
337 }
339 if (spec == nullptr) {
342 }
344 infix_call_frame_layout * layout = nullptr;
345 infix_forward_t * handle = nullptr;
346 // Use a temporary arena for all intermediate allocations during code generation.
347 infix_arena_t * temp_arena = infix_arena_create(65536);
348 if (!temp_arena) {
351 }
352 code_buffer buf;
353 code_buffer_init(&buf, temp_arena);
354 // JIT Compilation Pipeline
355 // 1. Prepare: Classify arguments and create the layout blueprint.
357 temp_arena, &layout, return_type, arg_types, num_args, num_fixed_args, target_fn);
358 if (status != INFIX_SUCCESS)
359 goto cleanup;
360 // 2. Generate: Emit machine code based on the layout.
361 status = spec->generate_forward_prologue(&buf, layout);
362 if (status != INFIX_SUCCESS)
363 goto cleanup;
364 status = spec->generate_forward_argument_moves(&buf, layout, arg_types, num_args, num_fixed_args);
365 if (status != INFIX_SUCCESS)
366 goto cleanup;
367 status = spec->generate_forward_call_instruction(&buf, layout);
368 if (status != INFIX_SUCCESS)
369 goto cleanup;
370 status = spec->generate_forward_epilogue(&buf, layout, return_type);
371 if (status != INFIX_SUCCESS)
372 goto cleanup;
373 if (buf.error || temp_arena->error) {
375 goto cleanup;
376 }
377 // Finalize Handle
378 handle = infix_calloc(1, sizeof(infix_forward_t));
379 if (handle == nullptr) {
381 goto cleanup;
382 }
383 // "Estimate" stage: Calculate the exact size needed for the handle's private arena.
384 size_t required_metadata_size = _estimate_metadata_size(temp_arena, return_type, arg_types, num_args);
385 if (target_arena) {
386 handle->arena = target_arena;
387 handle->is_external_arena = true;
388 }
389 else {
390 handle->arena = infix_arena_create(required_metadata_size + INFIX_TRAMPOLINE_HEADROOM);
391 handle->is_external_arena = false;
392 }
393 if (handle->arena == nullptr) {
395 goto cleanup;
396 }
397 // "Copy" stage: Deep copy all type info into the handle's private arena.
399 if (num_args > 0) {
400 handle->arg_types = infix_arena_alloc(handle->arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *));
401 if (handle->arg_types == nullptr) {
403 goto cleanup;
404 }
405 for (size_t i = 0; i < num_args; ++i) {
406 handle->arg_types[i] = _copy_type_graph_to_arena(handle->arena, arg_types[i]);
407 // Check for allocation failure during copy
408 if (arg_types[i] != nullptr && handle->arg_types[i] == nullptr && !handle->arena->error) {
410 goto cleanup;
411 }
412 }
413 }
414 handle->num_args = num_args;
415 handle->num_fixed_args = num_fixed_args;
416 handle->target_fn = target_fn;
417 // Allocate and finalize executable memory.
418 handle->exec = infix_executable_alloc(buf.size);
419 if (handle->exec.rw_ptr == nullptr) {
421 goto cleanup;
422 }
423 infix_memcpy(handle->exec.rw_ptr, buf.code, buf.size);
424 if (!infix_executable_make_executable(&handle->exec)) {
426 goto cleanup;
427 }
428 infix_dump_hex(handle->exec.rx_ptr, handle->exec.size, "Forward Trampoline Machine Code");
429 *out_trampoline = handle;
430cleanup:
431 // If any step failed, ensure the partially created handle is fully destroyed.
432 if (status != INFIX_SUCCESS && handle != nullptr)
433 infix_forward_destroy(handle);
434 // The temporary arena is always destroyed.
435 infix_arena_destroy(temp_arena);
436 return status;
437}
466 size_t num_args,
467 void * target_fn,
469 // 1. Validation and Setup
470 if (!out_trampoline || !return_type || (!arg_types && num_args > 0) || !target_fn || !handlers) {
473 }
474
476 if (spec == nullptr) {
479 }
480
482 infix_direct_call_frame_layout * layout = nullptr;
483 infix_forward_t * handle = nullptr;
484 infix_arena_t * temp_arena = infix_arena_create(65536);
485 if (!temp_arena) {
488 }
489 code_buffer buf;
490 code_buffer_init(&buf, temp_arena);
491
492 // 2. JIT Compilation Pipeline
494 temp_arena, &layout, return_type, arg_types, num_args, handlers, target_fn);
495 if (status != INFIX_SUCCESS)
496 goto cleanup;
497
498 status = spec->generate_direct_forward_prologue(&buf, layout);
499 if (status != INFIX_SUCCESS)
500 goto cleanup;
501
503 if (status != INFIX_SUCCESS)
504 goto cleanup;
505
507 if (status != INFIX_SUCCESS)
508 goto cleanup;
509
511 if (status != INFIX_SUCCESS)
512 goto cleanup;
513
514 if (buf.error || temp_arena->error) {
516 goto cleanup;
517 }
518
519 // 3. Finalize Handle
520 handle = infix_calloc(1, sizeof(infix_forward_t));
521 if (handle == nullptr) {
523 goto cleanup;
524 }
525
526 handle->is_direct_trampoline = true; // Mark this as a direct marshalling trampoline.
527
528 size_t required_metadata_size = _estimate_metadata_size(temp_arena, return_type, arg_types, num_args);
529 handle->arena = infix_arena_create(required_metadata_size + INFIX_TRAMPOLINE_HEADROOM);
530 handle->is_external_arena = false;
531 if (handle->arena == nullptr) {
533 goto cleanup;
534 }
535
537 if (num_args > 0) {
538 handle->arg_types = infix_arena_alloc(handle->arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *));
539 if (!handle->arg_types) {
541 goto cleanup;
542 }
543 for (size_t i = 0; i < num_args; ++i) {
544 handle->arg_types[i] = _copy_type_graph_to_arena(handle->arena, arg_types[i]);
545 if (arg_types[i] && !handle->arg_types[i] && !handle->arena->error) {
547 goto cleanup;
548 }
549 }
550 }
551 handle->num_args = num_args;
552 handle->num_fixed_args = num_args; // Direct trampolines are always fixed-arity.
553 handle->target_fn = target_fn;
554
555 // 4. Allocate and Finalize Executable Memory
556 handle->exec = infix_executable_alloc(buf.size);
557 if (handle->exec.rw_ptr == nullptr) {
559 goto cleanup;
560 }
561 infix_memcpy(handle->exec.rw_ptr, buf.code, buf.size);
562 if (!infix_executable_make_executable(&handle->exec)) {
564 goto cleanup;
565 }
566
567 infix_dump_hex(handle->exec.rx_ptr, handle->exec.size, "Direct-Marshalling Forward Trampoline Machine Code");
568 *out_trampoline = handle;
569
570cleanup:
571 if (status != INFIX_SUCCESS && handle != nullptr)
572 infix_forward_destroy(handle);
573 infix_arena_destroy(temp_arena);
574 return status;
575}
597 size_t num_args,
598 size_t num_fixed_args,
599 void * target_function) {
600 // This is part of the "Manual API". It calls the internal implementation directly
601 // without involving the signature parser. `source_arena` is null because the
602 // types are assumed to be managed by the user.
605 out_trampoline, nullptr, return_type, arg_types, num_args, num_fixed_args, target_function);
606}
623 size_t num_args,
624 size_t num_fixed_args) {
627 out_trampoline, nullptr, return_type, arg_types, num_args, num_fixed_args, nullptr);
628}
637 if (trampoline == nullptr)
638 return;
639 // Destroying the private arena frees all deep-copied type metadata.
640 if (trampoline->arena && !trampoline->is_external_arena)
641 infix_arena_destroy(trampoline->arena);
642 // Free the JIT-compiled executable code.
643 infix_executable_free(trampoline->exec);
644 // Free the handle struct itself.
645 infix_free(trampoline);
646}
647// Reverse Trampoline API Implementation
653static size_t get_page_size() {
654#if defined(INFIX_OS_WINDOWS)
655 SYSTEM_INFO sysInfo;
656 GetSystemInfo(&sysInfo);
657 return sysInfo.dwPageSize;
658#else
659 // sysconf is the standard POSIX way to get system configuration values.
660 return sysconf(_SC_PAGESIZE);
661#endif
662}
689 size_t num_args,
690 size_t num_fixed_args,
691 void * user_callback_fn,
692 void * user_data,
693 bool is_callback) {
694 if (out_context == nullptr || return_type == nullptr || num_fixed_args > num_args) {
697 }
698 // Pre-flight check: ensure all types are fully resolved.
702 }
703 if (arg_types == nullptr && num_args > 0) {
706 }
707 for (size_t i = 0; i < num_args; ++i) {
708 if (arg_types[i] == nullptr || !_is_type_graph_resolved(arg_types[i])) {
711 }
712 }
714 if (spec == nullptr) {
717 }
719 infix_reverse_call_frame_layout * layout = nullptr;
720 infix_reverse_t * context = nullptr;
721 infix_arena_t * temp_arena = nullptr;
722 infix_protected_t prot = {.rw_ptr = nullptr, .size = 0};
723 code_buffer buf;
724 temp_arena = infix_arena_create(65536);
725 if (!temp_arena) {
728 }
729 code_buffer_init(&buf, temp_arena);
730 // Security Hardening: Allocate the context struct itself in special, page-aligned
731 // memory that can be made read-only after initialization.
732 size_t page_size = get_page_size();
733 size_t context_alloc_size = (sizeof(infix_reverse_t) + page_size - 1) & ~(page_size - 1);
734 prot = infix_protected_alloc(context_alloc_size);
735 if (prot.rw_ptr == nullptr) {
737 goto cleanup;
738 }
739 context = (infix_reverse_t *)prot.rw_ptr;
740 infix_memset(context, 0, context_alloc_size);
741 // "Estimate" stage: Calculate the exact size needed for the context's private arena.
742 size_t required_metadata_size = _estimate_metadata_size(temp_arena, return_type, arg_types, num_args);
743 // Create the context's private arena with the calculated size plus some headroom for safety.
744 context->arena = infix_arena_create(required_metadata_size + INFIX_TRAMPOLINE_HEADROOM);
745 if (context->arena == nullptr) {
747 goto cleanup;
748 }
749 // Populate the context fields.
750 context->protected_ctx = prot;
751 context->num_args = num_args;
752 context->num_fixed_args = num_fixed_args;
753 context->is_variadic = (num_fixed_args < num_args);
754 context->user_callback_fn = user_callback_fn;
755 context->user_data = user_data;
757 context->cached_forward_trampoline = nullptr;
758 // "Copy" stage: deep copy all types into the context's private arena.
760 if (num_args > 0) {
761 context->arg_types = infix_arena_alloc(context->arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *));
762 if (context->arg_types == nullptr) {
764 goto cleanup;
765 }
766 for (size_t i = 0; i < num_args; ++i) {
767 context->arg_types[i] = _copy_type_graph_to_arena(context->arena, arg_types[i]);
768 if (arg_types[i] != nullptr && context->arg_types[i] == nullptr) {
770 goto cleanup;
771 }
772 }
773 }
774 // Special step for type-safe callbacks: generate and cache a forward trampoline
775 // that will be used to call the user's type-safe C handler.
776 if (is_callback) {
778 context->return_type,
779 context->arg_types,
780 context->num_args,
781 context->num_fixed_args,
782 user_callback_fn);
783 if (status != INFIX_SUCCESS)
784 goto cleanup;
785 }
786 // JIT Compilation Pipeline for Reverse Stub
787 status = spec->prepare_reverse_call_frame(temp_arena, &layout, context);
788 if (status != INFIX_SUCCESS)
789 goto cleanup;
790 status = spec->generate_reverse_prologue(&buf, layout);
791 if (status != INFIX_SUCCESS)
792 goto cleanup;
793 status = spec->generate_reverse_argument_marshalling(&buf, layout, context);
794 if (status != INFIX_SUCCESS)
795 goto cleanup;
796 status = spec->generate_reverse_dispatcher_call(&buf, layout, context);
797 if (status != INFIX_SUCCESS)
798 goto cleanup;
799 status = spec->generate_reverse_epilogue(&buf, layout, context);
800 if (status != INFIX_SUCCESS)
801 goto cleanup;
802 // End of Pipeline
803 if (buf.error || temp_arena->error) {
805 goto cleanup;
806 }
807 context->exec = infix_executable_alloc(buf.size);
808 if (context->exec.rw_ptr == nullptr) {
810 goto cleanup;
811 }
812 infix_memcpy(context->exec.rw_ptr, buf.code, buf.size);
813 if (!infix_executable_make_executable(&context->exec)) {
815 goto cleanup;
816 }
817 // Security Hardening: Make the context memory read-only to prevent runtime corruption.
820 goto cleanup;
821 }
822 infix_dump_hex(context->exec.rx_ptr, buf.size, "Reverse Trampoline Machine Code");
823 *out_context = context;
824cleanup:
825 if (status != INFIX_SUCCESS) {
826 // If allocation of the context itself failed, prot.rw_ptr will be null.
827 if (prot.rw_ptr != nullptr)
828 infix_reverse_destroy(context);
829 }
830 infix_arena_destroy(temp_arena);
831 return status;
832}
846 size_t num_args,
847 size_t num_fixed_args,
848 void * user_callback_fn) {
849
852 out_context, return_type, arg_types, num_args, num_fixed_args, user_callback_fn, nullptr, true);
853}
868 size_t num_args,
869 size_t num_fixed_args,
870 infix_closure_handler_fn user_callback_fn,
871 void * user_data) {
872
875 out_context, return_type, arg_types, num_args, num_fixed_args, (void *)user_callback_fn, user_data, false);
876}
885 if (reverse_trampoline == nullptr)
886 return;
887 // The cached trampoline (if it exists) must also be destroyed.
888 if (reverse_trampoline->cached_forward_trampoline)
890 if (reverse_trampoline->arena)
891 infix_arena_destroy(reverse_trampoline->arena);
892 infix_executable_free(reverse_trampoline->exec);
893 // Free the special read-only memory region for the context struct.
894 infix_protected_free(reverse_trampoline->protected_ctx);
895}
903 if (reverse_trampoline == nullptr)
904 return nullptr;
905 return reverse_trampoline->exec.rx_ptr;
906}
913 if (reverse_trampoline == nullptr)
914 return nullptr;
915 return reverse_trampoline->user_data;
916}
917// High-Level Signature API Wrappers
919 infix_arena_t * target_arena,
920 const char * signature,
921 void * target_function,
924 if (!signature) {
927 }
928 infix_arena_t * arena = nullptr;
929 infix_type * ret_type = nullptr;
930 infix_function_argument * args = nullptr;
931 size_t num_args = 0, num_fixed = 0;
932 infix_type ** arg_types = nullptr;
934 if (signature[0] == '@') {
935 if (registry == nullptr) {
937 INFIX_CATEGORY_GENERAL, INFIX_CODE_MISSING_REGISTRY, 0); // Using @Name requires a registry
939 }
940 const infix_type * func_type = infix_registry_lookup_type(registry, &signature[1]);
941 if (func_type == NULL) {
944 }
945 if (func_type->category != INFIX_TYPE_REVERSE_TRAMPOLINE) {
946 // The user provided a name for a non-function type (e.g., "@Point")
949 }
950 // We have a valid function type from the registry. Now, unpack its components.
952 num_args = func_type->meta.func_ptr_info.num_args;
953 num_fixed = func_type->meta.func_ptr_info.num_fixed_args;
954 args = func_type->meta.func_ptr_info.args;
955 // The Manual API needs a temporary arena to hold the arg_types array.
956 infix_arena_t * temp_arena = infix_arena_create(sizeof(infix_type *) * num_args + 128);
957 if (!temp_arena) {
960 }
961 if (num_args > 0) {
962 arg_types = infix_arena_alloc(temp_arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *));
963 if (!arg_types) {
964 infix_arena_destroy(temp_arena);
967 }
968 for (size_t i = 0; i < num_args; ++i)
969 arg_types[i] = args[i].type;
970 }
971 arena = temp_arena;
972 }
973 else {
974 // This is a high-level wrapper. It uses the parser to build the type info first.
975 status = infix_signature_parse(signature, &arena, &ret_type, &args, &num_args, &num_fixed, registry);
976 if (status != INFIX_SUCCESS) {
978 return status;
979 }
980 // Extract the `infix_type*` array from the parsed `infix_function_argument` array.
981 arg_types = (num_args > 0) ? infix_arena_alloc(arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *))
982 : nullptr;
983 if (num_args > 0 && !arg_types) {
987 }
988 for (size_t i = 0; i < num_args; ++i)
989 arg_types[i] = args[i].type;
990 }
991 // Call the core internal implementation with the parsed types.
993 out_trampoline, target_arena, ret_type, arg_types, num_args, num_fixed, target_function);
995 return status;
996}
998 const char * signature,
999 void * target_function,
1001 return infix_forward_create_in_arena(out_trampoline, NULL, signature, target_function, registry);
1002}
1004 const char * signature,
1006 return infix_forward_create_in_arena(out_trampoline, NULL, signature, NULL, registry);
1007}
1009 const char * signature,
1010 void * target_function,
1014 if (!signature || !target_function || !handlers) {
1017 }
1018
1019 infix_arena_t * arena = nullptr;
1020 infix_type * ret_type = nullptr;
1021 infix_function_argument * args = nullptr;
1022 size_t num_args = 0, num_fixed = 0;
1023 infix_type ** arg_types = nullptr;
1024
1025 // Parse the signature to get the type graph.
1026 infix_status status = infix_signature_parse(signature, &arena, &ret_type, &args, &num_args, &num_fixed, registry);
1027 if (status != INFIX_SUCCESS) {
1029 return status;
1030 }
1031
1032 // Convert the parsed `infix_function_argument*` array to an `infix_type**` array.
1033 if (num_args > 0) {
1034 arg_types = infix_arena_alloc(arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *));
1035 if (!arg_types) {
1039 }
1040 for (size_t i = 0; i < num_args; ++i)
1041 arg_types[i] = args[i].type;
1042 }
1043
1044 // Call the core internal implementation with the parsed types and provided handlers.
1045 status =
1046 _infix_forward_create_direct_impl(out_trampoline, ret_type, arg_types, num_args, target_function, handlers);
1047
1048 // Clean up the temporary arena used by the parser.
1050 return status;
1051}
1053 const char * signature,
1054 void * user_callback_fn,
1056 infix_arena_t * arena = nullptr;
1057 infix_type * ret_type = nullptr;
1058 infix_function_argument * args = nullptr;
1059 size_t num_args = 0, num_fixed = 0;
1060 infix_status status = infix_signature_parse(signature, &arena, &ret_type, &args, &num_args, &num_fixed, registry);
1061 if (status != INFIX_SUCCESS) {
1063 return status;
1064 }
1066 (num_args > 0) ? infix_arena_alloc(arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *)) : nullptr;
1067 if (num_args > 0 && !arg_types) {
1071 }
1072 for (size_t i = 0; i < num_args; ++i)
1073 arg_types[i] = args[i].type;
1074 // Call the manual API with the parsed types.
1075 status =
1076 infix_reverse_create_callback_manual(out_context, ret_type, arg_types, num_args, num_fixed, user_callback_fn);
1078 return status;
1079}
1081 const char * signature,
1082 infix_closure_handler_fn user_callback_fn,
1083 void * user_data,
1085 infix_arena_t * arena = nullptr;
1086 infix_type * ret_type = nullptr;
1087 infix_function_argument * args = nullptr;
1088 size_t num_args = 0, num_fixed = 0;
1089 infix_status status = infix_signature_parse(signature, &arena, &ret_type, &args, &num_args, &num_fixed, registry);
1090 if (status != INFIX_SUCCESS) {
1092 return status;
1093 }
1095 (num_args > 0) ? infix_arena_alloc(arena, sizeof(infix_type *) * num_args, _Alignof(infix_type *)) : nullptr;
1096 if (num_args > 0 && !arg_types) {
1100 }
1101 for (size_t i = 0; i < num_args; ++i)
1102 arg_types[i] = args[i].type;
1104 out_context, ret_type, arg_types, num_args, num_fixed, user_callback_fn, user_data);
1106 return status;
1107}
1108// ============================================================================
1109// UNITY BUILD INCLUDES
1110// This section includes the actual ABI implementations at the end of the file.
1111// Because `trampoline.c` is the central translation unit, including the
1112// correct ABI-specific .c file here makes its functions (`g_win_x64_spec`, etc.)
1113// available without needing to add platform-specific logic to the build system.
1114// The `infix_config.h` header ensures only one of these #if blocks is active.
1115// ============================================================================
1116#if defined(INFIX_ABI_WINDOWS_X64)
1117#include "../arch/x64/abi_win_x64.c"
1118#include "../arch/x64/abi_x64_emitters.c"
1119#elif defined(INFIX_ABI_SYSV_X64)
1120#include "../arch/x64/abi_sysv_x64.c"
1121#include "../arch/x64/abi_x64_emitters.c"
1122#elif defined(INFIX_ABI_AAPCS64)
1123#include "../arch/aarch64/abi_arm64.c"
1124#include "../arch/aarch64/abi_arm64_emitters.c"
1125#else
1126#error "No supported ABI was selected for the unity build in trampoline.c."
1127#endif
infix_arena_t * arena
Definition 005_layouts.c:62
infix_registry_t * registry
Definition 008_registry_introspection.c:33
infix_status status
Definition 103_unions.c:61
void * args[]
Definition 202_in_structs.c:59
infix_type * return_type
Definition 202_in_structs.c:55
infix_type * arg_types[]
Definition 901_call_overhead.c:62
infix_type * ret_type
Definition 901_call_overhead.c:61
infix_direct_arg_handler_t handlers[2]
Definition 901_call_overhead.c:104
const infix_reverse_abi_spec g_arm64_reverse_spec
Definition abi_arm64.c:116
const infix_forward_abi_spec g_arm64_forward_spec
Definition abi_arm64.c:95
const infix_direct_forward_abi_spec g_arm64_direct_forward_spec
Definition abi_arm64.c:139
const infix_reverse_abi_spec g_sysv_x64_reverse_spec
Definition abi_sysv_x64.c:113
const infix_direct_forward_abi_spec g_sysv_x64_direct_forward_spec
Definition abi_sysv_x64.c:137
const infix_forward_abi_spec g_sysv_x64_forward_spec
Definition abi_sysv_x64.c:92
const infix_direct_forward_abi_spec g_win_x64_direct_forward_spec
Definition abi_win_x64.c:129
const infix_reverse_abi_spec g_win_x64_reverse_spec
Definition abi_win_x64.c:105
const infix_forward_abi_spec g_win_x64_forward_spec
Definition abi_win_x64.c:85
#define c23_nodiscard
Internal alias for the public INFIX_NODISCARD macro.
Definition compat_c23.h:91
void(* infix_direct_cif_func)(void *, void **)
A function pointer for a direct marshalling forward trampoline.
Definition infix.h:1418
INFIX_API c23_nodiscard infix_direct_cif_func infix_forward_get_direct_code(infix_forward_t *trampoline)
Gets the callable function pointer from a direct marshalling trampoline.
Definition trampoline.c:288
INFIX_API c23_nodiscard infix_status infix_forward_create_direct(infix_forward_t **out_trampoline, const char *signature, void *target_function, infix_direct_arg_handler_t *handlers, infix_registry_t *registry)
Creates a forward trampoline with direct, JIT-bound marshalling.
Definition trampoline.c:1008
@ INFIX_CODE_MISSING_REGISTRY
Definition infix.h:1347
@ INFIX_CODE_UNRESOLVED_NAMED_TYPE
Definition infix.h:1368
@ INFIX_CODE_INTEGER_OVERFLOW
Definition infix.h:1360
@ INFIX_CODE_UNEXPECTED_TOKEN
Definition infix.h:1356
@ INFIX_CODE_UNSUPPORTED_ABI
Definition infix.h:1366
@ INFIX_CODE_NULL_POINTER
Definition infix.h:1346
@ INFIX_CODE_OUT_OF_MEMORY
Definition infix.h:1350
@ INFIX_CATEGORY_ABI
Definition infix.h:1337
@ INFIX_CATEGORY_ALLOCATION
Definition infix.h:1335
@ INFIX_CATEGORY_GENERAL
Definition infix.h:1334
@ INFIX_CATEGORY_PARSER
Definition infix.h:1336
struct infix_type_t::@0::@1 pointer_info
Metadata for INFIX_TYPE_POINTER.
union infix_type_t::@0 meta
A union containing metadata specific to the type's category.
bool is_incomplete
Definition infix.h:279
infix_type * type
Definition infix.h:347
INFIX_API INFIX_NODISCARD infix_status infix_signature_parse(const char *, infix_arena_t **, infix_type **, infix_function_argument **, size_t *, size_t *, infix_registry_t *)
Parses a full function signature string into its constituent parts.
Definition signature.c:1087
struct infix_type_t::@0::@4 func_ptr_info
Metadata for INFIX_TYPE_REVERSE_TRAMPOLINE.
void(* infix_cif_func)(void *, void **)
A function pointer type for a bound forward trampoline.
Definition infix.h:417
void(* infix_unbound_cif_func)(void *, void *, void **)
A function pointer type for an unbound forward trampoline.
Definition infix.h:408
INFIX_API c23_nodiscard infix_status infix_reverse_create_callback(infix_reverse_t **out_context, const char *signature, void *user_callback_fn, infix_registry_t *registry)
Creates a type-safe reverse trampoline (callback).
Definition trampoline.c:1052
infix_struct_member * members
Definition infix.h:292
infix_function_argument * args
Definition infix.h:305
c23_nodiscard infix_status infix_reverse_create_closure(infix_reverse_t **out_context, const char *signature, infix_closure_handler_fn user_callback_fn, void *user_data, infix_registry_t *registry)
Creates a generic reverse trampoline (closure) for stateful callbacks.
Definition trampoline.c:1080
infix_status
Enumerates the possible status codes returned by infix API functions.
Definition infix.h:433
INFIX_API c23_nodiscard infix_status infix_forward_create_in_arena(infix_forward_t **out_trampoline, infix_arena_t *target_arena, const char *signature, void *target_function, infix_registry_t *registry)
Creates a "bound" forward trampoline within a user-provided arena.
Definition trampoline.c:918
infix_type_category category
Definition infix.h:275
struct infix_type_t::@0::@2 aggregate_info
Metadata for INFIX_TYPE_STRUCT and INFIX_TYPE_UNION.
struct infix_type_t::@0::@3 array_info
Metadata for INFIX_TYPE_ARRAY.
struct infix_type_t * pointee_type
Definition infix.h:288
infix_type * type
Definition infix.h:335
struct infix_type_t * element_type
Definition infix.h:298
struct infix_type_t * return_type
Definition infix.h:304
size_t num_members
Definition infix.h:293
size_t num_fixed_args
Definition infix.h:307
INFIX_API c23_nodiscard infix_status infix_forward_create_unbound(infix_forward_t **out_trampoline, const char *signature, infix_registry_t *registry)
Creates an "unbound" forward trampoline from a signature string.
Definition trampoline.c:1003
void(* infix_closure_handler_fn)(infix_context_t *, void *, void **)
A function pointer type for a generic closure handler.
Definition infix.h:429
size_t num_args
Definition infix.h:306
INFIX_API c23_nodiscard infix_status infix_forward_create(infix_forward_t **out_trampoline, const char *signature, void *target_function, infix_registry_t *registry)
Creates a "bound" forward trampoline from a signature string.
Definition trampoline.c:997
@ INFIX_ERROR_ALLOCATION_FAILED
Definition infix.h:435
@ INFIX_ERROR_PROTECTION_FAILED
Definition infix.h:439
@ INFIX_ERROR_UNSUPPORTED_ABI
Definition infix.h:437
@ INFIX_SUCCESS
Definition infix.h:434
@ INFIX_ERROR_INVALID_ARGUMENT
Definition infix.h:436
INFIX_API c23_nodiscard void * infix_reverse_get_code(const infix_reverse_t *reverse_trampoline)
Gets the native, callable C function pointer from a reverse trampoline.
Definition trampoline.c:902
INFIX_API c23_nodiscard infix_unbound_cif_func infix_forward_get_unbound_code(infix_forward_t *trampoline)
Gets the callable function pointer from an unbound forward trampoline.
Definition trampoline.c:278
INFIX_API c23_nodiscard infix_cif_func infix_forward_get_code(infix_forward_t *trampoline)
Gets the callable function pointer from a bound forward trampoline.
Definition trampoline.c:283
INFIX_API c23_nodiscard void * infix_reverse_get_user_data(const infix_reverse_t *reverse_trampoline)
Gets the user-provided data pointer from a closure context.
Definition trampoline.c:912
INFIX_API void infix_reverse_destroy(infix_reverse_t *reverse_trampoline)
Destroys a reverse trampoline and frees all associated memory.
Definition trampoline.c:884
INFIX_API c23_nodiscard infix_status infix_forward_create_manual(infix_forward_t **out_trampoline, infix_type *return_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args, void *target_function)
Creates a bound forward trampoline from infix_type objects (Manual API).
Definition trampoline.c:594
INFIX_API c23_nodiscard infix_status infix_forward_create_unbound_manual(infix_forward_t **out_trampoline, infix_type *return_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args)
Creates an unbound forward trampoline from infix_type objects (Manual API).
Definition trampoline.c:620
INFIX_API c23_nodiscard infix_status infix_reverse_create_closure_manual(infix_reverse_t **out_context, infix_type *return_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args, infix_closure_handler_fn user_callback_fn, void *user_data)
Creates a generic reverse trampoline (closure) from infix_type objects (Manual API).
Definition trampoline.c:865
INFIX_API c23_nodiscard infix_status infix_reverse_create_callback_manual(infix_reverse_t **out_context, infix_type *return_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args, void *user_callback_fn)
Creates a type-safe reverse trampoline (callback) from infix_type objects (Manual API).
Definition trampoline.c:843
INFIX_API void infix_forward_destroy(infix_forward_t *trampoline)
Destroys a forward trampoline and frees all associated memory.
Definition trampoline.c:636
#define infix_free
A macro that can be defined to override the default free function.
Definition infix.h:382
INFIX_API INFIX_NODISCARD void * infix_arena_alloc(infix_arena_t *, size_t, size_t)
Allocates a block of memory from an arena.
Definition arena.c:117
#define infix_memcpy
A macro that can be defined to override the default memcpy function.
Definition infix.h:386
#define infix_calloc
A macro that can be defined to override the default calloc function.
Definition infix.h:374
INFIX_API INFIX_NODISCARD infix_arena_t * infix_arena_create(size_t)
Creates a new memory arena.
Definition arena.c:52
#define infix_memset
A macro that can be defined to override the default memset function.
Definition infix.h:390
INFIX_API void infix_arena_destroy(infix_arena_t *)
Destroys an arena and frees all memory allocated from it.
Definition arena.c:83
INFIX_API INFIX_NODISCARD const infix_type * infix_registry_lookup_type(const infix_registry_t *, const char *)
Retrieves the canonical infix_type object for a given name from the registry.
Definition type_registry.c:888
@ INFIX_TYPE_UNION
Definition infix.h:231
@ INFIX_TYPE_ARRAY
Definition infix.h:232
@ INFIX_TYPE_POINTER
Definition infix.h:229
@ INFIX_TYPE_NAMED_REFERENCE
Definition infix.h:237
@ INFIX_TYPE_REVERSE_TRAMPOLINE
Definition infix.h:233
@ INFIX_TYPE_STRUCT
Definition infix.h:230
#define INFIX_API
Symbol visibility macro.
Definition infix.h:114
#define INFIX_TRAMPOLINE_HEADROOM
Extra bytes to allocate in a trampoline's private arena.
Definition infix_config.h:201
Internal data structures, function prototypes, and constants.
INFIX_INTERNAL void infix_executable_free(infix_executable_t exec)
Frees a block of executable memory and applies guard pages to prevent use-after-free.
Definition executor.c:347
INFIX_INTERNAL c23_nodiscard infix_protected_t infix_protected_alloc(size_t size)
Allocates a block of standard memory for later protection.
Definition executor.c:480
INFIX_INTERNAL void infix_protected_free(infix_protected_t prot)
Frees a block of protected memory.
Definition executor.c:514
INFIX_INTERNAL c23_nodiscard infix_executable_t infix_executable_alloc(size_t size)
Allocates a block of executable memory using the platform's W^X strategy.
Definition executor.c:235
INFIX_INTERNAL infix_type * _copy_type_graph_to_arena(infix_arena_t *, const infix_type *)
Performs a deep copy of a type graph into a destination arena.
Definition types.c:1141
INFIX_INTERNAL size_t _infix_estimate_graph_size(infix_arena_t *temp_arena, const infix_type *type)
Estimates the total memory required to deep-copy a complete type graph.
Definition types.c:1246
INFIX_INTERNAL c23_nodiscard bool infix_protected_make_readonly(infix_protected_t prot)
Makes a block of memory read-only for security hardening.
Definition executor.c:534
INFIX_INTERNAL c23_nodiscard bool infix_executable_make_executable(infix_executable_t *exec)
Makes a block of JIT memory executable, completing the W^X process.
Definition executor.c:399
INFIX_INTERNAL void _infix_clear_error(void)
Clears the thread-local error state.
Definition error.c:266
INFIX_INTERNAL void _infix_set_error(infix_error_category_t category, infix_error_code_t code, size_t position)
Sets the thread-local error state with detailed information.
Definition error.c:173
INFIX_INTERNAL void infix_internal_dispatch_callback_fn_impl(infix_reverse_t *context, void *return_value_ptr, void **args_array)
The universal C entry point for all reverse call trampolines.
Definition executor.c:573
A dynamic buffer for staged machine code generation.
Definition infix_internals.h:180
uint8_t * code
Definition infix_internals.h:181
bool error
Definition infix_internals.h:184
size_t size
Definition infix_internals.h:183
size_t capacity
Definition infix_internals.h:182
infix_arena_t * arena
Definition infix_internals.h:185
Internal definition of a memory arena.
Definition infix_internals.h:138
bool error
Definition infix_internals.h:142
A complete layout blueprint for a forward call frame.
Definition infix_internals.h:269
A struct containing all the necessary handlers for a single function argument.
Definition infix.h:1481
A complete layout blueprint for a direct marshalling forward call frame.
Definition infix_internals.h:452
Defines the ABI-specific implementation interface for direct marshalling forward trampolines.
Definition infix_internals.h:466
infix_status(* generate_direct_forward_call_instruction)(code_buffer *buf, infix_direct_call_frame_layout *layout)
Generates the call instruction to the target function.
Definition infix_internals.h:480
infix_status(* generate_direct_forward_argument_moves)(code_buffer *buf, infix_direct_call_frame_layout *layout)
Generates code to call marshallers and move arguments into their native locations.
Definition infix_internals.h:478
infix_status(* prepare_direct_forward_call_frame)(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)
Analyzes a function signature to create a complete direct call frame layout.
Definition infix_internals.h:468
infix_status(* generate_direct_forward_epilogue)(code_buffer *buf, infix_direct_call_frame_layout *layout, infix_type *ret_type)
Generates the function epilogue (handling return value, calling write-back handlers,...
Definition infix_internals.h:483
infix_status(* generate_direct_forward_prologue)(code_buffer *buf, infix_direct_call_frame_layout *layout)
Generates the function prologue (stack setup, saving registers).
Definition infix_internals.h:476
size_t size
Definition infix_internals.h:64
void * rw_ptr
Definition infix_internals.h:63
void * rx_ptr
Definition infix_internals.h:62
Defines the ABI-specific implementation interface for forward trampolines.
Definition infix_internals.h:313
infix_status(* generate_forward_prologue)(code_buffer *buf, infix_call_frame_layout *layout)
Generates the function prologue (stack setup, saving registers).
Definition infix_internals.h:342
infix_status(* generate_forward_argument_moves)(code_buffer *buf, infix_call_frame_layout *layout, infix_type **arg_types, size_t num_args, size_t num_fixed_args)
Generates code to move arguments from the void** array into registers and/or the stack.
Definition infix_internals.h:352
infix_status(* generate_forward_call_instruction)(code_buffer *buf, infix_call_frame_layout *layout)
Generates the call instruction to the target function.
Definition infix_internals.h:363
infix_status(* prepare_forward_call_frame)(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)
Analyzes a function signature to create a complete call frame layout.
Definition infix_internals.h:329
infix_status(* generate_forward_epilogue)(code_buffer *buf, infix_call_frame_layout *layout, infix_type *ret_type)
Generates the function epilogue (handling return value, restoring stack, returning).
Definition infix_internals.h:371
Internal definition of a forward trampoline handle.
Definition infix_internals.h:88
infix_executable_t exec
Definition infix_internals.h:92
void * target_fn
Definition infix_internals.h:97
size_t num_args
Definition infix_internals.h:95
bool is_external_arena
Definition infix_internals.h:90
size_t num_fixed_args
Definition infix_internals.h:96
infix_type ** arg_types
Definition infix_internals.h:94
infix_type * return_type
Definition infix_internals.h:93
infix_arena_t * arena
Definition infix_internals.h:89
bool is_direct_trampoline
Definition infix_internals.h:98
Describes a single argument to a C function.
Definition infix.h:345
Internal representation of a memory block that will be made read-only.
Definition infix_internals.h:75
void * rw_ptr
Definition infix_internals.h:76
Internal definition of a named type registry.
Definition infix_internals.h:165
Defines the ABI-specific implementation interface for reverse trampolines.
Definition infix_internals.h:382
infix_status(* generate_reverse_argument_marshalling)(code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
Generates code to marshal arguments from their native locations (registers/stack) into a void** array...
Definition infix_internals.h:407
infix_status(* prepare_reverse_call_frame)(infix_arena_t *arena, infix_reverse_call_frame_layout **out_layout, infix_reverse_t *context)
Analyzes a function signature to create a layout for the reverse call stub's stack frame.
Definition infix_internals.h:390
infix_status(* generate_reverse_prologue)(code_buffer *buf, infix_reverse_call_frame_layout *layout)
Generates the reverse stub's prologue (stack setup).
Definition infix_internals.h:399
infix_status(* generate_reverse_dispatcher_call)(code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
Generates the call to the universal C dispatcher (infix_internal_dispatch_callback_fn_impl).
Definition infix_internals.h:417
infix_status(* generate_reverse_epilogue)(code_buffer *buf, infix_reverse_call_frame_layout *layout, infix_reverse_t *context)
Generates the reverse stub's epilogue (handling return value, restoring stack, returning).
Definition infix_internals.h:427
A complete layout blueprint for a reverse call frame.
Definition infix_internals.h:291
Internal definition of a reverse trampoline (callback/closure) handle.
Definition infix_internals.h:114
infix_type * return_type
Definition infix_internals.h:118
void * user_data
Definition infix_internals.h:124
void * user_callback_fn
Definition infix_internals.h:123
infix_executable_t exec
Definition infix_internals.h:116
infix_internal_dispatch_callback_fn internal_dispatcher
Definition infix_internals.h:126
size_t num_args
Definition infix_internals.h:120
size_t num_fixed_args
Definition infix_internals.h:121
infix_protected_t protected_ctx
Definition infix_internals.h:117
bool is_variadic
Definition infix_internals.h:122
infix_forward_t * cached_forward_trampoline
Definition infix_internals.h:128
infix_arena_t * arena
Definition infix_internals.h:115
infix_type ** arg_types
Definition infix_internals.h:119
A semi-opaque structure that describes a C type.
Definition infix.h:273
Definition trampoline.c:193
const infix_type * type
Definition trampoline.c:194
struct visited_node_t * next
Definition trampoline.c:195
void emit_byte(code_buffer *buf, uint8_t byte)
A convenience wrapper to append a single byte to a code buffer.
Definition trampoline.c:186
static bool _is_type_graph_resolved_recursive(const infix_type *type, visited_node_t *visited_head)
Definition trampoline.c:209
const infix_forward_abi_spec * get_current_forward_abi_spec()
Gets the ABI v-table for forward calls for the current platform.
Definition trampoline.c:84
void code_buffer_init(code_buffer *buf, infix_arena_t *arena)
Initializes a code buffer for JIT code generation.
Definition trampoline.c:135
static bool _is_type_graph_resolved(const infix_type *type)
Definition trampoline.c:248
void emit_int64(code_buffer *buf, int64_t value)
A convenience wrapper to append a 64-bit integer (little-endian) to a code buffer.
Definition trampoline.c:190
void code_buffer_append(code_buffer *buf, const void *data, size_t len)
Appends raw bytes to a code buffer, reallocating within its arena if necessary.
Definition trampoline.c:154
static infix_status _infix_forward_create_direct_impl(infix_forward_t **out_trampoline, infix_type *return_type, infix_type **arg_types, size_t num_args, void *target_fn, infix_direct_arg_handler_t *handlers)
Definition trampoline.c:463
static size_t get_page_size()
Definition trampoline.c:653
void emit_int32(code_buffer *buf, int32_t value)
A convenience wrapper to append a 32-bit integer (little-endian) to a code buffer.
Definition trampoline.c:188
static size_t _estimate_metadata_size(infix_arena_t *temp_arena, infix_type *return_type, infix_type **arg_types, size_t num_args)
Definition trampoline.c:263
const infix_direct_forward_abi_spec * get_current_direct_forward_abi_spec()
Gets the ABI v-table for direct marshalling forward calls for the current platform.
Definition trampoline.c:117
static infix_status _infix_reverse_create_internal(infix_reverse_t **out_context, infix_type *return_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args, void *user_callback_fn, void *user_data, bool is_callback)
Definition trampoline.c:686
static infix_status _infix_forward_create_impl(infix_forward_t **out_trampoline, infix_arena_t *target_arena, infix_type *return_type, infix_type **arg_types, size_t num_args, size_t num_fixed_args, void *target_fn)
Definition trampoline.c:316
const infix_reverse_abi_spec * get_current_reverse_abi_spec()
Gets the ABI v-table for reverse calls for the current platform.
Definition trampoline.c:101
A header for conditionally compiled debugging utilities.
static void infix_dump_hex(c23_maybe_unused const void *data, c23_maybe_unused size_t size, c23_maybe_unused const char *title)
Definition utility.h:131