PS2SDK
PS2 Homebrew Libraries
iopheap.c
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # (C)2002, Vzzrzzn
7 # (c) 2003 Marcus R. Brown (mrbrown@0xd6.org)
8 # Licenced under Academic Free License version 2.0
9 # Review ps2sdk README & LICENSE files for further details.
10 */
11 
12 #include "tamtypes.h"
13 #include "ps2lib_err.h"
14 #include "kernel.h"
15 #include "sifrpc.h"
16 #include "sifcmd.h"
17 #include "string.h"
18 #include <iopcontrol.h>
19 #include "iopheap-common.h"
20 
21 #include "iopheap.h"
22 
23 extern SifRpcClientData_t _ih_cd;
24 
25 #ifdef F_SifInitIopHeap
26 SifRpcClientData_t _ih_cd;
27 
28 int SifInitIopHeap()
29 {
30  int res;
32  SifExitIopHeap();
33 
34  if (_ih_cd.server)
35  return 0;
36 
37  sceSifInitRpc(0);
38 
39  while ((res = sceSifBindRpc(&_ih_cd, 0x80000003, 0)) >= 0 && !_ih_cd.server)
40  nopdelay();
41 
42  if (res < 0)
43  return -E_SIF_RPC_BIND;
44 
45  return 0;
46 }
47 #endif
48 
49 #ifdef F_SifExitIopHeap
50 void SifExitIopHeap()
51 {
52  memset(&_ih_cd, 0, sizeof _ih_cd);
53 }
54 #endif
55 
56 #ifdef F_SifAllocIopHeap
57 void *SifAllocIopHeap(int size)
58 {
59  union
60  {
61  int size;
62  u32 addr;
63  } arg;
64 
65  if (SifInitIopHeap() < 0)
66  return NULL;
67 
68  arg.size = size;
69 
70  if (sceSifCallRpc(&_ih_cd, 1, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
71  return NULL;
72 
73  return (void *)arg.addr;
74 }
75 #endif
76 
77 #ifdef F_SifFreeIopHeap
78 int SifFreeIopHeap(void *addr)
79 {
80  union
81  {
82  void *addr;
83  int result;
84  } arg;
85 
86  if (SifInitIopHeap() < 0)
87  return -E_LIB_API_INIT;
88 
89  arg.addr = addr;
90 
91  if (sceSifCallRpc(&_ih_cd, 2, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
92  return -E_SIF_RPC_CALL;
93 
94  return arg.result;
95 }
96 #endif
97 
98 #ifdef F_SifLoadIopHeap
99 int SifLoadIopHeap(const char *path, void *addr)
100 {
101  struct _iop_load_heap_arg arg;
102 
103  if (SifInitIopHeap() < 0)
104  return -E_LIB_API_INIT;
105 
106  arg.p.addr = addr;
107  strlcpy(arg.path, path, sizeof(arg.path));
108 
109  if (sceSifCallRpc(&_ih_cd, 3, 0, &arg, sizeof arg, &arg, 4, NULL, NULL) < 0)
110  return -E_SIF_RPC_CALL;
111 
112  return arg.p.result;
113 }
114 #endif
kernel.h
ps2lib_err.h
E_LIB_API_INIT
@ E_LIB_API_INIT
Definition: ps2lib_err.h:68
E_SIF_RPC_CALL
@ E_SIF_RPC_CALL
Definition: ps2lib_err.h:88
iopcontrol.h
iopheap.h
E_SIF_RPC_BIND
@ E_SIF_RPC_BIND
Definition: ps2lib_err.h:86
tamtypes.h
HasIopRebootedSinceLastCall
static int HasIopRebootedSinceLastCall(void)
Definition: iopcontrol.h:47
iopheap-common.h
_iop_load_heap_arg
Definition: iopheap-common.h:25
t_SifRpcClientData
Definition: sifrpc-common.h:134