Merge remote-tracking branch 'brson/io' into incoming
Conflicts: mk/rt.mk src/libcore/run.rs
This commit is contained in:
commit
6c478c7de8
42 changed files with 1399 additions and 347 deletions
|
|
@ -27,11 +27,11 @@ rust_opaque_box *boxed_region::malloc(type_desc *td, size_t body_size) {
|
|||
if (live_allocs) live_allocs->prev = box;
|
||||
live_allocs = box;
|
||||
|
||||
LOG(rust_get_current_task(), box,
|
||||
/*LOG(rust_get_current_task(), box,
|
||||
"@malloc()=%p with td %p, size %lu==%lu+%lu, "
|
||||
"align %lu, prev %p, next %p\n",
|
||||
box, td, total_size, sizeof(rust_opaque_box), body_size,
|
||||
td->align, box->prev, box->next);
|
||||
td->align, box->prev, box->next);*/
|
||||
|
||||
return box;
|
||||
}
|
||||
|
|
@ -50,9 +50,9 @@ rust_opaque_box *boxed_region::realloc(rust_opaque_box *box,
|
|||
if (new_box->next) new_box->next->prev = new_box;
|
||||
if (live_allocs == box) live_allocs = new_box;
|
||||
|
||||
LOG(rust_get_current_task(), box,
|
||||
/*LOG(rust_get_current_task(), box,
|
||||
"@realloc()=%p with orig=%p, size %lu==%lu+%lu",
|
||||
new_box, box, total_size, sizeof(rust_opaque_box), new_size);
|
||||
new_box, box, total_size, sizeof(rust_opaque_box), new_size);*/
|
||||
|
||||
return new_box;
|
||||
}
|
||||
|
|
@ -74,15 +74,15 @@ void boxed_region::free(rust_opaque_box *box) {
|
|||
// double frees (kind of).
|
||||
assert(box->td != NULL);
|
||||
|
||||
LOG(rust_get_current_task(), box,
|
||||
/*LOG(rust_get_current_task(), box,
|
||||
"@free(%p) with td %p, prev %p, next %p\n",
|
||||
box, box->td, box->prev, box->next);
|
||||
box, box->td, box->prev, box->next);*/
|
||||
|
||||
if (box->prev) box->prev->next = box->next;
|
||||
if (box->next) box->next->prev = box->prev;
|
||||
if (live_allocs == box) live_allocs = box->next;
|
||||
|
||||
if (env->poison_on_free) {
|
||||
if (poison_on_free) {
|
||||
memset(box_body(box), 0xab, box->td->size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ struct rust_env;
|
|||
* a type descr which describes the payload (what follows the header). */
|
||||
class boxed_region {
|
||||
private:
|
||||
rust_env *env;
|
||||
bool poison_on_free;
|
||||
memory_region *backing_region;
|
||||
rust_opaque_box *live_allocs;
|
||||
|
||||
|
|
@ -41,8 +41,8 @@ private:
|
|||
boxed_region& operator=(const boxed_region& rhs);
|
||||
|
||||
public:
|
||||
boxed_region(rust_env *e, memory_region *br)
|
||||
: env(e)
|
||||
boxed_region(memory_region *br, bool poison_on_free)
|
||||
: poison_on_free(poison_on_free)
|
||||
, backing_region(br)
|
||||
, live_allocs(NULL)
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "sync/sync.h"
|
||||
#include "memory_region.h"
|
||||
#include "rust_env.h"
|
||||
|
||||
#if RUSTRT_TRACK_ALLOCATIONS >= 3
|
||||
#include <execinfo.h>
|
||||
|
|
@ -35,15 +34,19 @@ void *memory_region::get_data(alloc_header *ptr) {
|
|||
return (void*)((char *)ptr + HEADER_SIZE);
|
||||
}
|
||||
|
||||
memory_region::memory_region(rust_env *env, bool synchronized) :
|
||||
_env(env), _parent(NULL), _live_allocations(0),
|
||||
_detailed_leaks(env->detailed_leaks),
|
||||
memory_region::memory_region(bool synchronized,
|
||||
bool detailed_leaks,
|
||||
bool poison_on_free) :
|
||||
_parent(NULL), _live_allocations(0),
|
||||
_detailed_leaks(detailed_leaks),
|
||||
_poison_on_free(poison_on_free),
|
||||
_synchronized(synchronized) {
|
||||
}
|
||||
|
||||
memory_region::memory_region(memory_region *parent) :
|
||||
_env(parent->_env), _parent(parent), _live_allocations(0),
|
||||
_parent(parent), _live_allocations(0),
|
||||
_detailed_leaks(parent->_detailed_leaks),
|
||||
_poison_on_free(parent->_poison_on_free),
|
||||
_synchronized(parent->_synchronized) {
|
||||
}
|
||||
|
||||
|
|
@ -241,7 +244,7 @@ memory_region::claim_alloc(void *mem) {
|
|||
void
|
||||
memory_region::maybe_poison(void *mem) {
|
||||
|
||||
if (!_env->poison_on_free)
|
||||
if (!_poison_on_free)
|
||||
return;
|
||||
|
||||
# if RUSTRT_TRACK_ALLOCATIONS >= 1
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ private:
|
|||
inline alloc_header *get_header(void *mem);
|
||||
inline void *get_data(alloc_header *);
|
||||
|
||||
rust_env *_env;
|
||||
memory_region *_parent;
|
||||
int _live_allocations;
|
||||
array_list<alloc_header *> _allocation_list;
|
||||
const bool _detailed_leaks;
|
||||
const bool _poison_on_free;
|
||||
const bool _synchronized;
|
||||
lock_and_signal _lock;
|
||||
|
||||
|
|
@ -75,7 +75,8 @@ private:
|
|||
memory_region& operator=(const memory_region& rhs);
|
||||
|
||||
public:
|
||||
memory_region(rust_env *env, bool synchronized);
|
||||
memory_region(bool synchronized,
|
||||
bool detailed_leaks, bool poison_on_free);
|
||||
memory_region(memory_region *parent);
|
||||
void *malloc(size_t size, const char *tag);
|
||||
void *realloc(void *mem, size_t size);
|
||||
|
|
|
|||
|
|
@ -856,6 +856,63 @@ rust_initialize_global_state() {
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" CDECL memory_region*
|
||||
rust_new_memory_region(uintptr_t synchronized,
|
||||
uintptr_t detailed_leaks,
|
||||
uintptr_t poison_on_free) {
|
||||
return new memory_region((bool)synchronized,
|
||||
(bool)detailed_leaks,
|
||||
(bool)poison_on_free);
|
||||
}
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_delete_memory_region(memory_region *region) {
|
||||
delete region;
|
||||
}
|
||||
|
||||
extern "C" CDECL boxed_region*
|
||||
rust_new_boxed_region(memory_region *region,
|
||||
uintptr_t poison_on_free) {
|
||||
return new boxed_region(region, poison_on_free);
|
||||
}
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_delete_boxed_region(boxed_region *region) {
|
||||
delete region;
|
||||
}
|
||||
|
||||
extern "C" CDECL rust_opaque_box*
|
||||
rust_boxed_region_malloc(boxed_region *region, type_desc *td, size_t size) {
|
||||
return region->malloc(td, size);
|
||||
}
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_boxed_region_free(boxed_region *region, rust_opaque_box *box) {
|
||||
region->free(box);
|
||||
}
|
||||
|
||||
typedef void *(rust_try_fn)(void*, void*);
|
||||
|
||||
extern "C" CDECL uintptr_t
|
||||
rust_try(rust_try_fn f, void *fptr, void *env) {
|
||||
try {
|
||||
f(fptr, env);
|
||||
} catch (uintptr_t token) {
|
||||
assert(token != 0);
|
||||
return token;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_begin_unwind(uintptr_t token) {
|
||||
#ifndef __WIN32__
|
||||
throw token;
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ rust_sched_loop::rust_sched_loop(rust_scheduler *sched, int id, bool killed) :
|
|||
sched(sched),
|
||||
log_lvl(log_debug),
|
||||
min_stack_size(kernel->env->min_stack_size),
|
||||
local_region(kernel->env, false),
|
||||
local_region(false, kernel->env->detailed_leaks, kernel->env->poison_on_free),
|
||||
// FIXME #2891: calculate a per-scheduler name.
|
||||
name("main")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
|
|||
kernel(sched_loop->kernel),
|
||||
name(name),
|
||||
list_index(-1),
|
||||
boxed(sched_loop->kernel->env, &local_region),
|
||||
boxed(&local_region, sched_loop->kernel->env->poison_on_free),
|
||||
local_region(&sched_loop->local_region),
|
||||
unwinding(false),
|
||||
total_stack_sz(0),
|
||||
|
|
|
|||
|
|
@ -165,3 +165,14 @@ extern "C" CDECL TwoDoubles
|
|||
rust_dbg_extern_identity_TwoDoubles(TwoDoubles u) {
|
||||
return u;
|
||||
}
|
||||
|
||||
// Generates increasing port numbers for network testing
|
||||
extern "C" CDECL uintptr_t
|
||||
rust_dbg_next_port() {
|
||||
static lock_and_signal dbg_port_lock;
|
||||
static uintptr_t next_port = 9600;
|
||||
scoped_lock with(dbg_port_lock);
|
||||
uintptr_t this_port = next_port;
|
||||
next_port += 1;
|
||||
return this_port;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,7 +293,13 @@ upcall_rust_personality(int version,
|
|||
s_rust_personality_args args = {(_Unwind_Reason_Code)0,
|
||||
version, actions, exception_class,
|
||||
ue_header, context};
|
||||
rust_task *task = rust_get_current_task();
|
||||
rust_task *task = rust_try_get_current_task();
|
||||
|
||||
if (task == NULL) {
|
||||
// Assuming we're running with the new scheduler
|
||||
upcall_s_rust_personality(&args);
|
||||
return args.retval;
|
||||
}
|
||||
|
||||
// The personality function is run on the stack of the
|
||||
// last function that threw or landed, which is going
|
||||
|
|
@ -330,8 +336,12 @@ upcall_del_stack() {
|
|||
// needs to acquire the value of the stack pointer
|
||||
extern "C" CDECL void
|
||||
upcall_reset_stack_limit() {
|
||||
rust_task *task = rust_get_current_task();
|
||||
task->reset_stack_limit();
|
||||
rust_task *task = rust_try_get_current_task();
|
||||
if (task != NULL) {
|
||||
task->reset_stack_limit();
|
||||
} else {
|
||||
// We must be in a newsched task
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -224,4 +224,12 @@ rust_uv_free_ip4_addr
|
|||
rust_uv_free_ip6_addr
|
||||
rust_call_nullary_fn
|
||||
rust_initialize_global_state
|
||||
|
||||
rust_dbg_next_port
|
||||
rust_new_memory_region
|
||||
rust_delete_memory_region
|
||||
rust_new_boxed_region
|
||||
rust_delete_boxed_region
|
||||
rust_boxed_region_malloc
|
||||
rust_boxed_region_free
|
||||
rust_try
|
||||
rust_begin_unwind
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue