Skip to content

LATX, fix: correct native wrapper ABIs and loader semantics - #393

Merged
LaurenIsACoder merged 3 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/native-wrapper-abi-fixes
Aug 13, 2026
Merged

LATX, fix: correct native wrapper ABIs and loader semantics#393
LaurenIsACoder merged 3 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/native-wrapper-abi-fixes

Conversation

@LaurenIsACoder

Copy link
Copy Markdown
Contributor

Summary

  • correct native libdl/libc wrapper semantics for link maps, symbol versions, error state, namespaces, and path expansion
  • align X11, XCB, Xt, GL, EGL, GLX, and Vulkan wrapper signatures with their native ABIs
  • harden callback and proc-address bridging so guest code never receives an unwrapped native entry point
  • keep generated native-call types and shared dispatchers consistent with the corrected declarations

Problem

LATX native-library forwarding depends on compact signatures that describe argument widths, return classes, and aggregate passing rules. Several wrapper entries used incorrect signatures, including truncated 64-bit values, missing parameters, pointer returns represented as integers, floating-point return classes for integer cookies, and incomplete 16-byte XCB iterator handling. These mismatches can corrupt arguments or return values before the native library is entered.

The dynamic-loader wrappers also mishandled parts of the dl* contract. Native link maps were read through the wrong pointer level, dlvsym discarded its version, dlerror was shared and non-consuming, non-base dlmopen namespaces were silently ignored, and path token expansion used fixed-size stack storage. Managed handles could consequently return the wrong link map, resolve the wrong symbol version, leak stale error state across threads, or overwrite memory during path expansion.

Dynamic graphics entry-point lookup had related bridging gaps. Missing wrapper metadata could be dereferenced, extension fallback names could lose their canonical bridge key, and some callback/proc-address functions could expose native function pointers directly to translated code.

Changes

Loader semantics

  • retrieve RTLD_DI_LINKMAP through the required pointer result
  • preserve symbol versions and explicit handles when forwarding dlsym and dlvsym
  • translate managed handles for dlinfo and lazily establish their guest link maps
  • make loader error state thread-local and consume it with dlerror
  • reject unsupported dlmopen namespaces instead of weakening namespace isolation
  • replace fixed-size dlopen path buffers with checked dynamic expansion
  • serialize TB bridge lookup and insertion and reject conflicting duplicate bindings

Native ABI forwarding

  • correct argument counts, widths, pointer returns, and status returns across X11, XCB, Xt, GL, GLX, and Vulkan
  • forward 64-bit GL offsets, sizes, handles, and GLX drawables without truncation
  • return 16-byte XCB iterators through both integer return registers
  • preserve XCB cookie return classes and error-pointer arguments
  • add the shared dispatcher forms required by the corrected signatures

Callback and proc-address bridging

  • use the correct callback ABI for AMD debug output, EGL blob caches, Xt event handlers, and MESA program callbacks
  • require a native provider before returning a custom graphics wrapper
  • return NULL when wrapper metadata or a custom target is unavailable
  • retain canonical extension names when constructing Vulkan bridges
  • release dynamically allocated proc-address wrapper state during teardown

Impact

Native calls now receive the same argument and return layout described by their public C APIs. Loader calls preserve versioning, error, and link-map semantics, while dynamic graphics entry points remain inside the translated bridge boundary.

Validation

  • corrected wrapper declarations were checked against the corresponding public native prototypes
  • every active compact signature has a matching dispatcher declaration and implementation
  • generated wrapper type headers pass GNU99 syntax validation in both libc configuration branches
  • loader, callback, proc-address, and generated-table consistency checks pass

@LaurenIsACoder
LaurenIsACoder marked this pull request as ready for review August 13, 2026 03:09
Comment thread target/i386/latx/context/wrappedlibc.c Outdated
@@ -3536,29 +3625,28 @@ int init_x86dlfun(void);
int init_x86dlfun(void)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ABI 1.0的)x86dlfun在wrappedlibdl.c里已经有“一份”基础设施,(ABI 2.0)的x86dlfun能否让wrappedlibc.c复用wrappedlibdl.c已有的代码?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以,已按这个方向调整。现在将 guest dl* 入口解析和 dlprivate_t 初始化抽到 x86dlfun.c,wrappedlibdl.c 与 wrappedlibc.c 共用。ABI 1.0 保持 libdl.so.2 → libc.so.6 的查找顺序;ABI 2.0 保持 libc.so.6 → libdl.so.2 的查找顺序,并在公共初始化后继续执行 KZT 初始化。见 e07822b

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,my_dlopen、my_dlmopen、my_dlerror、my_dlsym、my_dlclose、my_dladdr、my_dladdr1、my_dlvsym、my_dlinfo也可以只保留“一份”。

@LaurenIsACoder LaurenIsACoder Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按这个方向进一步收敛。现在这 9 个 my_dl* 函数、dlprivate 生命周期函数和内部 helper 都只在 wrappedlibdl.c 保留一份,两种 ABI 均编译该公共实现。ABI 1.0 由 wrappedlibdl.c 条件注册 libdl wrapper,ABI 2.0 仍由 libc 注册;两者只在公共初始化中保留 provider 查找顺序以及 ABI 2.0 的 KZT 后置初始化差异。整理并同步最新主线后的对应提交为 483be7a

@LaurenIsACoder
LaurenIsACoder force-pushed the lauren/native-wrapper-abi-fixes branch from 9b1837a to 6dc6e53 Compare August 13, 2026 08:31
Correct native link-map handling, preserve dlvsym and dlinfo semantics, bound dlopen path expansion, and make dlerror state thread-local. Serialize TB bridge registration, keep generated dlfcn mappings aligned, and scope guest CPU-state forwarding to the paths that require it.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Align X11, XCB, Xt, GL, GLX, EGL, and Vulkan signatures with their native prototypes. Preserve wide scalar and aggregate arguments, bridge custom callbacks and proc-address results, and keep generated tables and shared dispatchers consistent.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Resolve guest dlfcn entry points through one provider helper and compile one shared implementation for both ABI modes. Keep only provider order, ABI-specific registration, and ABI 2.0 KZT initialization conditional.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
@LaurenIsACoder
LaurenIsACoder force-pushed the lauren/native-wrapper-abi-fixes branch from 6dc6e53 to 483be7a Compare August 13, 2026 11:16
@LaurenIsACoder
LaurenIsACoder merged commit ce06d61 into lat-opensource:master Aug 13, 2026
20 checks passed
@LaurenIsACoder
LaurenIsACoder deleted the lauren/native-wrapper-abi-fixes branch August 13, 2026 11:22
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.

2 participants