Skip to content

Commit 2130e22

Browse files
committed
[EE RPC]: break all RPC binding after 100 retries
applications will no longer hang eternally on a loop. Applications that bind to RPC should check return values of rpc binding functions and throw errors if necesary to avoid the program to continue execution as if server is ok
1 parent a81be1f commit 2130e22

File tree

18 files changed

+94
-29
lines changed

18 files changed

+94
-29
lines changed

.github/workflows/compilation.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: CI
33
on:
44
push:
55
pull_request:
6-
workflow_dispatch:
76
repository_dispatch:
87
types: [run_build]
98

ee/kernel/src/fileio.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <fileio.h>
2323
#include <string.h>
2424
#include <fileio-common.h>
25+
#include <loadfile.h>
2526

2627
#define D(fmt, args...) printf("(%s:%s:%i):" #fmt, __FILE__, __FUNCTION__, __LINE__, ##args)
2728

@@ -50,6 +51,7 @@ int _fio_completion_sema = -1;
5051
#ifdef F_fio_init
5152
int fioInit(void)
5253
{
54+
int bind_retry = 100;
5355
int res;
5456
ee_sema_t sema;
5557
static int _rb_count = 0;
@@ -66,8 +68,10 @@ int fioInit(void)
6668
SifInitRpc(0);
6769

6870
while (((res = SifBindRpc(&_fio_cd, 0x80000001, 0)) >= 0) &&
69-
(_fio_cd.server == NULL))
70-
nopdelay();
71+
(_fio_cd.server == NULL)) {
72+
nopdelay();
73+
if (--bind_retry < 1) return -SCE_EBINDMISS;
74+
}
7175

7276
if (res < 0)
7377
return res;

ee/kernel/src/iopheap.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Review ps2sdk README & LICENSE files for further details.
1010
*/
1111

12+
#include <loadfile.h>
1213
#include "tamtypes.h"
1314
#include "ps2lib_err.h"
1415
#include "kernel.h"
@@ -31,7 +32,7 @@ int _ih_caps = 0;
3132

