Skip to content

Commit afab9a5

Browse files
authored
implement __getreent syscall (#151)
* use getreent syscall * use global reent macro also fixes libogc build
1 parent 4f37028 commit afab9a5

File tree

6 files changed

+21
-88
lines changed

6 files changed

+21
-88
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ OGCOBJ := \
146146
gx.o gu.o gu_psasm.o audio.o cache.o decrementer.o \
147147
message.o card.o aram.o depackrnc.o decrementer_handler.o \
148148
depackrnc1.o dsp.o si.o tpl.o ipc.o ogc_crt0.o \
149-
console_font_8x16.o timesupp.o lock_supp.o newlibc.o usbgecko.o usbmouse.o \
149+
console_font_8x16.o timesupp.o lock_supp.o usbgecko.o usbmouse.o \
150150
sbrk.o malloc_lock.o kprintf.o stm.o aes.o sha.o ios.o es.o isfs.o usb.o network_common.o \
151151
sdgecko_io.o sdgecko_buf.o gcsd.o argv.o network_wii.o wiisd.o conf.o usbstorage.o \
152152
texconv.o wiilaunch.o

gc/ogc/lwp_threads.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ extern vu32 _context_switch_want;
6666
extern vu32 _thread_dispatch_disable_level;
6767

6868
extern wd_cntrl _lwp_wd_timeslice;
69-
extern void **__lwp_thr_libc_reent;
7069
extern lwp_queue _lwp_thr_ready[];
7170

7271
void __thread_dispatch();

libogc/lwp_threads.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <stdlib.h>
22
#include <stdio.h>
33
#include <string.h>
4+
#include <sys/iosupport.h>
5+
46
#include "asm.h"
57
#include "processor.h"
68
#include "lwp_stack.h"
@@ -35,7 +37,6 @@ vu32 _thread_dispatch_disable_level;
3537

3638
wd_cntrl _lwp_wd_timeslice;
3739
u32 _lwp_ticks_per_timeslice = 0;
38-
void **__lwp_thr_libc_reent = NULL;
3940
lwp_queue _lwp_thr_ready[LWP_MAXPRIORITIES];
4041

4142
static void (*_lwp_exitfunc)(void);
@@ -47,10 +48,6 @@ extern void _cpu_context_restore(void *);
4748
extern void _cpu_context_save_fp(void *);
4849
extern void _cpu_context_restore_fp(void *);
4950

50-
extern int __libc_create_hook(lwp_cntrl *,lwp_cntrl *);
51-
extern int __libc_start_hook(lwp_cntrl *,lwp_cntrl *);
52-
extern int __libc_delete_hook(lwp_cntrl *, lwp_cntrl *);
53-
5451
extern void kprintf(const char *str, ...);
5552

5653
#ifdef _LWPTHREADS_DEBUG
@@ -80,6 +77,13 @@ void __lwp_dumpcontext_fp(lwp_cntrl *thrA,lwp_cntrl *thrB)
8077
}
8178
#endif
8279

80+
struct _reent* __SYSCALL(getreent)()
81+
{
82+
if ( _thr_executing == NULL || _thr_executing->libc_reent == NULL) return _GLOBAL_REENT;
83+
84+
return _thr_executing->libc_reent;
85+
}
86+
8387
/*
8488
void __lwp_getthreadlist(lwp_obj **thrs)
8589
{
@@ -193,10 +197,6 @@ void __thread_dispatch(void)
193197
_thr_executing = heir;
194198
_CPU_ISR_Restore(level);
195199

196-
if(__lwp_thr_libc_reent) {
197-
exec->libc_reent = *__lwp_thr_libc_reent;
198-
*__lwp_thr_libc_reent = heir->libc_reent;
199-
}
200200
#ifdef _DEBUG
201201
_cpu_context_switch_ex((void*)&exec->context,(void*)&heir->context);
202202
#else
@@ -617,7 +617,7 @@ u32 __lwp_thread_init(lwp_cntrl *thethread,void *stack_area,u32 stack_size,u32 p
617617
thethread->res_cnt = 0;
618618
__lwp_thread_setpriority(thethread,prio);
619619

620-
__libc_create_hook(_thr_executing,thethread);
620+
thethread->libc_reent = NULL;
621621

622622
return 1;
623623
}
@@ -646,7 +646,10 @@ void __lwp_thread_close(lwp_cntrl *thethread)
646646
thethread->budget_algo = LWP_CPU_BUDGET_ALGO_NONE;
647647
_CPU_ISR_Restore(level);
648648

649-
__libc_delete_hook(_thr_executing,thethread);
649+
struct _reent *ptr = thethread->libc_reent;
650+
_reclaim_reent(ptr);
651+
free(ptr);
652+
thethread->libc_reent = NULL;
650653

651654
if(__lwp_thread_isallocatedfp(thethread))
652655
__lwp_thread_deallocatefp();
@@ -701,7 +704,12 @@ u32 __lwp_thread_start(lwp_cntrl *thethread,void* (*entry)(void*),void *arg)
701704
thethread->arg = arg;
702705
__lwp_thread_loadenv(thethread);
703706
__lwp_thread_ready(thethread);
704-
__libc_start_hook(_thr_executing,thethread);
707+
struct _reent *ptr= (struct _reent*)calloc(1,sizeof(struct _reent));
708+
if(!ptr) abort();
709+
710+
_REENT_INIT_PTR((ptr));
711+
712+
thethread->libc_reent = ptr;
705713
return 1;
706714
}
707715
return 0;

libogc/lwp_threads.inl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ static __inline__ void __lwp_thread_unblock(lwp_cntrl *thethread)
6060
__lwp_thread_clearstate(thethread,LWP_STATES_BLOCKED);
6161
}
6262

63-
static __inline__ void** __lwp_thread_getlibcreent(void)
64-
{
65-
return __lwp_thr_libc_reent;
66-
}
67-
68-
static __inline__ void __lwp_thread_setlibcreent(void **libc_reent)
69-
{
70-
__lwp_thr_libc_reent = libc_reent;
71-
}
72-
7363
static __inline__ bool __lwp_thread_isswitchwant(void)
7464
{
7565

libogc/newlibc.c

Lines changed: 0 additions & 62 deletions
This file was deleted.

libogc/system.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ extern void __irq_init(void);
186186
extern void __lwp_start_multitasking(void);
187187
extern void __timesystem_init(void);
188188
extern void __memlock_init(void);
189-
extern void __libc_init(int);
190189

191190
extern void __libogc_malloc_lock( struct _reent *ptr );
192191
extern void __libogc_malloc_unlock( struct _reent *ptr );
@@ -1102,7 +1101,6 @@ void SYS_Init(void)
11021101
IRQ_Request(IRQ_PI_RSW,__RSWHandler,NULL);
11031102
__MaskIrq(IRQMASK(IRQ_PI_RSW));
11041103
#endif
1105-
__libc_init(1);
11061104
__lwp_thread_startmultitasking();
11071105
_CPU_ISR_Restore(level);
11081106
}

0 commit comments

Comments
 (0)