libnx
Data Structures | Macros
ipc.h File Reference

Inter-process communication handling. More...

#include "../result.h"
#include "../arm/tls.h"
#include "../kernel/svc.h"

Go to the source code of this file.

Data Structures

struct  IpcCommand
 
struct  IpcBufferDescriptor
 IPC buffer descriptor. More...
 
struct  IpcStaticSendDescriptor
 IPC static send-buffer descriptor. More...
 
struct  IpcStaticRecvDescriptor
 IPC static receive-buffer descriptor. More...
 
struct  IpcParsedCommand
 IPC parsed command (response) structure. More...
 
struct  DomainMessageHeader
 IPC domain message header. More...
 

Macros

#define SFCI_MAGIC   0x49434653
 IPC input header magic.
 
#define SFCO_MAGIC   0x4f434653
 IPC output header magic.
 
#define IPC_INVALID_OBJECT_ID   UINT32_MAX
 IPC invalid object ID.
 

Functions

IPC response parsing
static Result ipcParse (IpcParsedCommand *r)
 Parse an IPC command response into an IPC parsed command structure. More...
 
static Result ipcQueryPointerBufferSize (Handle session, size_t *size)
 Queries the size of an IPC pointer buffer. More...
 
static Result ipcCloseSession (Handle session)
 Closes the IPC session with proper clean up. More...
 
IPC domain handling
static Result ipcConvertSessionToDomain (Handle session, u32 *object_id_out)
 Converts an IPC session handle into a domain. More...
 
static void ipcSendObjectId (IpcCommand *cmd, u32 object_id)
 Adds an object ID to be sent through an IPC domain command structure. More...
 
static void * ipcPrepareHeaderForDomain (IpcCommand *cmd, size_t sizeof_raw, u32 object_id)
 Prepares the header of an IPC command structure (domain version). More...
 
static Result ipcParseForDomain (IpcParsedCommand *r)
 Parse an IPC command response into an IPC parsed command structure (domain version). More...
 
static Result ipcCloseObjectById (Handle session, u32 object_id)
 Closes a domain object by ID. More...
 

IPC request building

#define IPC_MAX_BUFFERS   8
 IPC command (request) structure.
 
#define IPC_MAX_OBJECTS   8
 
enum  BufferType {
  BufferType_Normal =0,
  BufferType_Type1 =1,
  BufferType_Invalid =2,
  BufferType_Type3 =3
}
 
enum  BufferDirection {
  BufferDirection_Send =0,
  BufferDirection_Recv =1,
  BufferDirection_Exch =2
}
 
enum  IpcCommandType {
  IpcCommandType_Invalid = 0,
  IpcCommandType_LegacyRequest = 1,
  IpcCommandType_Close = 2,
  IpcCommandType_LegacyControl = 3,
  IpcCommandType_Request = 4,
  IpcCommandType_Control = 5,
  IpcCommandType_RequestWithContext = 6,
  IpcCommandType_ControlWithContext = 7
}
 
static void ipcInitialize (IpcCommand *cmd)
 Initializes an IPC command structure. More...
 
static void ipcAddSendBuffer (IpcCommand *cmd, const void *buffer, size_t size, BufferType type)
 Adds a buffer to an IPC command structure. More...
 
static void ipcAddRecvBuffer (IpcCommand *cmd, void *buffer, size_t size, BufferType type)
 Adds a receive-buffer to an IPC command structure. More...
 
static void ipcAddExchBuffer (IpcCommand *cmd, void *buffer, size_t size, BufferType type)
 Adds an exchange-buffer to an IPC command structure. More...
 
static void ipcAddSendStatic (IpcCommand *cmd, const void *buffer, size_t size, u8 index)
 Adds a static-buffer to an IPC command structure. More...
 
static void ipcAddRecvStatic (IpcCommand *cmd, void *buffer, size_t size, u8 index)
 Adds a static-receive-buffer to an IPC command structure. More...
 
static void ipcAddSendSmart (IpcCommand *cmd, size_t ipc_buffer_size, const void *buffer, size_t size, u8 index)
 Adds a smart-buffer (buffer + static-buffer pair) to an IPC command structure. More...
 
static void ipcAddRecvSmart (IpcCommand *cmd, size_t ipc_buffer_size, void *buffer, size_t size, u8 index)
 Adds a smart-receive-buffer (buffer + static-receive-buffer pair) to an IPC command structure. More...
 
static void ipcSendPid (IpcCommand *cmd)
 Tags an IPC command structure to send the PID. More...
 
static void ipcSendHandleCopy (IpcCommand *cmd, Handle h)
 Adds a copy-handle to be sent through an IPC command structure. More...
 
static void ipcSendHandleMove (IpcCommand *cmd, Handle h)
 Adds a move-handle to be sent through an IPC command structure. More...
 
static void * ipcPrepareHeader (IpcCommand *cmd, size_t sizeof_raw)
 Prepares the header of an IPC command structure. More...
 
static Result ipcDispatch (Handle session)
 Dispatches an IPC request. More...
 

Detailed Description

Inter-process communication handling.

Author
plutoo

Enumeration Type Documentation

enum BufferType
Enumerator
BufferType_Normal 

Regular buffer.

BufferType_Type1 

Allows ProcessMemory and shared TransferMemory.

BufferType_Type3 

Same as Type1 except remote process is not allowed to use device-mapping.

Function Documentation

static void ipcAddExchBuffer ( IpcCommand cmd,
void *  buffer,
size_t  size,
BufferType  type 
)
inlinestatic

Adds an exchange-buffer to an IPC command structure.

