summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <astrohavoc@gmail.com>2022-10-22 18:47:07 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-11 00:26:55 -0500
commit65ba328539c3a6f0fa26a7dc182c2de450d836ea (patch)
tree89fe5f950f0e2139c7eddd74620837812e7d22b1
parentd2d6dfd271b442891b2384203c59d72c7caca5b0 (diff)
downloadhaskell-65ba328539c3a6f0fa26a7dc182c2de450d836ea.tar.gz
rts: RtsStartup: chdir to PWD on wasm32
This patch adds a wasm32-specific behavior to RtsStartup logic. When the PWD environment variable is present, we chdir() to it first. The point is to workaround an issue in wasi-libc: it's currently not possible to specify the initial working directory, it always defaults to / (in the virtual filesystem mapped from some host directory). For some use cases this is sufficient, but there are some other cases (e.g. in the testsuite) where the program needs to access files outside.
-rw-r--r--rts/RtsStartup.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c
index 46749163dc..9495eb3b43 100644
--- a/rts/RtsStartup.c
+++ b/rts/RtsStartup.c
@@ -252,6 +252,17 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
stg_exit(1);
}
+#if defined(wasm32_HOST_ARCH)
+ char *pwd = getenv("PWD");
+ if (pwd != NULL) {
+ int chdir_result = chdir(pwd);
+ if (chdir_result != 0) {
+ errorBelch("hs_init_ghc: chdir(%s) failed with %d", pwd, chdir_result);
+ stg_exit(1);
+ }
+ }
+#endif
+
setlocale(LC_CTYPE,"");
/* Initialise the stats department, phase 0 */