3233
int SifInitIopHeap()
3334
{
34-
int res;
35+
int res, bind_retry = 100;
3536

3637
static int _rb_count = 0;
3738
if (_rb_count != _iop_reboot_count) {
@@ -46,9 +47,10 @@ int SifInitIopHeap()
4647

4748
SifInitRpc(0);
4849

49-
while ((res = SifBindRpc(&_ih_cd, 0x80000003, 0)) >= 0 && !_ih_cd.server)
50+
while ((res = SifBindRpc(&_ih_cd, 0x80000003, 0)) >= 0 && !_ih_cd.server) {
5051
nopdelay();
51-
52+
if (--bind_retry < 1) return -SCE_EBINDMISS;
53+
}
5254
if (res < 0)
5355
return -E_SIF_RPC_BIND;
5456

ee/kernel/src/loadfile.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int _lf_init = 0;
3939

4040
int SifLoadFileInit()
4141
{
42-
int res;
42+
int res, bind_retry = 100;;
4343
static int _rb_count = 0;
4444
if (_rb_count != _iop_reboot_count) {
4545
_rb_count = _iop_reboot_count;
@@ -52,9 +52,10 @@ int SifLoadFileInit()
5252

5353
SifInitRpc(0);
5454

55-
while ((res = SifBindRpc(&_lf_cd, 0x80000006, 0)) >= 0 && !_lf_cd.server)
55+
while ((res = SifBindRpc(&_lf_cd, 0x80000006, 0)) >= 0 && !_lf_cd.server) {
5656
nopdelay();
57-
57+
if (--bind_retry < 1) return -SCE_EBINDMISS;
58+
}
5859
if (res < 0)
5960
return -E_SIF_RPC_BIND;
6061

ee/network/netman/src/rpc_client.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <malloc.h>
66
#include <netman.h>
77
#include <netman_rpc.h>
8+
#include <loadfile.h>
89

910
#include "rpc_client.h"
1011

@@ -56,7 +57,7 @@ static void NETMAN_TxThread(void *arg);
5657

5758
int NetManInitRPCClient(void){
5859
static const char NetManID[]="NetMan";
59-
int result;
60+
int result, bind_retry = 100;
6061
ee_sema_t SemaData;
6162
ee_thread_t thread;
6263

@@ -88,8 +89,10 @@ int NetManInitRPCClient(void){
8889
return NETMAN_Tx_threadID;
8990
}
9091

91-
while((SifBindRpc(&NETMAN_rpc_cd, NETMAN_RPC_NUMBER, 0)<0)||(NETMAN_rpc_cd.server==NULL))
92+
while((SifBindRpc(&NETMAN_rpc_cd, NETMAN_RPC_NUMBER, 0)<0)||(NETMAN_rpc_cd.server==NULL)) {
93+
if (--bind_retry < 1) return -SCE_EBINDMISS;
9294
nopdelay();
95+
}
9396

9497
if((result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_INIT, 0, NULL, 0, &ReceiveBuffer, sizeof(s32), NULL, NULL))>=0)
9598
{

ee/rpc/ahx/src/ahx_rpc.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <fcntl.h>
2323
#include <unistd.h>
2424
#include <stdio.h>
25+
#include <loadfile.h>
2526
#include "ahx_rpc.h"
2627

2728
static unsigned sbuff[64] __attribute__((aligned (64)));
@@ -51,7 +52,7 @@ int AHX_Init()
5152

5253
// if already init'd, exit
5354
if (ahx_init_done) return 0;
54-
55+
int bind_retry = 100;
5556
// bind rpc
5657
while(1){
5758
int i;
@@ -60,6 +61,7 @@ int AHX_Init()
6061
if (cd0.server != 0) break;
6162
i = 0x10000;
6263
while(i--);
64+
if (--bind_retry < 1) return -SCE_EBINDMISS;
6365
}
6466

6567
SifCallRpc(&cd0,AHX_INIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);

ee/rpc/audsrv/src/audsrv_rpc.c

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sifrpc.h>
1919
#include <tamtypes.h>
2020
#include <string.h>
21+
#include <loadfile.h>
2122
#include <iopheap.h>
2223

2324
#include <audsrv.h>
@@ -353,6 +354,11 @@ int audsrv_init()
353354
}
354355

355356
nopdelay();
357+
358+
if (--bind_retry < 1) {
359+
set_error(AUDSRV_ERR_RPC_FAILED);
360+
return -SCE_EBINDMISS;
361+
}
356362
}
357363

358364
compSema.init_count = 1;

ee/rpc/camera/src/ps2cam_rpc.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <tamtypes.h>
1313
#include <kernel.h>
14+
#include <loadfile.h>
1415
#include <sifrpc.h>
1516
#include <stdio.h>
1617
#include <string.h>
@@ -36,18 +37,20 @@ int sem;
3637

3738
int PS2CamInit(int mode)
3839
{
39-
int ret=0;
40-
int *buf;
40+
int ret = 0;
41+
int *buf;
42+
int bind_retry = 100;
4143
// unsigned int i;
4244
// int timeout = 100000;
4345

4446
if(CamInited)return 0;
4547

4648
SifInitRpc(0);
4749

48-
while (((ret = SifBindRpc(&cdata, PS2_CAM_RPC_ID, 0)) >= 0) && (cdata.server == NULL))
50+
while (((ret = SifBindRpc(&cdata, PS2_CAM_RPC_ID, 0)) >= 0) && (cdata.server == NULL)) {
51+
if (--bind_retry < 1) return -SCE_EBINDMISS;
4952
nopdelay();
50-
53+
}
5154
nopdelay();
5255

5356

ee/rpc/cdvd/src/libcdvd.c

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sifrpc.h>
2727
#include <string.h>
2828
#include <libcdvd.h>
29+
#include <loadfile.h>
2930
#include <stdarg.h>
3031

3132
#include "internal.h"
@@ -121,6 +122,7 @@ extern u32 searchFileRecvBuff;
121122
#ifdef F_sceCdInit
122123
s32 sceCdInit(s32 mode)
123124
{
125+
int bind_retry = 100;
124126
if (_CdSyncS(1))
125127
return 0;
126128
SifInitRpc(0);
@@ -139,6 +141,7 @@ s32 sceCdInit(s32 mode)
139141
break;
140142

141143
nopdelay();
144+
if (--bind_retry < 1) return -SCE_EBINDMISS;
142145
}
143146

144147
bindInit = 0;

ee/rpc/filexio/src/fileXio_rpc.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdlib.h>
2222
#include <stdarg.h>
2323
#include <sys/fcntl.h>
24+
#include <loadfile.h>
2425
#include <sys/stat.h>
2526
#include <ps2sdkapi.h>
2627

@@ -93,7 +94,7 @@ static inline int _unlock(void)
9394
#ifdef F_fileXioInit
9495
int fileXioInit(void)
9596
{
96-
int res;
97+
int res, bind_retry = 100;
9798
ee_sema_t sp;
9899
static int _rb_count = 0;
99100

@@ -114,8 +115,10 @@ int fileXioInit(void)
114115
sp.option = 0;
115116
__lock_sema_id = CreateSema(&sp);
116117

117-
while(((res = SifBindRpc(&__cd0, FILEXIO_IRX, 0)) >= 0) && (__cd0.server == NULL))
118+
while(((res = SifBindRpc(&__cd0, FILEXIO_IRX, 0)) >= 0) && (__cd0.server == NULL)) {
119+
if (--bind_retry < 1) return -SCE_EBINDMISS;
118120
nopdelay();
121+
}
119122

120123
if(res < 0)
121124
return res;

ee/rpc/memorycard/src/libmc.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <tamtypes.h>
1717
#include <kernel.h>
1818
#include <sifrpc.h>
19+
#include <loadfile.h>
1920
#include <string.h>
2021
#include "libmc.h"
2122

@@ -229,7 +230,7 @@ static void mcStoreDir(void* arg)
229230

230231
int mcInit(int type)
231232
{
232-
int ret=0;
233+
int ret = 0, bind_retry = 100;
233234
mcRpcStat_t *rpcStat = (mcRpcStat_t*)UNCACHED_SEG(&g_rdata.rpcStat);
234235
static int _rb_count = 0;
235236

@@ -260,6 +261,7 @@ int mcInit(int type)
260261
}
261262
if(g_cdata.server == NULL)
262263
nopdelay();
264+
if (--bind_retry < 1) return -SCE_EBINDMISS;
263265
}
264266
while (g_cdata.server == NULL);
265267

ee/rpc/mouse/src/libmouse.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdio.h>
1717
#include <tamtypes.h>
1818
#include <sifrpc.h>
19+
#include <loadfile.h>
1920
#include <kernel.h>
2021
#include <string.h>
2122
#include "libmouse.h"
@@ -39,13 +40,13 @@ static union {
3940
static int mouse_init = 0;
4041

4142
int PS2MouseInit(void)
42-
4343
{
44-
if(mouse_init)
45-
{
44+
int bind_retry = 100;
45+
if (mouse_init)
46+
{
4647
printf("PS2Mouse Library already initialised\n");
4748
return 0;
48-
}
49+
}
4950

5051
mouseif.server = NULL;
5152

@@ -54,6 +55,7 @@ int PS2MouseInit(void)
5455
return -1;
5556
}
5657
nopdelay();
58+
if (--bind_retry < 1) return -SCE_EBINDMISS;
5759
} while(!mouseif.server);
5860

5961
mouse_init = 1;

ee/rpc/multitap/src/libmtap.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <tamtypes.h>
1717
#include <string.h>
1818
#include <kernel.h>
19+
#include <loadfile.h>
1920
#include <sifrpc.h>
2021
#include <stdarg.h>
2122

@@ -33,30 +34,36 @@ static int mtapInited = 0;
3334

3435
int mtapInit(void)
3536
{
37+
int bind_retry = 100;
3638
if(mtapInited) return -1;
3739

3840
while(1)
3941
{
4042
if (SifBindRpc(&clientPortOpen, MTAPSERV_PORT_OPEN, 0) < 0) return -1;
4143
if (clientPortOpen.server != 0) break;
44+
if (--bind_retry < 1) return -SCE_EBINDMISS;
4245

43-
nopdelay();
46+
nopdelay();
4447
}
4548

49+
bind_retry = 100;
4650
while(1)
4751
{
4852
if (SifBindRpc(&clientPortClose, MTAPSERV_PORT_CLOSE, 0) < 0) return -1;
4953
if (clientPortClose.server != 0) break;
54+
if (--bind_retry < 1) return -SCE_EBINDMISS;
5055

51-
nopdelay();
56+
nopdelay();
5257
}
5358

59+
bind_retry = 100;
5460
while(1)
5561
{
5662
if (SifBindRpc(&clientGetConnection, MTAPSERV_GET_CONNECTION, 0) < 0) return -1;
5763
if (clientGetConnection.server != 0) break;
64+
if (--bind_retry < 1) return -SCE_EBINDMISS;
5865

59-
nopdelay();
66+
nopdelay();
6067
}
6168

6269
mtapInited = 1;

ee/rpc/pad/src/libpad.c

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdio.h>
2121
#include <string.h>
2222
#include <sifrpc.h>
23+
#include <loadfile.h>
2324
#include <sifcmd.h>
2425
#include "libpad.h"
2526

@@ -299,6 +300,7 @@ padInit(int mode)
299300
// Version check isn't used by default
300301
// int ver;
301302
static int _rb_count = 0;
303+
int bind_retry = 100;
302304

303305
if (_rb_count != _iop_reboot_count)
304306
{
@@ -319,13 +321,16 @@ padInit(int mode)
319321
return -1;
320322
}
321323
nopdelay();
324+
if (--bind_retry < 1) return -SCE_EBINDMISS;
322325
} while(!padsif[0].server);
323326

327+
bind_retry = 100;
324328
do {
325329
if (SifBindRpc(&padsif[1], PAD_BIND_RPC_ID2, 0) < 0) {
326330
return -3;
327331
}
328332
nopdelay();
333+
if (--bind_retry < 1) return -SCE_EBINDMISS;
329334
} while(!padsif[1].server);
330335

331336
// If you require a special version of the padman, check for that here (uncomment)

0 commit comments

Comments
 (0)