Skip to content

Allow loading the main module via dlopen #5611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zebreus
Copy link
Contributor

@zebreus zebreus commented Jun 18, 2025

Calling dl_open with a NULL path now returns the handle of the main module. The PR also changes the dlopen handle of the main module to 1, because 0 means search everywhere.

Description

@zebreus zebreus requested review from Arshia001 and Copilot June 18, 2025 11:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR allows the main module to be loaded via dlopen by handling a NULL file path argument and updating the main module handle from 0 to 1.

  • Added a branch in dlopen to immediately return the main module handle when the path is NULL.
  • Updated the main module handle constant and the next module handle allocation in the linker.
  • Adjusted comments in both files to reflect the new handle values.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/wasix/src/syscalls/wasix/dlopen.rs Added a null check branch to return the main module handle immediately when dlopen is called with NULL.
lib/wasix/src/state/linker.rs Updated the main module handle from 0 to 1 and adjusted next_module_handle accordingly.
Comments suppressed due to low confidence (2)

lib/wasix/src/state/linker.rs:1016

  • Ensure that the updated main module handle value (from 0 to 1) is adopted consistently across interfacing modules and update any related documentation if necessary.
            next_module_handle: MAIN_MODULE_HANDLE.0 + 1,

lib/wasix/src/syscalls/wasix/dlopen.rs:32

  • Add unit tests for the null path branch to verify that calling dlopen with a NULL path returns the main module handle appropriately.
    if path.is_null() {

@@ -33,6 +28,19 @@ pub fn dlopen<M: MemorySize>(
err_buf_len
);
};

if path.is_null() {
Copy link
Preview

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider refactoring duplicated input string retrieval logic by extracting common functionality into a helper function to improve maintainability.

Copilot uses AI. Check for mistakes.

@zebreus zebreus marked this pull request as draft June 18, 2025 11:55
Copy link

promptless bot commented Jun 18, 2025

✅ No documentation updates required.

@Arshia001
Copy link
Member

@zebreus we don't have the 'search all modules after the given handle' functionality; if you give dlopen a non-zero module handle, it'll look in that module only. It's likely whatever required this change will depend on that functionality as well. Otherwise, lgtm.

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