IPC (SDK)
This is an old revision of this page, as edited by Hallowizer (talk | contribs) at 03:01, 17 January 2022. It may differ significantly from the current revision. |
IPC is the SDK library that provides functions for communication with IOS. It seems to also mirror some IOS syscalls, suggesting that IOS was originally planned to run on the Broadway.
Public functions
Signature | Description |
---|---|
int IPCCltInit(void)
|
Initializes the library. Returns an error code. |
int IOS_OpenAsync(char *path, int mode, void (*callback)(int, void *), void *userData)
|
Calls IOS_Open, calling callback when a response is received. May return an error code if something fails before sending the request.
|
int IOS_Open(char *path, int mode)
|
Calls IOS_Open and blocks until a response is received. Returns an error code, or an FD for the opened file. |
int IOS_CloseAsync(int fd, void (*callback)(int, void *), void *userData)
|
Calls IOS_Close, calling callback when a response is received. May return an error code if something fails before sending the request.
|
int IOS_Close(int fd)
|
Calls IOS_Close and blocks until a response is received. Returns an error code. |
int IOS_ReadAsync(int fd, char *data, int len, void (*callback)(int, void *), void *userData)
|
Calls IOS_Read, calling callback when a response is received. May return an error code if something fails before sending the request.
|
int IOS_Read(int fd, char *data, int len)
|
Calls IOS_Read and blocks until a response is received. Returns an error code. |
int IOS_WriteAsync(int fd, char *data, int len, void (*callback)(int, void *), void *userData)
|
Calls IOS_Write, calling callback when a response is received. May return an error code if something fails before sending the request.
|
int IOS_Write(int fd, char *data, int len)
|
Calls IOS_Write and blocks until a response is received. Returns an error code. |
int IOS_SeekAsync(int fd, int offset, SeekMode mode, void (*callback)(int, void *), void *userData)
|
Calls IOS_Seek, calling callback when a response is received. May return an error code if something fails before sending the request.
|
int IOS_IoctlAsync(int fd, int request, char *in, int inSize, char *out, int outSize, void (*callback)(int, void *), void *userData)
|
Calls IOS_Ioctl, calling callback when a response is received. May return an error code if something fails before sending the request.
|
int IOS_Ioctl(int fd, int request, char *in, int inSize, char *out, int outSize)
|
Calls IOS_Ioctl and blocks until a response is received. Returns an error code. |
int IOS_IoctlvAsync(int fd, int request, int inCount, int ioCount, struct IOVector *vectors, void (*callback)(int, void *), void *userData)
|
Calls IOS_Ioctlv, calling callback when a response is received. May return an error code if something fails before sending the request.
|
int IOS_Ioctlv(int fd, int request, int inCount, int ioCount, struct IOVector *vectors)
|
Calls IOS_Ioctlv and blocks until a response is received. Returns an error code. |
int IOS_IoctlvReboot(int fd, int request, int inCount, int ioCount, struct IOVector *vectors)
|
Calls IOS_Ioctlv with the relaunch flag and blocks until a response is received. The purpose of the relaunch flag is unknown.
|
int iosCreateHeap(void *ptr, int size)
|
Creates a heap and returns the heapId .
|
void *iosAllocAligned(int heapId, int size, int align)
|
Allocates size bytes from heap heapId , plus however many are needed for the base pointer to be aligned to align bytes. align must be a power of 2. Returns the base pointer.
|
int iosFree(int heapId, void *ptr)
|
Frees ptr back into heap heapId . Returns an error code.
|
Error codes
In addition to these error codes, any error returned by IOS can be returned from a blocking function.
Number | Description |
---|---|
0 | No error. This is returned from async functions if the request was successfully sent. |
-4 | General memory error. Returned when there is not enough stack space, or when improperly freeing memory. |
-22 | Not enough memory in the heap |
All of the IPC functions include code to return error -4 if the heap does not have enough memory, but the error -22 code takes priority over it; this probably means error -22 was added later.
Message wrapper
IPC wraps IOS messages around a wrapper to store user data.
struct IOSRequestWrapper { struct IOSRequest request; void (*callback)(int, void *); // NULL for synchronous requests void *userData; // NULL for synchronous requests u32 relaunch; // always 0 or 1 struct OSThreadQueue dummyThreadQueue; }
dummyThreadQueue
is an 8-byte area used for synchronous requests to hold the current thread while it is waiting for a reply.
Memory allocation
Memory used by IPC and NAND is mainly allocated with iosAllocAligned
, which allocates from one of 8 heaps, each with the following structure:
struct HeapBlockHeader { u16 magic; // always 0xbabe u16 status; // 0 means free, 1 means it is in the process of being allocated, 2 means it is being used u32 size; struct HeapBlockHeader *prev; // points to the same heap block if it is allocated, NULL for the beginning of the heap struct HeapBlockHeader *next; // NULL for the end of the heap or if this heap block is allocated } struct Heap { void *base; u32 processId; // See note below u32 size; struct HeapBlockHeader *firstBlock; }
processId
is probably only present to match the struct used by IOS; it is never set or checked by IPC, but it may be used by IOS's memory management.