Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std threads support #46

Merged
merged 14 commits into from
Mar 1, 2022
Merged

Use std threads support #46

merged 14 commits into from
Mar 1, 2022

Conversation

AzureMarker
Copy link
Member

@AzureMarker AzureMarker commented Feb 10, 2022

@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.

ctru-rs/examples/thread-basic.rs Outdated Show resolved Hide resolved
@ian-h-chamberlain
Copy link
Member

ian-h-chamberlain commented Feb 10, 2022

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
Copy link
Member Author

AzureMarker commented Feb 11, 2022

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
Copy link
Member

@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 Meziu/rust-horizon@ef21c1c

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

@AzureMarker
Copy link
Member Author

AzureMarker commented Feb 13, 2022

@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: #48

@AzureMarker AzureMarker changed the title Implement std threads support Use std threads support Feb 14, 2022
The thread list syscall has a bug which causes the process to become a
zombie. See #48.
# Conflicts:
#	ctru-rs/src/services/ps.rs
@Meziu Meziu merged commit df845c5 into master Mar 1, 2022
@AzureMarker AzureMarker deleted the feature/std-threads branch March 2, 2022 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge our thread code back into std?
3 participants