Parameters
cmdIPC command structure.
bufferAddress of the buffer.
sizeSize of the buffer.
typeBuffer type.
static void ipcAddRecvBuffer ( IpcCommand cmd,
void *  buffer,
size_t  size,
BufferType  type 
)
inlinestatic

Adds a receive-buffer to an IPC command structure.

Parameters
cmdIPC command structure.
bufferAddress of the buffer.
sizeSize of the buffer.
typeBuffer type.
static void ipcAddRecvSmart ( IpcCommand cmd,
size_t  ipc_buffer_size,
void *  buffer,
size_t  size,
u8  index 
)
inlinestatic

Adds a smart-receive-buffer (buffer + static-receive-buffer pair) to an IPC command structure.

Parameters
cmdIPC command structure.
ipc_buffer_sizeIPC buffer size.
bufferAddress of the buffer.
sizeSize of the buffer.
indexIndex of buffer.
static void ipcAddRecvStatic ( IpcCommand cmd,
void *  buffer,
size_t  size,
u8  index 
)
inlinestatic

Adds a static-receive-buffer to an IPC command structure.

Parameters
cmdIPC command structure.
bufferAddress of the buffer.
sizeSize of the buffer.
indexIndex of buffer.
static void ipcAddSendBuffer ( IpcCommand cmd,
const void *  buffer,
size_t  size,
BufferType  type 
)
inlinestatic

Adds a buffer to an IPC command structure.

Parameters
cmdIPC command structure.
bufferAddress of the buffer.
sizeSize of the buffer.
typeBuffer type.
static void ipcAddSendSmart ( IpcCommand cmd,
size_t  ipc_buffer_size,
const void *  buffer,
size_t  size,
u8  index 
)
inlinestatic

Adds a smart-buffer (buffer + static-buffer pair) to an IPC command structure.

Parameters
cmdIPC command structure.
ipc_buffer_sizeIPC buffer size.
bufferAddress of the buffer.
sizeSize of the buffer.
indexIndex of buffer.
static void ipcAddSendStatic ( IpcCommand cmd,
const void *  buffer,
size_t  size,
u8  index 
)
inlinestatic

Adds a static-buffer to an IPC command structure.

Parameters
cmdIPC command structure.
bufferAddress of the buffer.
sizeSize of the buffer.
indexIndex of buffer.
static Result ipcCloseObjectById ( Handle  session,
u32  object_id 
)
inlinestatic

Closes a domain object by ID.

Parameters
sessionIPC session handle.
object_idID of the object to close.
Returns
Result code.
static Result ipcCloseSession ( Handle  session)
inlinestatic

Closes the IPC session with proper clean up.

Parameters
sessionIPC session handle.
Returns
Result code.
static Result ipcConvertSessionToDomain ( Handle  session,
u32 object_id_out 
)
inlinestatic

Converts an IPC session handle into a domain.

Parameters
sessionIPC session handle.
object_id_outOutput variable in which to store the object ID.
Returns
Result code.
static Result ipcDispatch ( Handle  session)
inlinestatic

Dispatches an IPC request.

Parameters
sessionIPC session handle.
Returns
Result code.
static void ipcInitialize ( IpcCommand cmd)
inlinestatic

Initializes an IPC command structure.

Parameters
cmdIPC command structure.
static Result ipcParse ( IpcParsedCommand r)
inlinestatic

Parse an IPC command response into an IPC parsed command structure.

Parameters
IPCparsed command structure to fill in.
Returns
Result code.
static Result ipcParseForDomain ( IpcParsedCommand r)
inlinestatic

Parse an IPC command response into an IPC parsed command structure (domain version).

Parameters
IPCparsed command structure to fill in.
Returns
Result code.
static void* ipcPrepareHeader ( IpcCommand cmd,
size_t  sizeof_raw 
)
inlinestatic

Prepares the header of an IPC command structure.

Parameters
cmdIPC command structure.
sizeof_rawSize in bytes of the raw data structure to embed inside the IPC request
Returns
Pointer to the raw embedded data structure in the request, ready to be filled out.
static void* ipcPrepareHeaderForDomain ( IpcCommand cmd,
size_t  sizeof_raw,
u32  object_id 
)
inlinestatic

Prepares the header of an IPC command structure (domain version).

Parameters
cmdIPC command structure.
sizeof_rawSize in bytes of the raw data structure to embed inside the IPC request object_id Domain object ID.
Returns
Pointer to the raw embedded data structure in the request, ready to be filled out.
static Result ipcQueryPointerBufferSize ( Handle  session,
size_t *  size 
)
inlinestatic

Queries the size of an IPC pointer buffer.

Parameters
sessionIPC session handle.
sizeOutput variable in which to store the size.
Returns
Result code.
static void ipcSendHandleCopy ( IpcCommand cmd,
Handle  h 
)
inlinestatic

Adds a copy-handle to be sent through an IPC command structure.

Parameters
cmdIPC command structure.
hHandle to send.
Remarks
The receiving process gets a copy of the handle.
static void ipcSendHandleMove ( IpcCommand cmd,
Handle  h 
)
inlinestatic

Adds a move-handle to be sent through an IPC command structure.

Parameters
cmdIPC command structure.
hHandle to send.
Remarks
The sending process loses ownership of the handle, which is transferred to the receiving process.
static void ipcSendObjectId ( IpcCommand cmd,
u32  object_id 
)
inlinestatic

Adds an object ID to be sent through an IPC domain command structure.

Parameters
cmdIPC domain command structure.
object_idObject ID to send.
static void ipcSendPid ( IpcCommand cmd)
inlinestatic

Tags an IPC command structure to send the PID.

Parameters
cmdIPC command structure.