Browse Source

Increase stack size and add more detailed logs

The default stack size is super small: 4096 bytes. This was causing the
stack to overflow during normal processing. This was also not detected,
so it corrupted the heap and led to odd behavior or aborts.

See this long comment for more details and explanation:
https://github.com/Meziu/ctru-rs/pull/42#issuecomment-1030724973

I bumped the stack size to 2MiB, which is the default for Rust's std
threads. I have a few ideas to fix the underlying issues here (add a
guard struct like std does for stack overflows, move 3ds-specific stuff
like affinity into std but keep the impl in ctru-rs via linker hacks).

Also added some more logging.
pull/42/head
AzureMarker 3 years ago
parent
commit
368cf8bc0c
No known key found for this signature in database
GPG Key ID: 47A133F3BF9D03D3
  1. 7
      ctru-rs/examples/futures-tokio-basic.rs

7
ctru-rs/examples/futures-tokio-basic.rs

@ -28,16 +28,21 @@ fn main() {
let runtime_thread = ctru::thread::Builder::new() let runtime_thread = ctru::thread::Builder::new()
.affinity(1) .affinity(1)
.stack_size(0x200000)
.spawn(move || { .spawn(move || {
runtime.block_on(async move { runtime.block_on(async move {
println!("Start of future");
let mut wake_time = tokio::time::Instant::now() + Duration::from_secs(1); let mut wake_time = tokio::time::Instant::now() + Duration::from_secs(1);
let mut iteration = 0;
loop { loop {
println!("Start of loop");
let sleep_future = tokio::time::sleep_until(wake_time); let sleep_future = tokio::time::sleep_until(wake_time);
tokio::select! { tokio::select! {
_ = &mut exit_receiver => break, _ = &mut exit_receiver => break,
_ = sleep_future => { _ = sleep_future => {
println!("Tick"); println!("Tick {}", iteration);
iteration += 1;
wake_time += Duration::from_secs(1); wake_time += Duration::from_secs(1);
} }
} }

Loading…
Cancel
Save