-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathiopheap.c
More file actions
130 lines (102 loc) · 2.55 KB
/
iopheap.c
File metadata and controls
130 lines (102 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# (C)2002, Vzzrzzn
# (c) 2003 Marcus R. Brown (mrbrown@0xd6.org)
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
*/
#include <loadfile.h>
#include "tamtypes.h"
#include "ps2lib_err.h"
#include "kernel.h"
#include "sifrpc.h"
#include "sifcmd.h"
#include "string.h"
#include "iopheap-common.h"
#include "iopheap.h"
#define IH_C_BOUND 0x0001
extern int _iop_reboot_count;
extern SifRpcClientData_t _ih_cd;
extern int _ih_caps;
#ifdef F_SifInitIopHeap
SifRpcClientData_t _ih_cd;
int _ih_caps = 0;
int SifInitIopHeap()
{
int res, bind_retry = 100;
static int _rb_count = 0;
if (_rb_count != _iop_reboot_count) {
_rb_count = _iop_reboot_count;
memset(&_ih_cd, 0, sizeof _ih_cd);
_ih_caps = 0;
memset(&_ih_caps, 0, sizeof _ih_caps);
}
if (_ih_caps)
return 0;
SifInitRpc(0);
while ((res = SifBindRpc(&_ih_cd, 0x80000003, 0)) >= 0 && !_ih_cd.server) {
nopdelay();
if (--bind_retry < 1) return -SCE_EBINDMISS;
}
if (res < 0)
return -E_SIF_RPC_BIND;
_ih_caps |= IH_C_BOUND;
return 0;
}
#endif
#ifdef F_SifExitIopHeap
void SifExitIopHeap()
{
_ih_caps = 0;
memset(&_ih_caps, 0, sizeof _ih_caps);
}
#endif
#ifdef F_SifAllocIopHeap
void *SifAllocIopHeap(int size)
{
union
{
int size;
u32 addr;
} arg;
if (SifInitIopHeap() < 0)
return NULL;
arg.size = size;
if (SifCallRpc(&_ih_cd, 1, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
return NULL;
return (void *)arg.addr;
}
#endif
#ifdef F_SifFreeIopHeap
int SifFreeIopHeap(void *addr)
{
union
{
void *addr;
int result;
} arg;
if (SifInitIopHeap() < 0)
return -E_LIB_API_INIT;
arg.addr = addr;
if (SifCallRpc(&_ih_cd, 2, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
return -E_SIF_RPC_CALL;
return arg.result;
}
#endif
#ifdef F_SifLoadIopHeap
int SifLoadIopHeap(const char *path, void *addr)
{
struct _iop_load_heap_arg arg;
if (SifInitIopHeap() < 0)
return -E_LIB_API_INIT;
arg.p.addr = addr;
strncpy(arg.path, path, LIH_PATH_MAX - 1);
arg.path[LIH_PATH_MAX - 1] = 0;
if (SifCallRpc(&_ih_cd, 3, 0, &arg, sizeof arg, &arg, 4, NULL, NULL) < 0)
return -E_SIF_RPC_CALL;
return arg.p.result;
}
#endif