Skip to content

Commit d37d1e6

Browse files
authored
Merge pull request #357 from fjtrujy/fix_InitLockAPI
libcglue: clarify resetting newlib stdio init in __locks_init
2 parents 800ce35 + 8d1e801 commit d37d1e6

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/libcglue/lock.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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

165166
void __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;

0 commit comments

Comments
 (0)