Skip to content
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

Fix CWD sync #45

Merged
merged 4 commits into from
Nov 13, 2024
Merged

Fix CWD sync #45

merged 4 commits into from
Nov 13, 2024

Conversation

maminrayej
Copy link

@maminrayej maminrayej commented Nov 7, 2024

Fix CWD

CWD of the running binary is kept in two places: libc and the runtime. These two values should be in sync at all times. This rule could be broken though since at the start, libc always assumes that CWD is the root directory, but there are various ways to change the starting CWD of a wasm program, namely:

  • Specifying --dir . changes the CWD to /home
  • Using the cwd WASI annotation in wasmer.toml

That's why libc and runtime could have different opinions as to what CWD is.

This PR adds a synchronization logic to the make_absolute function which calls into the runtime to get the CWD of the program. This only needs to happen once, since any change to this value through chdir will update both libc and the runtime.

libc-bottom-half/sources/chdir.c Show resolved Hide resolved
libc-bottom-half/sources/posix.c Outdated Show resolved Hide resolved
libc-bottom-half/sources/preopens.c Outdated Show resolved Hide resolved
libc-bottom-half/sources/chdir.c Show resolved Hide resolved
Copy link

@syrusakbary syrusakbary left a comment

Choose a reason for hiding this comment

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

I requested to try to not have a fix for this on wasix-libc and try to do it only on the runtime

@maminrayej maminrayej changed the title Fix CWD and find_rel_path logic Fix CWD sync Nov 12, 2024
@maminrayej maminrayej merged commit eae155d into main Nov 13, 2024
1 check passed
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.

4 participants