sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
ps2sdkapi.h
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
15#ifndef LIBCGLUE_PS2SDKAPI_H
16#define LIBCGLUE_PS2SDKAPI_H
17
18#include <dirent.h>
19#include <inttypes.h>
20#include <sys/stat.h>
21#include <timer.h>
22#include <errno.h>
23#include <sys/socket.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
30
32
33typedef int (*_libcglue_fdman_getfd_cb_t)(void *userdata);
34typedef char *(*_libcglue_fdman_getfilename_cb_t)(void *userdata);
35typedef int (*_libcglue_fdman_close_cb_t)(void *userdata);
36typedef int (*_libcglue_fdman_read_cb_t)(void *userdata, void *buf, int nbytes);
37typedef int (*_libcglue_fdman_lseek_cb_t)(void *userdata, int offset, int whence);
38typedef int64_t (*_libcglue_fdman_lseek64_cb_t)(void *userdata, int64_t offset, int whence);
39typedef int (*_libcglue_fdman_write_cb_t)(void *userdata, const void *buf, int nbytes);
40typedef int (*_libcglue_fdman_ioctl_cb_t)(void *userdata, int request, void *data);
41typedef int (*_libcglue_fdman_ioctl2_cb_t)(void *userdata, int request, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
42typedef int (*_libcglue_fdman_dread_cb_t)(void *userdata, struct dirent *dir);
43typedef int (*_libcglue_fdman_fcntl_f_setfl_cb_t)(void *userdata, int newfl);
44typedef int (*_libcglue_fdman_accept_cb_t)(void *userdata, struct _libcglue_fdman_fd_info_ *info, struct sockaddr *addr, socklen_t *addrlen);
45typedef int (*_libcglue_fdman_bind_cb_t)(void *userdata, const struct sockaddr *my_addr, socklen_t addrlen);
46typedef int (*_libcglue_fdman_connect_cb_t)(void *userdata, const struct sockaddr *serv_addr, socklen_t addrlen);
47typedef int (*_libcglue_fdman_listen_cb_t)(void *userdata, int backlog);
48typedef ssize_t (*_libcglue_fdman_recv_cb_t)(void *userdata, void *buf, size_t len, int flags);
49typedef ssize_t (*_libcglue_fdman_recvfrom_cb_t)(void *userdata, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
50typedef ssize_t (*_libcglue_fdman_recvmsg_cb_t)(void *userdata, struct msghdr *msg, int flags);
51typedef ssize_t (*_libcglue_fdman_send_cb_t)(void *userdata, const void *buf, size_t len, int flags);
52typedef ssize_t (*_libcglue_fdman_sendto_cb_t)(void *userdata, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);
53typedef ssize_t (*_libcglue_fdman_sendmsg_cb_t)(void *userdata, const struct msghdr *msg, int flags);
54typedef int (*_libcglue_fdman_getsockopt_cb_t)(void *userdata, int level, int optname, void *optval, socklen_t *optlen);
55typedef int (*_libcglue_fdman_setsockopt_cb_t)(void *userdata, int level, int optname, const void *optval, socklen_t optlen);
56typedef int (*_libcglue_fdman_shutdown_cb_t)(void *userdata, int how);
57typedef int (*_libcglue_fdman_getpeername_cb_t)(void *userdata, struct sockaddr *name, socklen_t *namelen);
58typedef int (*_libcglue_fdman_getsockname_cb_t)(void *userdata, struct sockaddr *name, socklen_t *namelen);
59
61{
62 _libcglue_fdman_getfd_cb_t getfd;
63 _libcglue_fdman_getfilename_cb_t getfilename;
64 _libcglue_fdman_close_cb_t close;
65 _libcglue_fdman_read_cb_t read;
66 _libcglue_fdman_lseek_cb_t lseek;
67 _libcglue_fdman_lseek64_cb_t lseek64;
68 _libcglue_fdman_write_cb_t write;
69 _libcglue_fdman_ioctl_cb_t ioctl;
70 _libcglue_fdman_ioctl2_cb_t ioctl2;
71 _libcglue_fdman_dread_cb_t dread;
72 _libcglue_fdman_fcntl_f_setfl_cb_t fcntl_f_setfl;
73 _libcglue_fdman_accept_cb_t accept;
74 _libcglue_fdman_bind_cb_t bind;
75 _libcglue_fdman_connect_cb_t connect;
76 _libcglue_fdman_listen_cb_t listen;
77 _libcglue_fdman_recv_cb_t recv;
78 _libcglue_fdman_recvfrom_cb_t recvfrom;
79 _libcglue_fdman_recvmsg_cb_t recvmsg;
80 _libcglue_fdman_send_cb_t send;
81 _libcglue_fdman_sendto_cb_t sendto;
82 _libcglue_fdman_sendmsg_cb_t sendmsg;
83 _libcglue_fdman_getsockopt_cb_t getsockopt;
84 _libcglue_fdman_setsockopt_cb_t setsockopt;
85 _libcglue_fdman_shutdown_cb_t shutdown;
86 _libcglue_fdman_getpeername_cb_t getpeername;
87 _libcglue_fdman_getsockname_cb_t getsockname;
88} _libcglue_fdman_fd_ops_t;
89
91{
92 void *userdata;
93 _libcglue_fdman_fd_ops_t *ops;
94} _libcglue_fdman_fd_info_t;
95
96typedef int (*_libcglue_fdman_open_cb_t)(_libcglue_fdman_fd_info_t *info, const char *buf, int flags, mode_t mode);
97typedef int (*_libcglue_fdman_remove_cb_t)(const char *path);
98typedef int (*_libcglue_fdman_rename_cb_t)(const char *old, const char *new_);
99typedef int (*_libcglue_fdman_mkdir_cb_t)(const char *path, int mode);
100typedef int (*_libcglue_fdman_rmdir_cb_t)(const char *path);
101typedef int (*_libcglue_fdman_stat_cb_t)(const char *path, struct stat *buf);
102typedef int (*_libcglue_fdman_readlink_cb_t)(const char *path, char *buf, size_t bufsiz);
103typedef int (*_libcglue_fdman_symlink_cb_t)(const char *target, const char *linkpath);
104
106{
107 _libcglue_fdman_open_cb_t open;
108 _libcglue_fdman_remove_cb_t remove;
109 _libcglue_fdman_rename_cb_t rename;
110 _libcglue_fdman_mkdir_cb_t mkdir;
111 _libcglue_fdman_rmdir_cb_t rmdir;
112 _libcglue_fdman_stat_cb_t stat;
113 _libcglue_fdman_readlink_cb_t readlink;
114 _libcglue_fdman_symlink_cb_t symlink;
115} _libcglue_fdman_path_ops_t;
116
117extern _libcglue_fdman_path_ops_t *_libcglue_fdman_path_ops;
118
119/* ip4_addr_t/ip_addr_t/socklen_t/struct in_addr are all real types
120 * this file needs but doesn't define itself - <sys/socket.h>, included
121 * above, is their real, canonical home (see its own comments for why -
122 * the short version: this package's own legacy <sys/socket.h> used to
123 * pull them in via a blanket #include <tcpip.h>, a whole parallel,
124 * pre-lwip-migration copy of lwip's own types that conflicts outright
125 * with ps2ip's real lwip headers; replaced with real, minimal,
126 * lwip-compatible definitions). By the time this file's own typedefs
127 * below run, <sys/socket.h> has already provided all of them.
128 *
129 * t_ip_info is different: unlike the above, <sys/socket.h> does NOT
130 * reliably provide it. Which real file that literal include name
131 * resolves to depends on the consuming package's own include_dirs
132 * order - ps2ips (this package's small RPC-client sibling) wants
133 * libcglue's own <sys/socket.h>, but ps2ip (the real lwip stack
134 * package) deliberately puts lwip's own POSIX-compat <sys/socket.h>
135 * (a one-line "#include <lwip/sockets.h>" wrapper) earlier in its own
136 * include_dirs instead, since ps2ip.h/ps2ipee.h/ps2ip_ps2sdk.c need
137 * the real lwip_accept/err_t/pbuf/netif/tcpip chain that only lwip's
138 * own sockets.h transitively provides - see core/ps2ip/ps2.yaml's own
139 * comment. lwip's real sockets.h obviously has no concept of
140 * t_ip_info (a ps2sdk-specific struct, not a POSIX/lwip one), so it
141 * can't be left to <sys/socket.h> to supply here - given its own,
142 * independent, real definition instead, shared with libcglue's
143 * <sys/socket.h> via the same T_IP_INFO_DEFINED guard so whichever of
144 * the two headers is reached first in a given TU wins. */
145#ifndef T_IP_INFO_DEFINED
146#define T_IP_INFO_DEFINED
147typedef struct
148{
149 char netif_name[4];
150 struct in_addr ipaddr;
151 struct in_addr netmask;
152 struct in_addr gw;
153 u32 dhcp_enabled;
154 u32 dhcp_status;
155 u8 hw_addr[8];
156} t_ip_info;
157#endif
158
159typedef int (*_libcglue_fdman_setconfig_cb_t)(const t_ip_info *ip_info);
160typedef int (*_libcglue_fdman_getconfig_cb_t)(char *netif_name, t_ip_info *ip_info);
161typedef void (*_libcglue_fdman_dns_setserver_cb_t)(u8 numdns, const ip_addr_t *dnsserver);
162typedef const ip_addr_t *(*_libcglue_fdman_dns_getserver_cb_t)(u8 numdns);
163typedef int (*_libcglue_fdman_socket_cb_t)(_libcglue_fdman_fd_info_t *info, int domain, int type, int protocol);
164typedef int (*_libcglue_fdman_select_cb_t)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
165
166/* Real, file-scope forward declarations - without these, each `struct
167 * hostent *`/`struct addrinfo *` below (used only inside a function-
168 * pointer parameter list, never given a real definition reachable from
169 * this file) would otherwise each create its OWN, function-scope-only
170 * tag ("declared inside parameter list will not be visible outside of
171 * this definition or declaration"), incompatible with any other real
172 * struct hostent/addrinfo a consumer TU later reaches (e.g. lwip's own
173 * real lwip/netdb.h) - the exact "incompatible pointer type" pattern
174 * already hit and fixed for several other fdman callbacks this
175 * session. One shared tag here instead, real definition supplied
176 * wherever a TU actually needs one (lwip/netdb.h, or the guarded local
177 * copies in ps2ips/src/ps2ipc.c and libcglue/include/netdb.h). */
178struct hostent;
179struct addrinfo;
180
181typedef struct hostent *(*_libcglue_fdman_gethostbyaddr_cb_t)(const void *addr, int len, int type);
182typedef struct hostent *(*_libcglue_fdman_gethostbyname_cb_t)(const char *name);
183typedef int (*_libcglue_fdman_gethostbyname_r_cb_t)(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop);
184typedef void (*_libcglue_fdman_freeaddrinfo_cb_t)(struct addrinfo *ai);
185typedef int (*_libcglue_fdman_getaddrinfo_cb_t)(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res);
186
188{
189 _libcglue_fdman_setconfig_cb_t setconfig;
190 _libcglue_fdman_getconfig_cb_t getconfig;
191 _libcglue_fdman_dns_setserver_cb_t dns_setserver;
192 _libcglue_fdman_dns_getserver_cb_t dns_getserver;
193 _libcglue_fdman_socket_cb_t socket;
194 _libcglue_fdman_select_cb_t select;
195 _libcglue_fdman_gethostbyaddr_cb_t gethostbyaddr;
196 _libcglue_fdman_gethostbyname_cb_t gethostbyname;
197 _libcglue_fdman_gethostbyname_r_cb_t gethostbyname_r;
198 _libcglue_fdman_freeaddrinfo_cb_t freeaddrinfo;
199 _libcglue_fdman_getaddrinfo_cb_t getaddrinfo;
200} _libcglue_fdman_socket_ops_t;
201
202extern _libcglue_fdman_socket_ops_t *_libcglue_fdman_socket_ops;
203
204typedef u32 (*_libcglue_fdman_inet_addr_cb_t)(const char *cp);
205typedef char *(*_libcglue_fdman_inet_ntoa_cb_t)(const ip4_addr_t *addr);
206typedef char *(*_libcglue_fdman_inet_ntoa_r_cb_t)(const ip4_addr_t *addr, char *buf, int buflen);
207typedef int (*_libcglue_fdman_inet_aton_cb_t)(const char *cp, ip4_addr_t *addr);
208
210{
211 _libcglue_fdman_inet_addr_cb_t inet_addr;
212 _libcglue_fdman_inet_ntoa_cb_t inet_ntoa;
213 _libcglue_fdman_inet_ntoa_r_cb_t inet_ntoa_r;
214 _libcglue_fdman_inet_aton_cb_t inet_aton;
215} _libcglue_fdman_inet_ops_t;
216
217extern _libcglue_fdman_inet_ops_t *_libcglue_fdman_inet_ops;
218
219/* Functions from cwd.c */
220extern char __cwd[MAXNAMLEN + 1];
221extern int __path_absolute(const char *in, char *out, int len);
222
223#define PS2_CLOCKS_PER_SEC kBUSCLKBY256 // 576.000
224#define PS2_CLOCKS_PER_MSEC (PS2_CLOCKS_PER_SEC / 1000) // 576
225
226/* Disable the auto start of pthread on init for reducing binary size if not used. */
227#define PS2_DISABLE_AUTOSTART_PTHREAD() \
228 void __libpthreadglue_init() {} \
229 void __libpthreadglue_deinit() {}
230
231/* Namco system 246/256 dont have CDVDFSV module loaded on iop reboot. therefore, any libcglue code calling CDVDMAN RPCs will freeze*/
232#define LIBCGLUE_SUPPORT_NAMCO_SYSTEM_2x6() \
233 void _libcglue_rtc_update() {}
234
235typedef uint64_t ps2_clock_t;
236static inline ps2_clock_t ps2_clock(void) {
237 // DEPRECATED VERSION USE INSTEAD GetTimerSystemTime
238 return (ps2_clock_t)(GetTimerSystemTime() >> 8);
239}
240
241extern s64 _ps2sdk_rtc_offset_from_busclk;
242s64 _libcglue_rtc_get_offset_from_busclk(void);
243extern void _libcglue_rtc_update_impl();
244extern void _libcglue_rtc_update();
245
246// The newlib port does not support 64bit
247// this should have been defined in unistd.h
248typedef int64_t off64_t;
249extern off64_t lseek64(int fd, off64_t offset, int whence);
250
251// Functions to be used related to timezone
252extern void _libcglue_timezone_update_impl();
253extern void _libcglue_timezone_update();
254
255extern void ps2sdk_setTimezone(int timezone);
256extern void ps2sdk_setDaylightSaving(int daylightSaving);
257
258extern _libcglue_fdman_fd_info_t *libcglue_get_fd_info(int fd);
259extern int __libcglue_init_stdio(_libcglue_fdman_fd_info_t *info, int fd);
260
261/* The fd we provide to final user aren't actually the same than IOP's fd
262* so this function allow you to get actual IOP's fd from public fd
263*/
264extern int ps2sdk_get_iop_fd(int fd);
265extern char *ps2sdk_get_iop_filename(int fd);
266extern int _ps2sdk_close(int fd);
267extern int _ps2sdk_dclose(int fd);
268extern int _ps2sdk_read(int fd, void *buf, int nbytes);
269extern int _ps2sdk_lseek(int fd, int offset, int whence);
270extern int64_t _ps2sdk_lseek64(int fd, int64_t offset, int whence);
271extern int _ps2sdk_write(int fd, const void *buf, int nbytes);
272extern int _ps2sdk_ioctl(int fd, int request, void *data);
273extern int _ps2sdk_ioctl2(int fd, int request, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
274extern int _ps2sdk_dread(int fd, struct dirent *dir);
275
276#ifdef __cplusplus
277}
278#endif
279
280#endif /* LIBCGLUE_PS2SDKAPI_H */
struct ip4_addr ip4_addr_t
Definition ps2ip_rpc.h:41
Definition time.h:30
u64 GetTimerSystemTime(void)
Definition timer.c:487