File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717#include <stdio.h>
1818#include <stdlib.h>
1919#include <sys/lock.h>
20+ #include <reent.h>
2021#include <pspthreadman.h>
2122
2223// Structure representing the lock
@@ -164,6 +165,15 @@ extern struct __lock __lock___arc4random_mutex;
164165
165166void __locks_init ()
166167{
168+ /* Clear newlib's stdio init marker so `__sinit` will reinitialize
169+ * FILE structures and their associated locks the next time stdio
170+ * is used for this reentrancy structure.
171+ *
172+ * Setting `_REENT_CLEANUP(_REENT)` to NULL forces newlib to treat
173+ * stdio as uninitialized, ensuring locks are created deterministically.
174+ */
175+ _REENT_CLEANUP (_REENT ) = NULL ;
176+
167177 _LOCK_T lock_malloc = & __lock___malloc_recursive_mutex ;
168178 _LOCK_T lock_atexit = & __lock___atexit_recursive_mutex ;
169179 _LOCK_T lock_quick_exit = & __lock___at_quick_exit_mutex ;
You can’t perform that action at this time.
0 commit comments