Skip to content

Commit de66119

Browse files
committed
---
yaml --- r: 12275 b: refs/heads/master c: e185888 h: refs/heads/master i: 12273: a5332c6 12271: f607373 v: v3
1 parent 3f02c47 commit de66119

30 files changed

+523
-242
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 987bc2362926d0672a01e8d5964940743df48cb6
2+
refs/heads/master: e1858882a49bf0666d4ffb3f45989ac9dbe9c843
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ for the parameter list, as in `{|| ...}`.
919919
Partial application is done using the `bind` keyword in Rust.
920920

921921
~~~~
922-
let daynum = bind vec::position_elem(["mo", "tu", "we", "th",
922+
let daynum = bind vec::position_elem(["mo", "tu", "we", "do",
923923
"fr", "sa", "su"], _);
924924
~~~~
925925

trunk/mk/rt.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ RUNTIME_CS_$(1) := \
6464
rt/rust_port_selector.cpp \
6565
rt/circular_buffer.cpp \
6666
rt/isaac/randport.cpp \
67+
rt/rust_srv.cpp \
6768
rt/rust_kernel.cpp \
6869
rt/rust_shape.cpp \
6970
rt/rust_abi.cpp \

trunk/src/rt/circular_buffer.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ circular_buffer::circular_buffer(rust_kernel *kernel, size_t unit_sz) :
1212
_unread(0),
1313
_buffer((uint8_t *)kernel->malloc(_buffer_sz, "circular_buffer")) {
1414

15-
assert(unit_sz && "Unit size must be larger than zero.");
15+
A(kernel, unit_sz, "Unit size must be larger than zero.");
1616

1717
KLOG(kernel, mem, "new circular_buffer(buffer_sz=%d, unread=%d)"
1818
"-> circular_buffer=0x%" PRIxPTR,
1919
_buffer_sz, _unread, this);
2020

21-
assert(_buffer && "Failed to allocate buffer.");
21+
A(kernel, _buffer, "Failed to allocate buffer.");
2222
}
2323

2424
circular_buffer::~circular_buffer() {
2525
KLOG(kernel, mem, "~circular_buffer 0x%" PRIxPTR, this);
26-
assert(_buffer);
27-
assert(_unread == 0 && "didn't expect bytes in the circular buffer");
28-
26+
I(kernel, _buffer);
27+
W(kernel, _unread == 0,
28+
"freeing circular_buffer with %d unread bytes", _unread);
2929
kernel->free(_buffer);
3030
}
3131

3232
size_t
3333
circular_buffer::initial_size() {
34-
assert(unit_sz > 0);
34+
I(kernel, unit_sz > 0);
3535
return INITIAL_CIRCULAR_BUFFER_SIZE_IN_UNITS * unit_sz;
3636
}
3737

@@ -40,8 +40,8 @@ circular_buffer::initial_size() {
4040
*/
4141
void
4242
circular_buffer::transfer(void *dst) {
43-
assert(dst);
44-
assert(_unread <= _buffer_sz);
43+
I(kernel, dst);
44+
I(kernel, _unread <= _buffer_sz);
4545

4646
uint8_t *ptr = (uint8_t *) dst;
4747

@@ -53,13 +53,13 @@ circular_buffer::transfer(void *dst) {
5353
} else {
5454
head_sz = _buffer_sz - _next;
5555
}
56-
assert(_next + head_sz <= _buffer_sz);
56+
I(kernel, _next + head_sz <= _buffer_sz);
5757
memcpy(ptr, _buffer + _next, head_sz);
5858

5959
// Then copy any other items from the beginning of the buffer
60-
assert(_unread >= head_sz);
60+
I(kernel, _unread >= head_sz);
6161
size_t tail_sz = _unread - head_sz;
62-
assert(head_sz + tail_sz <= _buffer_sz);
62+
I(kernel, head_sz + tail_sz <= _buffer_sz);
6363
memcpy(ptr + head_sz, _buffer, tail_sz);
6464
}
6565

@@ -69,9 +69,9 @@ circular_buffer::transfer(void *dst) {
6969
*/
7070
void
7171
circular_buffer::enqueue(void *src) {
72-
assert(src);
73-
assert(_unread <= _buffer_sz);
74-
assert(_buffer);
72+
I(kernel, src);
73+
I(kernel, _unread <= _buffer_sz);
74+
I(kernel, _buffer);
7575

7676
// Grow if necessary.
7777
if (_unread == _buffer_sz) {
@@ -82,20 +82,20 @@ circular_buffer::enqueue(void *src) {
8282
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
8383
_unread, _next, _buffer_sz, unit_sz);
8484

85-
assert(_unread < _buffer_sz);
86-
assert(_unread + unit_sz <= _buffer_sz);
85+
I(kernel, _unread < _buffer_sz);
86+
I(kernel, _unread + unit_sz <= _buffer_sz);
8787

8888
// Copy data
8989
size_t dst_idx = _next + _unread;
90-
assert(dst_idx >= _buffer_sz || dst_idx + unit_sz <= _buffer_sz);
90+
I(kernel, dst_idx >= _buffer_sz || dst_idx + unit_sz <= _buffer_sz);
9191
if (dst_idx >= _buffer_sz) {
9292
dst_idx -= _buffer_sz;
9393

94-
assert(_next >= unit_sz);
95-
assert(dst_idx <= _next - unit_sz);
94+
I(kernel, _next >= unit_sz);
95+
I(kernel, dst_idx <= _next - unit_sz);
9696
}
9797

98-
assert(dst_idx + unit_sz <= _buffer_sz);
98+
I(kernel, dst_idx + unit_sz <= _buffer_sz);
9999
memcpy(&_buffer[dst_idx], src, unit_sz);
100100
_unread += unit_sz;
101101

@@ -109,17 +109,17 @@ circular_buffer::enqueue(void *src) {
109109
*/
110110
void
111111
circular_buffer::dequeue(void *dst) {
112-
assert(unit_sz > 0);
113-
assert(_unread >= unit_sz);
114-
assert(_unread <= _buffer_sz);
115-
assert(_buffer);
112+
I(kernel, unit_sz > 0);
113+
I(kernel, _unread >= unit_sz);
114+
I(kernel, _unread <= _buffer_sz);
115+
I(kernel, _buffer);
116116

117117
KLOG(kernel, mem,
118118
"circular_buffer dequeue "
119119
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
120120
_unread, _next, _buffer_sz, unit_sz);
121121

122-
assert(_next + unit_sz <= _buffer_sz);
122+
I(kernel, _next + unit_sz <= _buffer_sz);
123123
if (dst != NULL) {
124124
memcpy(dst, &_buffer[_next], unit_sz);
125125
}
@@ -153,7 +153,7 @@ circular_buffer::grow() {
153153
void
154154
circular_buffer::shrink() {
155155
size_t new_buffer_sz = _buffer_sz / 2;
156-
assert(initial_size() <= new_buffer_sz);
156+
I(kernel, initial_size() <= new_buffer_sz);
157157
KLOG(kernel, mem, "circular_buffer is shrinking to %d bytes",
158158
new_buffer_sz);
159159
void *new_buffer = kernel->malloc(new_buffer_sz,

trunk/src/rt/memory_region.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ void *memory_region::get_data(alloc_header *ptr) {
2323
return (void*)((char *)ptr + HEADER_SIZE);
2424
}
2525

26-
memory_region::memory_region(rust_env *env, bool synchronized) :
27-
_env(env), _parent(NULL), _live_allocations(0),
28-
_detailed_leaks(env->detailed_leaks),
26+
memory_region::memory_region(rust_srv *srv, bool synchronized) :
27+
_srv(srv), _parent(NULL), _live_allocations(0),
28+
_detailed_leaks(srv->env->detailed_leaks),
2929
_synchronized(synchronized) {
3030
}
3131

3232
memory_region::memory_region(memory_region *parent) :
33-
_env(parent->_env), _parent(parent), _live_allocations(0),
33+
_srv(parent->_srv), _parent(parent), _live_allocations(0),
3434
_detailed_leaks(parent->_detailed_leaks),
3535
_synchronized(parent->_synchronized) {
3636
}
@@ -55,11 +55,11 @@ void memory_region::free(void *mem) {
5555
# endif
5656

5757
if (_live_allocations < 1) {
58-
assert(false && "live_allocs < 1");
58+
_srv->fatal("live_allocs < 1", __FILE__, __LINE__, "");
5959
}
6060
release_alloc(mem);
6161
maybe_poison(mem);
62-
::free(alloc);
62+
_srv->free(alloc);
6363
}
6464

6565
void *
@@ -74,7 +74,7 @@ memory_region::realloc(void *mem, size_t orig_size) {
7474
# endif
7575

7676
size_t size = orig_size + HEADER_SIZE;
77-
alloc_header *newMem = (alloc_header *)::realloc(alloc, size);
77+
alloc_header *newMem = (alloc_header *)_srv->realloc(alloc, size);
7878

7979
# if RUSTRT_TRACK_ALLOCATIONS >= 1
8080
assert(newMem->magic == MAGIC);
@@ -88,7 +88,7 @@ memory_region::realloc(void *mem, size_t orig_size) {
8888
alloc->index, _allocation_list[alloc->index], alloc);
8989
printf("realloc: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n",
9090
(uintptr_t) get_data(alloc), alloc->tag);
91-
assert(false && "not in allocation_list");
91+
_srv->fatal("not in allocation_list", __FILE__, __LINE__, "");
9292
}
9393
else {
9494
_allocation_list[newMem->index] = newMem;
@@ -105,7 +105,7 @@ void *
105105
memory_region::malloc(size_t size, const char *tag, bool zero) {
106106
size_t old_size = size;
107107
size += HEADER_SIZE;
108-
alloc_header *mem = (alloc_header *)::malloc(size);
108+
alloc_header *mem = (alloc_header *)_srv->malloc(size);
109109

110110
# if RUSTRT_TRACK_ALLOCATIONS >= 1
111111
mem->magic = MAGIC;
@@ -166,8 +166,8 @@ memory_region::~memory_region() {
166166
# endif
167167

168168
if (_live_allocations > 0) {
169-
fprintf(stderr, "%s\n", msg);
170-
assert(false);
169+
_srv->fatal(msg, __FILE__, __LINE__,
170+
"%d objects", _live_allocations);
171171
}
172172
if (_synchronized) { _lock.unlock(); }
173173
}
@@ -184,7 +184,7 @@ memory_region::release_alloc(void *mem) {
184184
if (_allocation_list[alloc->index] != alloc) {
185185
printf("free: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n",
186186
(uintptr_t) get_data(alloc), alloc->tag);
187-
assert(false && "not in allocation_list");
187+
_srv->fatal("not in allocation_list", __FILE__, __LINE__, "");
188188
}
189189
else {
190190
// printf("freed index %d\n", index);
@@ -222,7 +222,7 @@ memory_region::claim_alloc(void *mem) {
222222
void
223223
memory_region::maybe_poison(void *mem) {
224224

225-
if (!_env->poison_on_free)
225+
if (!_srv->env->poison_on_free)
226226
return;
227227

228228
# if RUSTRT_TRACK_ALLOCATIONS >= 1

trunk/src/rt/memory_region.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// hugely expensive and should only be used as a last resort.
2323
#define RUSTRT_TRACK_ALLOCATIONS 0
2424

25-
struct rust_env;
25+
class rust_srv;
2626

2727
class memory_region {
2828
private:
@@ -42,7 +42,7 @@ class memory_region {
4242
inline alloc_header *get_header(void *mem);
4343
inline void *get_data(alloc_header *);
4444

45-
rust_env *_env;
45+
rust_srv *_srv;
4646
memory_region *_parent;
4747
int _live_allocations;
4848
array_list<alloc_header *> _allocation_list;
@@ -58,7 +58,7 @@ class memory_region {
5858
void claim_alloc(void *mem);
5959

6060
public:
61-
memory_region(rust_env *env, bool synchronized);
61+
memory_region(rust_srv *srv, bool synchronized);
6262
memory_region(memory_region *parent);
6363
void *malloc(size_t size, const char *tag, bool zero = true);
6464
void *calloc(size_t size, const char *tag);

trunk/src/rt/rust.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
7575
update_log_settings(crate_map, env->logspec);
7676
check_claims = env->check_claims;
7777

78-
rust_kernel *kernel = new rust_kernel(env);
78+
rust_srv *srv = new rust_srv(env);
79+
rust_kernel *kernel = new rust_kernel(srv);
7980
rust_sched_id sched_id = kernel->create_scheduler(env->num_sched_threads);
8081
rust_scheduler *sched = kernel->get_scheduler_by_id(sched_id);
8182
rust_task *root_task = sched->create_task(NULL, "main");
@@ -92,9 +93,10 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
9293
root_task->start((spawn_fn)main_fn, NULL, args->args);
9394
root_task = NULL;
9495

95-
int ret = kernel->wait_for_exit();
96+
int ret = kernel->run();
9697
delete args;
9798
delete kernel;
99+
delete srv;
98100

99101
free_env(env);
100102

0 commit comments

Comments
 (0)