]> git.proxmox.com Git - wasi-libc.git/commit - Makefile
Add basic emulation of getcwd/chdir (#214)
authorAlex Crichton <alex@alexcrichton.com>
Mon, 30 Nov 2020 20:40:41 +0000 (14:40 -0600)
committerGitHub <noreply@github.com>
Mon, 30 Nov 2020 20:40:41 +0000 (12:40 -0800)
commit5b148b6131f36770f110c24d61adfb1e17fea06a
treeb27e15330e855223c0bfe85a057ebd780ec539bb
parent9083fe84568fb4de76152757abfd216ba34ad908
Add basic emulation of getcwd/chdir (#214)

* Add basic emulation of getcwd/chdir

This commit adds basic emulation of a current working directory to
wasi-libc. The `getcwd` and `chdir` symbols are now implemented and
available for use. The `getcwd` implementation is pretty simple in that
it just copies out of a new global, `__wasilibc_cwd`, which defaults to
`"/"`. The `chdir` implementation is much more involved and has more
ramification, however.

A new function, `make_absolute`, was added to the preopens object. Paths
stored in the preopen table are now always stored as absolute paths
instead of relative paths, and initial relative paths are interpreted as
being relative to `/`. Looking up a path to preopen now always turns it
into an absolute path, relative to the current working directory, and an
appropriate path is then returned.

The signature of `__wasilibc_find_relpath` has changed as well. It now
returns two path components, one for the absolute part and one for the
relative part. Additionally the relative part is always dynamically
allocated since it may no longer be a substring of the original input
path.

This has been tested lightly against the Rust standard library so far,
but I'm not a regular C developer so there's likely a few things to
improve!

* Amortize mallocs made in syscalls

* Avoid size bloat on programs that don't use `chdir`

* Add threading compat

* Collect `link`/`renameat` second path lookup

* Update comments about chdir.c in makefile

* Move definition of `__wasilibc_find_relpath_alloc` to header

* Expand comments

* Document the format of strings a bit more

* Fixup a few issues in path logic

* Fix GitHub Actions
.github/workflows/main.yml
Makefile
expected/wasm32-wasi/defined-symbols.txt
libc-bottom-half/headers/public/wasi/libc-find-relpath.h
libc-bottom-half/sources/chdir.c [new file with mode: 0644]
libc-bottom-half/sources/getcwd.c [new file with mode: 0644]
libc-bottom-half/sources/posix.c
libc-bottom-half/sources/preopens.c
libc-top-half/musl/include/unistd.h