sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
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#include "sifarg.h"
21
22#include "iopheap.h"
23
24extern SifRpcClientData_t _ih_cd;
25
26SifRpcClientData_t _ih_cd;
27
28int SifInitIopHeap()
29{
30 int res;
31 if (HasIopRebootedSinceLastCall())
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
48void SifExitIopHeap()
49{
50 memset(&_ih_cd, 0, sizeof _ih_cd);
51}
52
53void *SifAllocIopHeap(int size)
54{
55 typedef union
56 {
57 int size;
58 u32 addr;
59 } arg_t;
60 SIF_ARG(arg_t, arg);
61
62 if (SifInitIopHeap() < 0)
63 return NULL;
64
65 arg->size = size;
66
67 if (sceSifCallRpc(&_ih_cd, 1, 0, arg, 4, arg, 4, NULL, NULL) < 0)
68 return NULL;
69
70 return (void *)arg->addr;
71}
72
73int SifFreeIopHeap(void *addr)
74{
75 typedef union
76 {
77 void *addr;
78 int result;
79 } arg_t;
80 SIF_ARG(arg_t, arg);
81
82 if (SifInitIopHeap() < 0)
83 return -E_LIB_API_INIT;
84
85 arg->addr = addr;
86
87 if (sceSifCallRpc(&_ih_cd, 2, 0, arg, 4, arg, 4, NULL, NULL) < 0)
88 return -E_SIF_RPC_CALL;
89
90 return arg->result;
91}
92
93int SifLoadIopHeap(const char *path, void *addr)
94{
95 SIF_ARG(struct _iop_load_heap_arg, arg);
96
97 if (SifInitIopHeap() < 0)
98 return -E_LIB_API_INIT;
99
100 arg->p.addr = addr;
101 strlcpy(arg->path, path, sizeof(arg->path));
102
103 if (sceSifCallRpc(&_ih_cd, 3, 0, arg, sizeof *arg, arg, 4, NULL, NULL) < 0)
104 return -E_SIF_RPC_CALL;
105
106 return arg->p.result;
107}
@ E_LIB_API_INIT
Definition ps2lib_err.h:69
@ E_SIF_RPC_CALL
Definition ps2lib_err.h:89
@ E_SIF_RPC_BIND
Definition ps2lib_err.h:87