Fix MyThread NULL _reent pointer - #2263
Open
LeonLeBreton wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, while playing around with the Rosalina source code, I noticed that using any stdio function that format strings (like sprintf, snprintf, etc.), when we want to formats something, make the console crash (so this is ok:
snprintf(buf, sizeof(buf), "OK");, and this make the console crash:snprintf(buf, sizeof(buf), "CRASH %u", 1u);).After long research, I found out that the problem is that is because of MyThread.c that don't initialize the TLS variables correctly.
libctru/source/internal.h
reent, need for newlib to work correctly, is not initialized in MyThread.c, so when we call snprintf with a format string that needs to access the reent structure, it crashes because the pointer is NULL.
So I modified MyThread.c to initialize the reent pointer using
(u32)_impure_ptr, and now snprintf works correctly. (I only added that, but the best would be to initialize the whole structure correctly).If you want to test the crash, here is a simple snippet that you can add to the Rosalina menu.c:
Trigger the entry immediately crash the console without the fix, and with the fix it works correctly.