rust3ds / ctru-rs

Rust wrapper for libctru
https://rust3ds.github.io/ctru-rs/
Other
119 stars 17 forks source link

Use std threads support #46

Closed AzureMarker closed 2 years ago

AzureMarker commented 2 years ago

@Meziu @ian-h-chamberlain

Closes #45

Requires:

Feels good to delete a bunch of code.

I tried using cargo 3ds test with these changes though and got some weird linker errors. It looks like libctru is included twice, but pthread-3ds isn't at all? I'll try debugging more but let me know if you see issues. Edit: The test issues are fixed now.

ian-h-chamberlain commented 2 years ago

I tried using cargo 3ds test with these changes though and got some weird linker errors. It looks like libctru is included twice, but pthread-3ds isn't at all? I'll try debugging more but let me know if you see issues.

Were you trying to cargo 3ds test without specifying a package or --lib ? I don't think it works yet for --example or for ctru-sys which will get built by default. I'd like to fix these eventually but for now cargo 3ds test --package ctru-rs --lib should work at least.

libctru is included twice

I think there's something to this stemming from the fact that cargo-3ds adds RUSTFLAGS for linking libctru, and ctru-rs also does in its build script. I'll open an issue to investigate on cargo-3ds

AzureMarker commented 2 years ago

Were you trying to cargo 3ds test without specifying a package or --lib ?

This is probably the reason.

Edit: most of the errors are gone, but there's a few more left (will investigate - probably just need stubs):

$ cargo 3ds test --package ctru-rs --lib
...
          /opt/devkitpro/devkitARM/bin/../lib/gcc/arm-none-eabi/11.2.0/../../../../arm-none-eabi/bin/ld: /home/mark/media/CLionProjects/ctru-rs/target/armv6k-nintendo-3ds/debug/deps/libstd-2a5199004e11d454.rlib(std-2a5199004e11d454.std.6d7770c6-cgu.11.rcgu.o): in function `std::sys::unix::process::process_inner::<impl std::sys::unix::process::process_common::Command>::do_exec':
          /home/mark/media/CLionProjects/rust-horizon/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/sys/unix/process/process_unix.rs:336: undefined reference to `pthread_sigmask'
          /opt/devkitpro/devkitARM/bin/../lib/gcc/arm-none-eabi/11.2.0/../../../../arm-none-eabi/bin/ld: /home/mark/media/CLionProjects/ctru-rs/target/armv6k-nintendo-3ds/debug/deps/libstd-2a5199004e11d454.rlib(std-2a5199004e11d454.std.6d7770c6-cgu.4.rcgu.o): in function `std::sys::unix::os::home_dir::fallback':
          /home/mark/media/CLionProjects/rust-horizon/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/sys/unix/os.rs:609: undefined reference to `getuid'
          /opt/devkitpro/devkitARM/bin/../lib/gcc/arm-none-eabi/11.2.0/../../../../arm-none-eabi/bin/ld: /home/mark/media/CLionProjects/rust-horizon/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/sys/unix/os.rs:608: undefined reference to `getpwuid_r'
ian-h-chamberlain commented 2 years ago

@AzureMarker make sure your deps are up-to-date – pthread_sigmask at least should be present in the latest pthread-3ds and the others I think are no longer needed in the latest horizon-std as of https://github.com/Meziu/rust-horizon/commit/ef21c1c010c91476eb50f0765e640b09ea8af998

I recall seeing the same link errors I think until I did a cargo update and pulled latest std

AzureMarker commented 2 years ago

@ian-h-chamberlain I tried the test command again after updating everything and it works! I also don't see any panic messages in the console (thanks to std threads). Some odd happens though if I run it a bunch of times. When exiting the 5th run, I get an ARM exception: prefetch abort (kernel panic). I haven't debugged this at all (just reproduced it), so it might be related to the std threads, or it's always been there, but that was weird.

Edit: this happens on other examples as well. Interestingly, the "Fault status" is "Debug event" and it's an exception on core 1 (sys core, though that makes sense since the error says kernel panic).

Edit 2: I noticed in Luma3DS's process list that there's zombie 3dsx_app processes when you open/close a program a few times. It panics when there are 4 zombies and you close the 5th 3dsx_app process.

Edit 3: I opened a new issue for this: https://github.com/Meziu/ctru-rs/issues/48