mozilla/rust — pull request #4619 by brson (2013-01-25 00:46:11+00:00)
Title: Some work on freestanding Rust: foreign calls, exchange allocator

r? @graydon

This is some initial work on freestanding Rust I've had sitting around. Needed to write scheduler code in Rust.

It does two major things:

1) Calls to `upcall_call_on_c_stack`/`upcall_call_on_rust_stack` will first check whether they are running in 'task context', i.e. if they can find the task pointer. If not they will call the function directly without switching stacks. This allows the same foreign function declarations to work either with or without the runtime.
2) It rewrites the exchange allocator so that it works outside of task context so that any Rust code can allocate owned types.

My intent was to write the exchange heap allocator in Rust but after I did so I noticed that there are still a number of C++ utility functions that make exchange heap allocations. As a result there is one written in Rust and one written in C++ (that both just use malloc), and they share a global atomic reference count of allocations. This change loses some of the debugging facilities provided by the existing `memory_region` allocator. It may be that this iteration of the allocator is insufficient, but I'd like your opinion.