Rust + CloudABI


#1

Hi

What is the current relationship/dependency between Rust’s libstd and libc? https://nuxi.nl/cloudabi/ has a libc that is modified to use Capsicum’s security model. I am looking into how one could leverage this in Rust.

Is there like a 1:1 mapping between libstd and libc so that one could simply replace libc and change the ffi calls to match that of Cloudabi’s function names and parameters?


#2

This would be possible, yes. Also, work is ongoing to make supporting other platform interfaces (Linux system calls, CloudABI, etc.) easier: https://github.com/rust-lang/rfcs/pull/1502


#3

If they have different function signatures it would require modifying the places in std that call them. It’s desirable for std to have a clean platform abstraction layer where those decisions can be centralized, but it doesn’t really exist today (@jethrogb’s link has some discussion).


#4

Discovering how to adapt std to use the cloudabi capability model does look like an interesting experiment…


#5

Just use FromRawFd and friends. Edit: I suppose you’re worried about a lot of std just not being available, such as TcpListener::bind and File::open etc.


#6

I want to bring this thread back to life. It would be a really interesting experiment to add CloudABI to Rust. CloudABI is also identical across platforms so apparently you can compile once on any platform and run on any platform :slight_smile: However, compared to libc, cloudlibc has very few (~60) functions. Not sure what functions are missing compared to a “normal” libc but am currently looking into that.

Basically you would have one x86_64-unknown-cloudabi target that would run on all OSs supporting CloudABI. Very cool!

Rust’s and CloudABI’s strong security added together would surely make a killer combination!


#7

This would probably be easier once something like Refactoring std for ultimate portability is implemented.


#8

That’s really interesting. When do we start? :smile:


#9

I like this idea. :slight_smile: In the long run, you’d want to fork std so that the interface it exposed was capability friendly, and eventually you’d want folks to develop against this capability oriented std even if they were not meaning to run their code on capsicum.


#10

Here is a FOSDOM talk which introduces cloudabi: https://fosdem.org/2017/schedule/event/cloudabi/

and a talk on 32C3: https://media.ccc.de/v/32c3-7231-cloudabi (this one has better quality and seems to cover the same informations (through I’m still listening) ;=) )

Btw. Rust+CloudABI seems like a really nice idea


#11

I just took a short look at the API and it seems that you have to create a alternative std something like using cfg to add some “additional” parts for capabilities won’t work as some of the syscall’s std uses are not available.

The most simple example is open, the variation of open in CoudABI is very similar to the openat system call, except that the mode parameter takes a different struct which does some more then what the mode parameter in linux open/openat does.

But then I think rust, at some point, needs support for alternative stable std’s anyway. At last if rust wants to take over micro-controllers (!= microprocessors).


#12

Yes, you want allocation, collections, etc. from std but you need io, etc. to go thought a capability controlled library.


#13

There is a listing of more capability-based tooling at https://github.com/dckc/awesome-ocap


#14

Hi there!

I’m the main author of CloudABI. Even though I’m quite interested in Rust, I only found time recently to start experimenting with this. The other day I managed to extend rustc to support CloudABI:

I’m now able to build very simple Rust binaries that don’t use std. I’m slowly working towards getting that to work, but that’s going to take some more time. I’ll post some more instructions here as things stabilise. Stay tuned!


#15

Minor update: compiler changes have all been merged now. The latest nightly compiler should be able to target CloudABI properly.

Right now I’m working on getting fixes for libstd upstreamed. The most important change has been sent out earlier today: https://github.com/rust-lang/rust/pull/47268

Once this pull request gets merged, it’s just a matter of getting all sorts of tiny fixes upstreamed here and there and set up automated continuous integration testing and builds.

It will probably not take long until we can use rustup, cargo, etc. to build Rust code for CloudABI. I’ll post instructions here when that’s possible.