Git Product home page Git Product logo

Comments (12)

sunfishcode avatar sunfishcode commented on July 26, 2024 1

I started sketching out a minimal version of my idea above, but many of the changes are relatively mechanical and I ended up with a complete, though still rough, draft: #54.

from wasi-libc.

sunfishcode avatar sunfishcode commented on July 26, 2024 1

This is now fixed, in #230.

from wasi-libc.

Ericson2314 avatar Ericson2314 commented on July 26, 2024

So WASI has no working directory. https://github.com/musec/libpreopen emulates it instead. https://github.com/musec/libpreopen probably need to wrap even *at functions so that AT_FDCWD can work.

from wasi-libc.

sunfishcode avatar sunfishcode commented on July 26, 2024

That's right. The WASI API layer has no concept of AT_FDCWD, which would imply an ambient authority to access the current directory, but it would be possible to emulate with more libpreopen-like wrappers.

from wasi-libc.

Ericson2314 avatar Ericson2314 commented on July 26, 2024

Issue already exists musec/libpreopen#11 .

from wasi-libc.

Ericson2314 avatar Ericson2314 commented on July 26, 2024

Ah I see the libraries are vendored in. @sunfishcode if git submodule is too much of a pain, would you be open to git subtree? Insofar that there is an upstream issue it would be nice to land the feature both places.

from wasi-libc.

sunfishcode avatar sunfishcode commented on July 26, 2024

We do have numerous local changes to libpreopen, so it's not trivial to do. At a high level, libpreopen is architected to work in a Capsicum-like environment where it's a library on top of libc. However in WASI libc, we're using it as part of the libc, which changes how some things work.

If anyone wants to implement this in upstream libpreopen, I'm happy to update WASI's vendored copy. That said, this feature seems like it will be a little tricky to do as a library on top of libc. It would want to intercept openat so that it can handle AT_FDCWD, but it still needs to be able to call the underlying openat in libc. This is something we could more easily do with libpreopen being part of libc.

For example, we could do this:

  • Rename the existing openat to __wasilibc_nocwd_openat (or something) in libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c
  • Define a new openat which just does this:
    • if the dirfd is AT_FDCWD, call open
    • otherwise call __wasilibc_nocwd_openat

from wasi-libc.

Ericson2314 avatar Ericson2314 commented on July 26, 2024

Yeah fair point about this interposition being such a pain with C having no namespacing.

from wasi-libc.

Ericson2314 avatar Ericson2314 commented on July 26, 2024

I almost want to go rewrite with https://gitlab.redox-os.org/redox-os/relibc, haha.

from wasi-libc.

emaste avatar emaste commented on July 26, 2024

It's straightforward (if a bit ugly) to intercept *at and conditionally pass through to the real function, using dlsym and RTLD_NEXT. I might have a look at implementing this during a FreeBSD hackathon in two weeks.

from wasi-libc.

sunfishcode avatar sunfishcode commented on July 26, 2024

That's a clever idea. WASI libc doesn't support dynamic linking yet though, so for our purposes here, we'll still need some other approach.

from wasi-libc.

Ericson2314 avatar Ericson2314 commented on July 26, 2024

@emaste it would also be interesting to use CPP / configure script to prefix the function names. that would work for static linking too to some extent.

from wasi-libc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.