Skip to content

LATX: Add experimental stateless GLib leaf passthrough - #408

Draft
LaurenIsACoder wants to merge 3 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/kzt-glib-gobject
Draft

LATX: Add experimental stateless GLib leaf passthrough#408
LaurenIsACoder wants to merge 3 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/kzt-glib-gobject

Conversation

@LaurenIsACoder

@LaurenIsACoder LaurenIsACoder commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

概要 / Overview

本 PR 为 KZT 增加 experimental glib 库族,并对 54 个无状态 GLib 叶子函数启用 LoongArch host 原生直通。所选函数只处理 scalar、caller-owned 字符串、caller-owned buffer 或 raw pointer,不创建或返回需要 GLib 管理的对象。

This PR adds an experimental KZT glib family and enables native LoongArch passthrough for 54 stateless GLib leaf functions. The selected functions only consume scalars, caller-owned strings, caller-owned buffers, or raw pointers; they do not create or return objects with GLib-managed ownership.

设计边界 / Design boundary

GLib 与 GObject 不能按常用函数逐步混合直通。GHashTable、GSource、GMainContext、GVariant、GType、GObject、GClosure、GValue 和 GIO 对象都包含长期状态;如果对象由 host 创建而后续函数回到 guest,guest 库会解引用 host 私有对象。GType、GQuark、signal ID 还依赖各自的 registry,不能混用 host 与 guest 值。

GLib and GObject cannot safely use opportunistic per-function passthrough for object APIs. GHashTable, GSource, GMainContext, GVariant, GType, GObject, GClosure, GValue, and GIO objects carry persistent state. If host code creates an object and an uncovered operation later returns to the guest library, guest code would dereference a host-private object. GType, GQuark, and signal IDs also belong to separate registries and cannot be mixed between host and guest.

因此,本 PR 明确保留以下范围在 guest:

  • allocator、GSlice 和返回新分配结果的 API;
  • GError、GBytes、container、main loop 和 thread object;
  • GType、GQuark、GObject、GClosure、GValue、GVariant 和 signal;
  • GModule 与 GIO。

The following areas therefore remain fully on the guest path:

  • allocators, GSlice, and APIs returning newly allocated ownership;
  • GError, GBytes, containers, main-loop objects, and thread objects;
  • GType, GQuark, GObject, GClosure, GValue, GVariant, and signals;
  • GModule and GIO.

This keeps every GLib/GObject object, registry, callback owner, and destroy path inside the guest implementation while allowing stateless leaf calls to enter host GLib.

主要修改 / Main changes

  • 新增 experimental glib group,依赖 stable core,默认不启用。

  • 为 ASCII、字符串、hash/equal、UTF-8 结构和 pointer-sized bit 操作增加 54 个 GO wrapper。

  • 增加对应的 signed-byte、pointer-sized、floating-point 和 mixed-register dispatch 形态。

  • wrapper 激活前仅 preflight 选定的叶子函数;guest 实际导出的叶子符号缺少 host 对应符号时关闭整个 glib group。

  • KZT 日志明确说明 allocator、container、GObject、GIO 和 callback-owning API 仍为 guest。

  • --kzt-libs 显示 glib status=experimental requires=core

  • Adds an experimental glib group depending on stable core; it is disabled by default.

  • Adds 54 GO wrappers covering ASCII, strings, hash/equal helpers, UTF-8 structure handling, and pointer-sized bit operations.

  • Adds the required signed-byte, pointer-sized, floating-point, and mixed-register dispatch shapes.

  • Preflights only the selected leaf surface. If a leaf symbol exported by the guest has no matching host symbol, the complete glib group is disabled.

  • Logs the explicit boundary that allocators, containers, GObject, GIO, and callback-owning APIs remain guest-side.

  • Exposes glib status=experimental requires=core through --kzt-libs.

验证 / Validation

当前验证在 AOSC OS LoongArch ABI 2.0 主机完成:

  • guest GLib 2.80.0,1850 个函数导出;host GLib 2.88.2,1868 个函数导出。
  • 54/54 选定函数在 guest 和 host 中存在,54/54 wrapper 签名与公开头文件 AST 一致。
  • 普通 latx-x86_64 产品构建通过;二进制 SHA-256:3c0b429d31df039b1dcec26e59db5503379b9bc1276e2328b0e232cb7ec4e70a
  • 56-call differential probe(54 个 native 候选和 2 个保持 guest 的版本敏感 hash control):KZT=0 20/20,KZT=1 20/20;两者结果 hash 均为 defd1c68d48c8314
  • guest 版本 data 继续报告 GLib 2.80.0,没有暴露 host 版本 data。
  • GDB 命中 host g_ascii_digit_valueg_ascii_strtodg_ascii_dtostrg_ascii_formatdg_bit_nth_lsfg_strlcatg_strcanong_unichar_to_utf8g_utf8_validate_len
  • 对象边界 probe:KZT=0/1 各 20/20;g_hash_table_new_fullg_object_newg_idle_add_full 仍位于 guest 0x550... 地址并由 LAT 翻译。
  • guest GHashTable 可以通过 KZT bridge 调用 host g_str_hash,但 GHashTable 对象仍完全属于 guest。
  • weak notify、signal callback、GClosure finalize、idle callback 和 destroy callback 均保持 guest 往返并正确完成。
  • thread probe:KZT=0/1 各 20/20;每次包含 4 线程、2000 次 leaf、400 个 guest GHashTable 和 4 个 guest GMainContext/GSource callback。
  • GDB 注入缺失 host GLib 后,preflight 记录原因、关闭 glib、跳过 wrapper,probe 在完整 guest 路径退出 0。
  • Loongnix ABI 1.0 guest GLib 2.58.3 中存在 52/54 个选定 leaf;2.60+ 的 g_strv_equalg_utf8_validate_len 不参与绑定。ABI 1.0 的 54-call differential、对象边界和四线程 probe 在 KZT=0/1 下各 20/20,结果 hash 均为 3b1b4b6ac4be492d,GDB endpoint 与安全回退通过。
  • g_int64_hashg_double_hash 在 GLib 2.58 与新 host 间返回不同的可观察数值,因此明确保留 guest,不在 54 个 allowlist 中。

