Skip to content

Commit d493438

Browse files
committed
rt: Disable some expensive asserts
1 parent d90a9d3 commit d493438

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

src/rt/rust_task.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,17 @@ rust_task::record_stack_limit() {
673673
record_sp(stk->data + LIMIT_OFFSET + RED_ZONE_SIZE);
674674
}
675675

676+
static bool
677+
sp_in_stk_seg(uintptr_t sp, stk_seg *stk) {
678+
// Not positive these bounds for sp are correct. I think that the first
679+
// possible value for esp on a new stack is stk->end, which points to the
680+
// address before the first value to be pushed onto a new stack. The last
681+
// possible address we can push data to is stk->data. Regardless, there's
682+
// so much slop at either end that we should never hit one of these
683+
// boundaries.
684+
return (uintptr_t)stk->data <= sp && sp <= stk->end;
685+
}
686+
676687
/*
677688
Called by landing pads during unwinding to figure out which
678689
stack segment we are currently running on, delete the others,
@@ -700,6 +711,25 @@ rust_task::config_notify(chan_handle chan) {
700711
notify_chan = chan;
701712
}
702713

714+
/*
715+
Returns true if we're currently running on the Rust stack
716+
*/
717+
bool
718+
rust_task::on_rust_stack() {
719+
uintptr_t sp = get_sp();
720+
bool in_first_segment = sp_in_stk_seg(sp, stk);
721+
if (in_first_segment) {
722+
return true;
723+
} else if (stk->next != NULL) {
724+
// This happens only when calling the upcall to delete
725+
// a stack segment
726+
bool in_second_segment = sp_in_stk_seg(sp, stk->next);
727+
return in_second_segment;
728+
} else {
729+
return false;
730+
}
731+
}
732+
703733
//
704734
// Local Variables:
705735
// mode: C++

src/rt/rust_task.h

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond
198198
void call_on_rust_stack(void *args, void *fn_ptr);
199199
};
200200

201+
// This stuff is on the stack-switching fast path
202+
201203
// Get a rough approximation of the current stack pointer
202204
extern "C" uintptr_t get_sp();
203205

@@ -226,7 +228,8 @@ sanitize_next_sp(uintptr_t next_sp) {
226228

227229
inline void
228230
rust_task::call_on_c_stack(void *args, void *fn_ptr) {
229-
I(thread, on_rust_stack());
231+
// Too expensive to check
232+
// I(thread, on_rust_stack());
230233

231234
next_rust_sp = get_sp();
232235

@@ -252,7 +255,8 @@ rust_task::call_on_c_stack(void *args, void *fn_ptr) {
252255

253256
inline void
254257
rust_task::call_on_rust_stack(void *args, void *fn_ptr) {
255-
I(thread, !on_rust_stack());
258+
// Too expensive to check
259+
// I(thread, !on_rust_stack());
256260
I(thread, next_rust_sp);
257261

258262
next_c_sp = get_sp();
@@ -264,43 +268,14 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) {
264268

265269
inline void
266270
rust_task::return_c_stack() {
267-
I(thread, on_rust_stack());
271+
// Too expensive to check
272+
// I(thread, on_rust_stack());
268273
I(thread, c_stack != NULL);
269274
thread->return_c_stack(c_stack);
270275
c_stack = NULL;
271276
next_c_sp = 0;
272277
}
273278

274-
inline bool
275-
sp_in_stk_seg(uintptr_t sp, stk_seg *stk) {
276-
// Not positive these bounds for sp are correct. I think that the first
277-
// possible value for esp on a new stack is stk->end, which points to the
278-
// address before the first value to be pushed onto a new stack. The last
279-
// possible address we can push data to is stk->data. Regardless, there's
280-
// so much slop at either end that we should never hit one of these
281-
// boundaries.
282-
return (uintptr_t)stk->data <= sp && sp <= stk->end;
283-
}
284-
285-
/*
286-
Returns true if we're currently running on the Rust stack
287-
*/
288-
inline bool
289-
rust_task::on_rust_stack() {
290-
uintptr_t sp = get_sp();
291-
bool in_first_segment = sp_in_stk_seg(sp, stk);
292-
if (in_first_segment) {
293-
return true;
294-
} else if (stk->next != NULL) {
295-
// This happens only when calling the upcall to delete
296-
// a stack segment
297-
bool in_second_segment = sp_in_stk_seg(sp, stk->next);
298-
return in_second_segment;
299-
} else {
300-
return false;
301-
}
302-
}
303-
304279
//
305280
// Local Variables:
306281
// mode: C++

src/rt/rust_task_thread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ rust_task_thread::get_log() {
150150
return _log;
151151
}
152152

153+
// This stuff is on the stack-switching fast path
154+
153155
#ifndef __WIN32__
154156

155157
inline rust_task *

0 commit comments

Comments
 (0)