.TH "ttypt/xy.h" 3 "libxylem" \" -*- nroff -*- .ad l .nh .SH NAME ttypt/xy.h \- Modding and extensibility API\&. .SH SYNOPSIS .br .PP \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBxy_adapter_t\fP" .br .RI "Adapter for dispatching hook calls to modules\&. " .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fBXY_MAX_RET_SIZE\fP 4096" .br .RI "Maximum size for return types in hooks\&. " .ti -1c .RI "#define \fBXY_INVALID\fP ((unsigned) \-1)" .br .RI "Invalid hook ID returned when lookup fails\&. " .ti -1c .RI "#define \fBUNUSED\fP \fB__attribute__\fP((unused))" .br .RI "Mark intentionally-unused symbols or parameters\&. " .ti -1c .RI "#define \fBXY_OK\fP 0" .br .RI "Success return code\&. " .ti -1c .RI "#define \fBXY_ERR_NOTFOUND\fP \-1" .br .RI "Error: Module or hook not found\&. " .ti -1c .RI "#define \fBXY_ERR_INVALID\fP \-2" .br .RI "Error: Invalid argument passed to function\&. " .ti -1c .RI "#define \fBXY_ERR_TOOBIG\fP \-3" .br .RI "Error: Return type exceeds XY_MAX_RET_SIZE / no slot available\&. " .ti -1c .RI "#define \fBXY_ERR_INIT\fP \-4" .br .RI "Error: Library initialization failed\&. " .ti -1c .RI "#define \fBXY_ERR_EPERM\fP \-5" .br .RI "Error: Operation not permitted (deny, claim, unload veto, etc\&.)\&. " .ti -1c .RI "#define \fBXY_ERR_ABI\fP \-6" .br .RI "Error: Module was built against a different xy_ctx ABI\&. " .ti -1c .RI "#define \fBXY_MODULE_API\fP \fB__attribute__\fP((visibility('default')))" .br .RI "Export symbol from module (POSIX)\&. " .ti -1c .RI "#define \fBXY_DECL\fP(ftype, fname, \&.\&.\&.)" .br .RI "Declare a hook that can be called like a normal function\&. " .ti -1c .RI "#define \fBXY_DEF\fP(ftype, fname, \&.\&.\&.)" .br .RI "Define the canonical adapter for a normal-function hook\&. " .ti -1c .RI "#define \fBXY_IMPL\fP(ftype, fname, \&.\&.\&.)" .br .RI "Define a module listener implementation for a hook\&. " .ti -1c .RI "#define \fBXY_LISTENER_TAG\fP(ftype, fname, tag, \&.\&.\&.)" .br .RI "Define a tagged module listener implementation for a hook\&. " .ti -1c .RI "#define \fBXY_CALL\fP(retp, fname, \&.\&.\&.)" .br .RI "Call a mod hook by name within the current thread-local region\&. " .ti -1c .RI "#define \fBXY_REGION_ROOT\fP ((uint64_t)0)" .br .ti -1c .RI "#define \fBXY_REGION_INVALID\fP ((uint64_t)\-1)" .br .in -1c .PP .RI "\fBContext ABI tripwire\fP" .br The host fills a module-local \fBxy_ctx\fP by writing \fRsizeof(struct xy_ctx)\fP bytes into it, using the size \fIthe host\fP was compiled with\&. If the module was built against a different header its object may be smaller, and the tail of that write lands in whatever follows it in the module's BSS\&. This is invisible at the source level — a stale module still loads, still returns XY_OK, and still has working function pointers for every field both versions share — so the only symptom is corruption of an unrelated library, some distance away\&. .PP Two mechanisms prevent that, and both must be used: .PP .IP "1." 4 \fBXY_CTX_SIZE\fP is a hard \fR_Static_assert\fP on this struct\&. Adding or removing a field fails the build of \fIeverything\fP that includes this header, host and module alike, until the constant is deliberately bumped\&. That makes a layout change impossible to ship silently\&. .IP "2." 4 \fBXY_CTX_ABI_VER\fP is exchanged at load time\&. A module must export \fR\fBxy_ctx_abi()\fP\fP (\fBxy-mod\&.h\fP emits it automatically); if the descriptor does not match the host's exactly, the load is refused with \fBXY_ERR_ABI\fP\&. This catches the case (1) cannot: a module compiled earlier against an older header and still sitting on disk\&. .PP .PP Note that (1) alone is not enough, because \fRexternal/axil-*\fP modules build against the \fIsystem-installed\fP header tree rather than this submodule, so a site \fRmake\fP does not rebuild them\&. .PP .in +1c .in +1c .ti -1c .RI "#define \fBXY_CTX_ABI_VER\fP 3" .br .RI "ABI generation of \fBxy_ctx\fP\&. Bump on every layout change\&. " .ti -1c .RI "#define \fBXY_CTX_SIZE\fP 184" .br .RI "\fRsizeof(struct xy_ctx)\fP as asserted by this header\&. " .ti -1c .RI "#define \fBXY_CTX_ABI_DESC\fP (((uint64_t)(\fBXY_CTX_ABI_VER\fP) << 32) | (uint32_t)(\fBXY_CTX_SIZE\fP))" .br .RI "The value a module must export from \fR\fBxy_ctx_abi()\fP\fP\&. " .in -1c .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef void(* \fBmod_cb_t\fP) (void)" .br .RI "Module callback function type\&. " .ti -1c .RI "typedef int \fBxy_deny_t\fP(const char *what, \fBxy_deny_type_t\fP type)" .br .RI "Deny a hook or module within the caller's current region\&. " .ti -1c .RI "typedef int \fBxy_claim_handler_fn_t\fP(const char *module_path, uint8_t requested_bits, uint8_t *granted_bits, void *ud)" .br .RI "Claim handler type\&. " .ti -1c .RI "typedef int \fBxy_require_claim_t\fP(\fBxy_claim_handler_fn_t\fP *fn, void *ud)" .br .RI "Set or clear the claim gate on the caller's current region\&. " .ti -1c .RI "typedef int \fBxy_region_each_fn_t\fP(uint64_t child_id, uint8_t plen, void *ud)" .br .RI "Enumerate immediate child regions of the caller's current region\&. " .ti -1c .RI "typedef int \fBxy_with_region_t\fP(uint64_t region_id, uint8_t plen, xy_scope_fn_t *fn, void *ud)" .br .RI "Run \fRfn\fP with the caller's current region temporarily set to the region identified by (\fRregion_id\fP, \fRplen\fP)\&. " .ti -1c .RI "typedef uint64_t \fBxy_current_region_t\fP(void)" .br .RI "Return the id half of the caller's current region identity\&. " .ti -1c .RI "typedef uint8_t \fBxy_current_region_plen_t\fP(void)" .br .RI "Return the plen half of the caller's current region identity\&. " .ti -1c .RI "typedef int \fBxy_region_exists_t\fP(uint64_t region_id, uint8_t plen)" .br .RI "Test whether the region identified by (\fRregion_id\fP, \fRplen\fP) exists and is addressable\&. " .ti -1c .RI "typedef int \fBxy_claim_at_t\fP(uint64_t id, uint8_t plen, \fBxy_claim_handler_fn_t\fP *fn, void *ud)" .br .RI "Create the region identified by (\fRid\fP, \fRplen\fP), or reuse it\&. " .ti -1c .RI "typedef uint64_t \fBxy_region_at_t\fP(uint64_t prefix_id, uint8_t plen, uint8_t *region_plen)" .br .RI "Find the deepest existing region whose prefix covers a point\&. " .ti -1c .RI "typedef int \fBxy_call_self_t\fP(void *retp, \fBxy_adapter_t\fP *adapter, void *args)" .br .RI "Dispatch to the caller's current region's own modules only\&. " .ti -1c .RI "typedef int \fBxy_load_t\fP(char *fname)" .br .RI "Load or reload a module into the caller's current region\&. " .ti -1c .RI "typedef int \fBxy_unload_t\fP(char *fname)" .br .RI "Unload a previously loaded module from the caller's current region\&. " .ti -1c .RI "typedef int \fBxy_reload_t\fP(char *fname)" .br .RI "Reload a module in place, preserving its dispatch position\&. " .ti -1c .RI "typedef void \fBxy_shutdown_t\fP(void)" .br .RI "Shutdown and unload all modules\&. " .ti -1c .RI "typedef int \fBxy_errno_t\fP(void)" .br .RI "Get last error code\&. " .ti -1c .RI "typedef const char * \fBxy_strerror_t\fP(int err)" .br .RI "Get human-readable error message\&. " .in -1c .SS "Enumerations" .in +1c .ti -1c .RI "enum \fBxy_deny_type_t\fP { \fBXY_DENY_HOOK\fP = 0, \fBXY_DENY_MODULE\fP = 1 }" .br .RI "Deny target (hook name or module path) selector\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "struct \fB__attribute__\fP ((packed)) xy_region_key" .br .RI "Region identity\&. " .ti -1c .RI "void \fBxy_self_init_ctx\fP (struct xy_ctx *ctx)" .br .RI "Register a module's xy context from a \&.init_array constructor\&. " .ti -1c .RI "uint64_t \fBxy_ctx_abi\fP (void)" .br .RI "Report this module's xy_ctx ABI generation and size\&. " .ti -1c .RI "int \fBxy_load_mem\fP (const xy_mem_mod_t *desc)" .br .RI "Load an in-memory module into the caller's current region\&. " .ti -1c .RI "int \fBxy_register_mem_mod\fP (const xy_mem_mod_t *desc)" .br .RI "Register a statically linked in-memory module descriptor for lazy resolution by \fBxy_load()\fP\&. " .in -1c .SH "Detailed Description" .PP Modding and extensibility API\&. .SH "Synopsis" .PP .PP .nf XY_DEF(int, on_tick, int, dt); on_tick(16); .fi .PP .SH "Overview" .PP libxylem provides a plugin/module system where: .IP "\(bu" 2 \fBHost\fP defines hooks and loads modules .IP "\(bu" 2 \fBModule\fP implements hooks in a shared library .PP .SH "Usage" .PP .IP "1." 4 Host uses XY_DEF to define hook signatures .IP "2." 4 Host loads modules via \fBxy_load()\fP .IP "3." 4 Modules use XY_IMPL to implement hooks they provide .IP "4." 4 Modules include \fBxy-mod\&.h\fP .PP .SH "Dependencies" .PP Dependencies between modules are handled through the API: .IP "\(bu" 2 Common headers use XY_DECL for shared hook signatures .IP "\(bu" 2 Implementing modules use XY_IMPL to define hooks .IP "\(bu" 2 Dependent modules call \fBxy_load()\fP in xy_install() to load dependencies .IP "\(bu" 2 Then call hooks as normal functions from dependencies .PP .SH "Error Handling" .PP .IP "\(bu" 2 Functions return XY_OK (0) on success or negative XY_ERR_* on failure .IP "\(bu" 2 Use xy_errno() to get last error code .IP "\(bu" 2 Use xy_strerror(err) to get human-readable message .PP .SH "Macro Definition Documentation" .PP .SS "#define XY_CALL( retp, fname, \&.\&.\&.)" \fBValue:\fP .nf { \\ struct fname##_args args = { __VA_ARGS__ }; \\ xy_call(retp, &fname##_adapter, &args); \\ } .PP .fi .PP Call a mod hook by name within the current thread-local region\&. This macro calls all modules that implement the named hook whose region is a descendant-or-equal of the caller's current region\&. The return value is from the last module that ran\&. .PP \fBParameters\fP .RS 4 \fIretp\fP Pointer to store return value .br \fIfname\fP Hook function name .br \fI\&.\&.\&.\fP Arguments to pass to the hook .RE .PP Example: .PP .nf int result; XY_CALL(&result, on_tick, 16); .fi .PP .SS "#define XY_CTX_ABI_DESC (((uint64_t)(\fBXY_CTX_ABI_VER\fP) << 32) | (uint32_t)(\fBXY_CTX_SIZE\fP))" .PP The value a module must export from \fR\fBxy_ctx_abi()\fP\fP\&. Packs the ABI generation in the high 32 bits and the context size in the low 32, so one exported function carries the whole contract and the host can decode it for an actionable error message\&. .SS "#define XY_DECL( ftype, fname, \&.\&.\&.)" \fBValue:\fP .nf typedef ftype fname##_t(XY_FA(__VA_ARGS__)); \\ _Pragma("GCC diagnostic push") \\ _Pragma("GCC diagnostic ignored \\"\-Wpedantic\\"") \\ struct fname##_args { \\ XY_PG(__VA_ARGS__) \\ }; \\ _Pragma("GCC diagnostic pop") \\ static xy_adapter_t __xy_decl_##fname##_adapter = { \\ \&.name = XSTR(fname), \\ \&.arg_size = sizeof(struct fname##_args), \\ \&.ret_size = sizeof(ftype), \\ \&.hook_id = \-1, \\ }; \\ static inline UNUSED \\ ftype fname(XY_FA(__VA_ARGS__)) { \\ ftype ret; \\ struct fname##_args args = { XY_DA(__VA_ARGS__) }; \\ __XY_DISPATCH(&ret, &__xy_decl_##fname##_adapter, &args); \\ return ret; \\ } \\ typedef int __xy_decl_##fname##_semicolon_eater_t .PP .fi .PP Declare a hook that can be called like a normal function\&. This is the preferred declaration form for call sites that should read as ordinary C\&. The generated inline function still routes through XY_CALL, so the current execution region is preserved\&. .PP Do not use this macro in the same translation unit that defines a listener for the same hook name with XY_IMPL; the listener should keep using XY_IMPL and dispatch recursively with XY_CALL when needed\&. .SS "#define XY_DEF( ftype, fname, \&.\&.\&.)" .PP Define the canonical adapter for a normal-function hook\&. Use XY_DECL in shared headers; use XY_DEF in the one translation unit that emits the canonical adapter\&. XY_DEF is self-sufficient in definition TUs and also provides the ordinary call syntax there\&. .SS "#define XY_ERR_ABI \-6" .PP Error: Module was built against a different xy_ctx ABI\&. Returned by \fBxy_load()\fP when the module's context object cannot be proven at least as large as the host's (see \fBXY_CTX_ABI_VER\fP and \fBxy_ctx_abi()\fP)\&. This is deliberately a \fIload-time refusal\fP rather than a best-effort write: see the ABI note above \fBstruct\fP xy_ctx for why the alternative is silent memory corruption\&. .SS "#define XY_IMPL( ftype, fname, \&.\&.\&.)" .PP Define a module listener implementation for a hook\&. Use this in modules that implement hooks\&. The host dispatches to these listener functions when the matching hook is called\&. .PP Creates: .IP "\(bu" 2 \fRfname##_t:\fP Function typedef .IP "\(bu" 2 \fRfname:\fP Function implementation (you provide this) .IP "\(bu" 2 \fRfname##_id:\fP Hook ID (set on registration) .PP .PP The hook is auto-registered when the module loads\&. .PP \fBParameters\fP .RS 4 \fIftype\fP Return type (e\&.g\&., int, void) .br \fIfname\fP Function name (e\&.g\&., on_tick) .br \fI\&.\&.\&.\fP Argument types and names (e\&.g\&., int, dt) .RE .PP Example: .PP .nf XY_IMPL(int, on_tick, int, dt); int on_tick(int dt) { return dt + 1; } .fi .PP .SS "#define XY_LISTENER_TAG( ftype, fname, tag, \&.\&.\&.)" .PP Define a tagged module listener implementation for a hook\&. Emits static functions and adapters tagged with \fRtag\fP so that multiple listeners for the same hook can be compiled into the same library or WASM reactor without linker symbol collisions\&. .SS "#define XY_MAX_RET_SIZE 4096" .PP Maximum size for return types in hooks\&. Return types larger than this will cause a compile-time static assertion when using XY_DEF or XY_IMPL\&. .SS "#define XY_REGION_INVALID ((uint64_t)\-1)" Sentinel returned when region allocation fails\&. .SS "#define XY_REGION_ROOT ((uint64_t)0)" Root region — ancestor of all regions\&. Passing this to xy_call dispatches to every module regardless of its region\&. .SH "Typedef Documentation" .PP .SS "typedef void(* mod_cb_t) (void)" .PP Module callback function type\&. Used for mod_auto_init(), xy_install() .SS "typedef int xy_call_self_t(void *retp, \fBxy_adapter_t\fP *adapter, void *args)" .PP Dispatch to the caller's current region's own modules only\&. The exact-region counterpart of xy_call()\&. xy_call() reaches the current region's whole subtree; this reaches only the modules loaded directly into the current region — no descendant region, and no ancestor\&. .PP It exists so an ancestor walk gives each region one observable turn instead of re-running every level's entire subtree once per step\&. Deny checks and xy_last() predecessor semantics are identical to xy_call()'s: a listener still sees its predecessor's return value, and a deny from any ancestor still refuses the whole dispatch with XY_ERR_EPERM\&. .PP \fBParameters\fP .RS 4 \fIretp\fP Out-param for the last listener's return value\&. .br \fIadapter\fP The hook adapter\&. .br \fIargs\fP Hook arguments\&. .RE .PP \fBReturns\fP .RS 4 XY_OK, XY_ERR_NOTFOUND if no listener in this exact region ran (an empty dispatch, which is not the same as a listener returning zero — read xy_errno() to tell them apart), or another XY_ERR_*\&. .RE .PP .SS "typedef int xy_claim_at_t(uint64_t id, uint8_t plen, \fBxy_claim_handler_fn_t\fP *fn, void *ud)" .PP Create the region identified by (\fRid\fP, \fRplen\fP), or reuse it\&. The engine-facing creation primitive: it names the region outright instead of waiting for a module to claim bits, so a region can exist before any module is loaded into it (Phase 3's st_open) and be rebuilt at boot from persisted state (Phase 2's restore)\&. .PP \fRid\fP is an opaque prefix value whose prefix lives in the HIGH bits above \fRplen\fP — the same shape region_alloc_slot() produces for a claim-gated child\&. So \fR2<<48\fP at \fRplen\fP 16 is a canonical, fully aligned id; a value with any bit set below the prefix width is not, and is rejected\&. \fRid\fP is never inspected to infer a width: CP-3 established that four regions share \fRid\fP 0, so a "lowest set bit implies the width" shortcut is exactly the bug this API exists to avoid\&. Pass the width\&. .PP The new region is attached to the \fInearest existing ancestor\fP — the region of the largest width below \fRplen\fP that prefix-covers (\fRid\fP, \fRplen\fP), the root always qualifying\&. No intermediate ancestors are invented, so a multi-bit jump is legal and cheap: claiming (0,64) straight from the root creates one region, not four\&. .PP Rejections: .IP "\(bu" 2 \fRplen\fP > 64 -> XY_ERR_TOOBIG .IP "\(bu" 2 (\fRid\fP & high-bit-mask(\fRplen\fP)) != \fRid\fP -> XY_ERR_INVALID (misaligned) .IP "\(bu" 2 \fRplen\fP <= its nearest covering ancestor's width -> XY_ERR_INVALID .PP .PP Note what that last rule does \fInot\fP say: a same-id child is legal\&. Claiming (0,16) under the root (0,0) widens the region, so it is accepted — and it has to be, since (0,0) and (0,16) sharing an id is exactly what CP-3 introduced\&. The rejection is about \fIwidth\fP, never about \fRid\fP equalling the ancestor's\&. .PP An exact (\fRid\fP, \fRplen\fP) match is idempotent: it succeeds, becomes the caller's current region, and — like the creation path — installs \fRfn\fP as the region's claim handler when \fRfn\fP is non-NULL\&. A later claim therefore reconfigures an existing region rather than silently ignoring the handler\&. .PP \fBParameters\fP .RS 4 \fIfn\fP Claim handler to install on the region, or NULL for none\&. .br \fIud\fP User data for \fRfn\fP\&. .RE .PP \fBReturns\fP .RS 4 XY_OK on creation or reuse; negative XY_ERR_* on rejection\&. On success the region is the caller's current region, so a following \fBxy_load()\fP lands inside it\&. .RE .PP .SS "typedef int xy_claim_handler_fn_t(const char *module_path, uint8_t requested_bits, uint8_t *granted_bits, void *ud)" .PP Claim handler type\&. .PP \fBParameters\fP .RS 4 \fImodule_path\fP Path of the child module making the request (read-only) .br \fIrequested_bits\fP Number of bits the child asked for .br \fIgranted_bits\fP Out-param: set to the approved width .br \fIud\fP User data from \fBxy_require_claim()\fP .RE .PP \fBReturns\fP .RS 4 XY_OK to approve (with *granted_bits set), XY_ERR_EPERM to reject\&. .RE .PP .SS "typedef uint8_t xy_current_region_plen_t(void)" .PP Return the plen half of the caller's current region identity\&. Reads the thread-local region entry directly — no lookup, and no ambiguity, because the current region is already resolved\&. For any region other than the current one, use \fBxy_region_exists()\fP to test an exact (id, plen)\&. .PP \fBReturns\fP .RS 4 Prefix length in bits; 0 for the root region\&. .RE .PP .SS "typedef uint64_t xy_current_region_t(void)" .PP Return the id half of the caller's current region identity\&. This is the id only\&. It does not name a region uniquely; pair it with \fBxy_current_region_plen()\fP to obtain a full identity\&. .SS "typedef int xy_deny_t(const char *what, \fBxy_deny_type_t\fP type)" .PP Deny a hook or module within the caller's current region\&. The deny applies to sub-regions only (children-only semantics by default)\&. A module's own region is never blocked by its own deny\&. .PP \fBParameters\fP .RS 4 \fIwhat\fP Hook name (XY_DENY_HOOK) or module path (XY_DENY_MODULE)\&. .br \fItype\fP XY_DENY_HOOK or XY_DENY_MODULE\&. .RE .PP \fBReturns\fP .RS 4 XY_OK or a negative XY_ERR_* code\&. .RE .PP .SS "typedef int xy_errno_t(void)" .PP Get last error code\&. .PP \fBReturns\fP .RS 4 Last error code from failed API call .RE .PP Most API functions set this on failure\&. .SS "typedef int xy_load_t(char *fname)" .PP Load or reload a module into the caller's current region\&. .PP \fBParameters\fP .RS 4 \fIfname\fP Path to \&.so (Linux) or \&.dll (Windows) file .RE .PP \fBReturns\fP .RS 4 XY_OK on success, negative error code on failure .RE .PP On first load, calls xy_install()\&. Subsequent loads of the same path into the same region are no-ops\&. .SS "typedef uint64_t xy_region_at_t(uint64_t prefix_id, uint8_t plen, uint8_t *region_plen)" .PP Find the deepest existing region whose prefix covers a point\&. The engine's "which region is this point in?" primitive: given a prefix value, return the most specific region that contains it, so a caller walking the tree coarse-to-fine can tell an exact hit from an ancestor fallback\&. .PP A region (A, plen_A) covers (\fRprefix_id\fP, \fRplen\fP) when \fRplen_A\fP <= \fRplen\fP and masking \fRprefix_id\fP to \fRplen_A\fP yields \fRA\fP\&. The root covers every point, so the only way to miss is a \fRplen\fP that no region reaches\&. .PP \fBParameters\fP .RS 4 \fIprefix_id\fP The point to locate\&. .br \fIplen\fP That point's prefix width in bits\&. .br \fIregion_plen\fP Out-param: the covering region's width\&. Set to 0 on every failure path, so it is always defined\&. May be NULL\&. .RE .PP \fBReturns\fP .RS 4 The covering region's id half, or XY_REGION_INVALID if none\&. The id alone does not name a region — (0,0) and (0,16) share it — so pass the returned width to \fBxy_with_region()\fP to dispatch there\&. .RE .PP .SS "typedef int xy_region_each_fn_t(uint64_t child_id, uint8_t plen, void *ud)" .PP Enumerate immediate child regions of the caller's current region\&. Calls \fRfn(child_id, plen, ud)\fP for each child in allocation order\&. \fRchild_id\fP is an opaque uint64_t region identifier and \fRplen\fP is that child's prefix length in bits; together they are the child's identity\&. .PP Return XY_OK from \fRfn\fP to continue, any other value to stop\&. xy_region_each returns the last value returned by \fRfn\fP, or XY_OK if there were no children\&. .SS "typedef int xy_region_exists_t(uint64_t region_id, uint8_t plen)" .PP Test whether the region identified by (\fRregion_id\fP, \fRplen\fP) exists and is addressable\&. .PP \fBReturns\fP .RS 4 XY_OK if that exact region exists, XY_ERR_NOTFOUND otherwise\&. Both halves are required: an \fRregion_id\fP that exists at a different width is a different region\&. .RE .PP .SS "typedef int xy_reload_t(char *fname)" .PP Reload a module in place, preserving its dispatch position\&. Equivalent to \fBxy_unload()\fP followed by \fBxy_load()\fP in the same region, but the reloaded module is re-inserted at its original position in the dispatch order rather than appended at the tail\&. .PP If xy_uninstall() vetoes the unload the reload is aborted\&. .PP \fBParameters\fP .RS 4 \fIfname\fP Path that was passed to \fBxy_load()\fP (without \&.so/\&.dll suffix) .RE .PP \fBReturns\fP .RS 4 XY_OK on success, negative XY_ERR_* on failure\&. .RE .PP .SS "typedef int xy_require_claim_t(\fBxy_claim_handler_fn_t\fP *fn, void *ud)" .PP Set or clear the claim gate on the caller's current region\&. When \fRfn\fP is non-NULL, the gate is opened: all subsequent \fBxy_load()\fP calls into this region require the module to export a \fR\fBXY_MODULE_API\fP uint8_t xy_claim\fP data symbol\&. If the symbol is absent, \fBxy_load()\fP returns XY_ERR_EPERM and xy_install() never runs\&. If the symbol is present, the host performs the claim on behalf of the module by invoking \fRfn\fP before running xy_install()\&. .PP Modules loaded \fIbefore\fP this call in the same xy_install() context are unaffected — they load flat into the current region as normal\&. .PP When \fRfn\fP is NULL, the gate is cleared: subsequent \fBxy_load()\fP calls no longer require an xy_claim symbol\&. A later non-NULL call re-enables the gate\&. .PP \fBParameters\fP .RS 4 \fIfn\fP Claim handler function, or NULL to clear the claim gate\&. .br \fIud\fP User data passed to fn (ignored when fn is NULL)\&. .RE .PP \fBReturns\fP .RS 4 XY_OK or negative XY_ERR_* code\&. .RE .PP .SS "typedef void xy_shutdown_t(void)" .PP Shutdown and unload all modules\&. Calls dlclose() on all loaded module handles\&. After this, \fBxy_load()\fP can be called again\&. .SS "typedef const char * xy_strerror_t(int err)" .PP Get human-readable error message\&. .PP \fBParameters\fP .RS 4 \fIerr\fP Error code (e\&.g\&., from xy_errno()) .RE .PP \fBReturns\fP .RS 4 Static string describing the error .RE .PP .SS "typedef int xy_unload_t(char *fname)" .PP Unload a previously loaded module from the caller's current region\&. Decrements the module's reference count\&. When the count reaches zero: .IP "\(bu" 2 Calls the module's xy_uninstall() export (if present); if it returns non-zero the unload is aborted and XY_ERR_EPERM is returned\&. .IP "\(bu" 2 Recursively unloads child modules whose reference count would reach zero\&. .IP "\(bu" 2 Removes deny entries registered by the module\&. .IP "\(bu" 2 Invalidates cached function pointers across all other modules\&. .IP "\(bu" 2 Calls dlclose() and frees internal bookkeeping\&. .PP .PP \fBParameters\fP .RS 4 \fIfname\fP Path that was passed to \fBxy_load()\fP (without \&.so/\&.dll suffix) .RE .PP \fBReturns\fP .RS 4 XY_OK on success, XY_ERR_NOTFOUND if not loaded, XY_ERR_EPERM if xy_uninstall() vetoed the unload\&. .RE .PP .SS "typedef int xy_with_region_t(uint64_t region_id, uint8_t plen, xy_scope_fn_t *fn, void *ud)" .PP Run \fRfn\fP with the caller's current region temporarily set to the region identified by (\fRregion_id\fP, \fRplen\fP)\&. Nested hook calls inside \fRfn\fP inherit that region\&. The previous region is always restored, including when \fRfn\fP fails\&. .PP \fBReturns\fP .RS 4 XY_ERR_NOTFOUND if no region with that exact (id, plen) exists — an \fRregion_id\fP that exists at some other width is a different region and is likewise not found\&. .RE .PP .SH "Enumeration Type Documentation" .PP .SS "enum \fBxy_deny_type_t\fP" .PP Deny target (hook name or module path) selector\&. .PP \fBEnumerator\fP .in +1c .TP \f(BIXY_DENY_HOOK \fP \fRwhat\fP is a hook name .TP \f(BIXY_DENY_MODULE \fP \fRwhat\fP is a module path .SH "Function Documentation" .PP .SS "struct __attribute__ ((packed) )" .PP Region identity\&. A region is identified by the pair \fR\fP(id, plen) — never by \fRid\fP alone\&. \fRid\fP is an opaque uint64_t prefix value and \fRplen\fP is that prefix's length in bits (0 for the root region)\&. Two regions may legitimately share an \fRid\fP and differ only in \fRplen\fP — e\&.g\&. the root \fR\fP(0,0) and a child granted its leftmost bits \fR\fP(0,16) — so any API that must name a region unambiguously takes both halves\&. .PP This struct is packed, and that is load-bearing rather than cosmetic: it serves as a fixed-width corm key compared bytewise, so any padding would be uninitialised bytes that differ between the storing and the looking-up call and would silently make lookups miss\&. sizeof must be exactly 9\&. .SS "uint64_t xy_ctx_abi (void )" .PP Report this module's xy_ctx ABI generation and size\&. A module \fBmust\fP export this symbol with exactly this signature, returning \fBXY_CTX_ABI_DESC\fP\&. \fR\fBxy-mod\&.h\fP\fP emits it automatically for C modules and \fRxy_module!()\fP does so for Rust modules; a hand-written module that only exports \fRget_xy_ptr\fP must add it by hand\&. .PP The host compares the returned descriptor against its own before writing anything into the module's context\&. A module built against a different header has an object of a different size, and the host's write would overrun it — corrupting unrelated data in the module's BSS rather than failing\&. A module that does not export this symbol at all is refused the same way, because an unversioned module cannot be proven safe\&. .PP Only modules that actually \fIhave\fP a context need this\&. A module that exports neither \fRget_xy_ptr\fP nor a \fR\fBxy_self_init_ctx\fP\fP call has nothing for the host to write into, so there is nothing to overrun and nothing to declare; bootstrap modules like the site's \fRcore\fP are in that class and load unchanged\&. .PP \fBReturns\fP .RS 4 \fBXY_CTX_ABI_DESC\fP as compiled into the calling module\&. .RE .PP .SS "int xy_load_mem (const xy_mem_mod_t * desc)" .PP Load an in-memory module into the caller's current region\&. On XY_OK, libxylem takes ownership of releasing the backing memory via desc->release(desc->ud) when the module is unloaded via xy_unload(desc->name) or xy_shutdown()\&. On any error, desc->release is NOT invoked\&. .SS "int xy_register_mem_mod (const xy_mem_mod_t * desc)" .PP Register a statically linked in-memory module descriptor for lazy resolution by \fBxy_load()\fP\&. When a host registers static modules with \fBxy_register_mem_mod()\fP, subsequent \fBxy_load()\fP calls matching desc->name (exact or logical basename) resolve via xy_load_mem(desc) without invoking dlopen()\&. Idempotent and preserved across xy_shutdown() so embedded hosts can restart cleanly\&. .SS "void xy_self_init_ctx (struct xy_ctx * ctx)" .PP Register a module's xy context from a \&.init_array constructor\&. Rust cdylibs call this from a \&.init_array constructor (generated by xy_module!()) to push their xy context pointer to the loader before mod_load_bind_xy runs\&. The loader uses it as a fallback when get_xy_ptr lookup fails or returns an unexpected result\&. .PP \fBParameters\fP .RS 4 \fIctx\fP Pointer to the module-local XyCtx static\&. .RE .PP .SH "Author" .PP Generated automatically by Doxygen for libxylem from the source code\&.