Validation currently covers an AOSC OS LoongArch ABI 2.0 host:

  • Guest GLib 2.80.0 exports 1850 functions; host GLib 2.88.2 exports 1868 functions.
  • All 54 selected functions exist in both guest and host, and all 54 wrapper signatures match the public-header AST.
  • The regular latx-x86_64 product build passes; binary SHA-256: 3c0b429d31df039b1dcec26e59db5503379b9bc1276e2328b0e232cb7ec4e70a.
  • A 56-call differential probe (54 native candidates and two version-sensitive hash controls kept on the guest path) passes 20/20 with KZT=0 and 20/20 with KZT=1; both produce hash defd1c68d48c8314.
  • Guest version data continues to report GLib 2.80.0; host version data is not exposed.
  • GDB reaches representative host ASCII, number-conversion, bit, string, Unicode-encoding, and UTF-8 functions.
  • The object-boundary probe passes 20/20 with both KZT settings. g_hash_table_new_full, g_object_new, and g_idle_add_full remain at guest 0x550... addresses and are translated by LAT.
  • A guest GHashTable can call host g_str_hash through a KZT bridge while the GHashTable object remains entirely guest-owned.
  • Weak notify, signal callbacks, GClosure finalization, idle callbacks, and destroy callbacks complete on the guest path.
  • The thread probe passes 20/20 with both KZT settings, with four threads, 2000 leaf calls, 400 guest GHashTable lifecycles, and four guest GMainContext/GSource callbacks per run.
  • Injecting a missing host GLib causes preflight to log the rejection, disable glib, skip the wrapper, and complete the probe through the full guest path.
  • On a Loongnix ABI 1.0 runtime with guest GLib 2.58.3, 52 of the 54 selected leaves are present; the GLib 2.60+ g_strv_equal and g_utf8_validate_len symbols do not participate in binding. The 54-call differential, object-boundary, and four-thread probes each pass 20/20 under KZT=0 and KZT=1 with identical hash 3b1b4b6ac4be492d; GDB endpoint and safe-fallback checks also pass.
  • g_int64_hash and g_double_hash produce observably different values between GLib 2.58 and the newer host implementation, so they explicitly remain guest-side and are not part of the 54-function allowlist.

当前边界 / Current limits

  • 本 PR 保持 Draft,glib 保持 experimental。

  • 本 PR 不宣称完整 GLib 或 GObject 原生直通,也不为 Pango/GTK 提供 host GObject object chain。

  • 本 PR 自身的 ABI 1.0 leaf、对象边界、线程、endpoint 和 fallback 已验证;所有新增库族合并后的最终 ABI 1.0 桌面矩阵仍由 WI-2119 统一补充。

  • 临时 probe、GDB 脚本和运行日志未加入产品提交。

  • This PR remains a draft and the glib group remains experimental.

  • It does not claim complete GLib or GObject passthrough and does not provide a host GObject object chain for Pango/GTK.

  • This PR's ABI 1.0 leaf, object-boundary, thread, endpoint, and fallback paths are validated; WI-2119 still tracks the final integrated ABI 1.0 desktop matrix across all new library families.

  • Temporary probes, GDB scripts, and runtime logs are not part of the product commits.

Add the signed-byte, pointer-sized, floating-point, and mixed-register dispatch shapes required by the selected GLib leaf ABI.

The signatures are derived from public GLib 2.80 and 2.88 headers and preserve independent x86_64 integer and XMM argument positions.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Wrap a version-stable subset of GLib functions that consumes only scalar values, caller-owned strings, or caller-owned buffers.

Keep allocators, containers, GType, GObject, GClosure, GIO, and callback-owning APIs on the guest path so native objects and registries cannot enter guest internals.

Preflight only the selected leaf surface and reject native activation when a guest leaf export has no matching host symbol.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Register libglib-2.0.so.0 in a dedicated experimental glib group with the core KZT dependency.

The group activates only the stateless leaf wrapper surface; GObject and GIO remain unregistered and execute entirely as guest libraries.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
@LaurenIsACoder
LaurenIsACoder force-pushed the lauren/kzt-glib-gobject branch from 74e7283 to 42c34eb Compare August 20, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant