libtransistor
A userland library for the Nintendo Switch
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
ipc.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #include<libtransistor/types.h>
17 
18 struct ipc_server_object_t;
19 
24 typedef struct {
25  session_h session;
26 } ipc_domain_t;
27 
32 typedef struct {
33  int32_t object_id;
34  union {
37  };
38  bool is_borrowed;
39 } ipc_object_t;
40 
44  ipc_multi_session_node_t *_Atomic next;
45  ipc_object_t object;
46  _Atomic _Bool is_busy;
47 };
48 
53 typedef struct {
54  ipc_object_t original;
57 
62 typedef struct {
63  void *addr;
64  uint64_t size;
65  uint32_t type;
66 } ipc_buffer_t;
67 
74 typedef struct {
75  uint32_t type;
76  uint32_t num_buffers;
78  uint32_t request_id;
79  void *raw_data;
80  size_t raw_data_size;
81  bool send_pid;
82  uint8_t num_copy_handles;
83  uint8_t num_move_handles;
84  uint8_t num_objects;
88  bool close_object;
90 
100 typedef struct {
101  uint32_t num_buffers;
103  void *raw_data;
104  size_t raw_data_size;
105  bool send_pid;
106  uint64_t *pid;
109  uint8_t num_objects;
114 
121 typedef struct {
122  uint32_t type;
123  uint32_t num_buffers;
124  ipc_buffer_t **buffers;
125  result_t result_code;
126  void *raw_data;
127  size_t raw_data_size; // in BYTES
128  bool send_pid;
129  uint8_t num_copy_handles;
130  uint8_t num_move_handles;
131  uint8_t num_objects;
132  handle_t *copy_handles;
133  handle_t *move_handles;
134  struct ipc_server_object_t **objects;
136 
144 typedef struct {
145  uint32_t num_copy_handles;
146  uint32_t num_move_handles;
147  uint32_t num_objects;
148  handle_t *copy_handles;
149  handle_t *move_handles;
150  ipc_object_t *objects;
151 
152  size_t raw_data_size;
153  void *raw_data;
154 
155  bool has_pid;
156  uint64_t *pid;
158 
178 
185 
192 
208 
216 
217 typedef enum {
224 
226 
234 typedef struct {
235  uint16_t message_type;
237  uint32_t num_x_descriptors;
238  uint32_t num_a_descriptors;
239  uint32_t num_b_descriptors;
240  uint32_t num_w_descriptors;
241  uint32_t c_descriptor_flags;
242  uint32_t *x_descriptors;
243  uint32_t *a_descriptors;
244  uint32_t *b_descriptors;
245  uint32_t *w_descriptors;
246  uint32_t *c_descriptors;
247  uint32_t num_copy_handles;
248  uint32_t num_move_handles;
251  bool has_pid;
252  uint64_t pid;
255  uint32_t *data_section;
256 } ipc_message_t;
257 
265 result_t ipc_pack_request(uint32_t *buffer, const ipc_request_t *rq, ipc_object_t object);
266 
276 result_t ipc_pack_response(uint32_t *buffer, const ipc_response_t *rs, struct ipc_server_object_t *object);
277 
284 result_t ipc_unpack(uint32_t *buffer, ipc_message_t *msg);
285 
300 
309 
318 
325 
334 
339 
344 
351 
358 
365 
366 #ifdef __cplusplus
367 }
368 #endif
Hexdump responses that could not be unpacked.
Definition: ipc.h:219
Represents the server side of an IPC object.
Definition: ipcserver.h:30
handle_t * copy_handles
Array to be populated with the expected amount of incoming copy handles.
Definition: ipc.h:110
handle_t * copy_handles
points to original ipc buffer
Definition: ipc.h:249
Various system types.
bool send_pid
Whether to expect an incoming PID.
Definition: ipc.h:105
handle_t * copy_handles
Array of num_copy_handles handles to be copied.
Definition: ipc.h:85
ipc_object_t * objects
Array of num_objects objects to be referenced.
Definition: ipc.h:87
bool close_object
Whether or not to close the domain object. You should use ipc_close instead of this.
Definition: ipc.h:88
ipc_response_t ipc_default_response
An IPC response with default values set.
handle_t * move_handles
points to original ipc buffer
Definition: ipc.h:250
struct ipc_server_object_t ** objects
Array to be populated with the expected amount of points to objects referenced by the request...
Definition: ipc.h:112
bool is_borrowed
whether or not this object is being borrowed from a loader or not
Definition: ipc.h:38
size_t raw_data_size
size in bytes of raw_data
Definition: ipc.h:152
result_t ipc_convert_to_multi(ipc_multi_session_t *multi, ipc_object_t *object)
Converts a session to a multi session.
int post_padding
size of padding (in words) after aligned data section
Definition: ipc.h:254
Describes an incoming IPC message. Used as an intermediate during unpacking.
Definition: ipc.h:234
ipc_domain_t * domain
object_id >= 0
Definition: ipc.h:36
result_t ipc_unpack(uint32_t *buffer, ipc_message_t *msg)
Unpacks the IPC message from buffer, filling out msg.
ipc_buffer_t ** buffers
This should point to an array of num_buffers buffers.
Definition: ipc.h:77
size_t raw_data_size
Size in bytes of raw_data.
Definition: ipc.h:80
ipc_request_t ipc_default_request
An IPC request with default values set.
result_t ipc_clone_current_object(ipc_object_t source, ipc_object_t *clone)
Clones a session.
uint32_t result_t
Function result.
Definition: types.h:51
Hexdump requests that triggered an error in svcSendSyncRequest.
Definition: ipc.h:221
Represents an unmarshalled outgoing IPC response.
Definition: ipc.h:121
handle_t session_h
Session handle.
Definition: types.h:42
Hexdump responses that could not be unflattened.
Definition: ipc.h:220
ipc_response_fmt_t ipc_default_response_fmt
An IPC response format with default values set.
result_t ipc_close_domain(ipc_domain_t domain)
Closes the whole domain
ipc_buffer_t ** buffers
This should point to an array of num_buffers buffers, with the type fields filled out...
Definition: ipc.h:102
Represents either an object within an IPC domain or a standalone object.
Definition: ipc.h:32
session_h session
object_id = -1
Definition: ipc.h:35
handle_t * move_handles
Array of num_move_handles handles to be moved.
Definition: ipc.h:86
uint32_t num_buffers
Number of buffers to expect.
Definition: ipc.h:101
size_t raw_data_size
Size in bytes of raw_data to expect.
Definition: ipc.h:104
result_t ipc_convert_to_domain(ipc_object_t *session, ipc_domain_t *domain)
Converts session to a domain object and initializes domain. domain is only initialized if RESULT_OK i...
ipc_request_fmt_t ipc_default_request_fmt
An IPC request format with default values set.
Describes format expectations for an incoming IPC response.
Definition: ipc.h:144
uint64_t * pid
Where to put an incoming PID, if one is expected and present.
Definition: ipc.h:106
Describes format expectations for an incoming IPC request.
Definition: ipc.h:100
result_t ipc_close_multi(ipc_multi_session_t *multi)
Closes a multi session.
uint8_t num_move_handles
How many handles to expect to be moved.
Definition: ipc.h:108
ipc_object_t ipc_null_object
An IPC object with default NULL values set.
handle_t * move_handles
Array to be populated with the expected amount of incoming move handles.
Definition: ipc.h:111
result_t ipc_send(ipc_object_t object, ipc_request_t *rq, ipc_response_fmt_t *rs)
Send a request described by rq to object and then unpack the response.
uint32_t handle_t
Resource handle.
Definition: types.h:38
result_t ipc_pack_response(uint32_t *buffer, const ipc_response_t *rs, struct ipc_server_object_t *object)
Packs the IPC response described by rs and object into buffer.
Represents an unmarshalled outgoing IPC request.
Definition: ipc.h:74
uint8_t num_copy_handles
How many handles to expect to be copied.
Definition: ipc.h:107
Buffer for transfer over IPC.
Definition: ipc.h:62
result_t ipc_unflatten_response(ipc_message_t *msg, ipc_response_fmt_t *rs, ipc_object_t object)
Unflattens the IPC response described by rs from msg.
Do not log any IPC messages.
Definition: ipc.h:218
Hexdump all requests and all responses.
Definition: ipc.h:222
result_t ipc_unflatten_request(ipc_message_t *msg, ipc_request_fmt_t *rs, struct ipc_server_object_t *object)
Unflattens the IPC request described by rq from msg
result_t ipc_send_multi(ipc_multi_session_t *multi, ipc_request_t *rq, ipc_response_fmt_t *rs)
Send a requst described by rq to multi and then unpack the response See ipc_send. NOTE: may call mall...
void * raw_data
Buffer to copy raw request data into.
Definition: ipc.h:103
result_t ipc_close(ipc_object_t object)
Closes the object
ipc_debug_level_t ipc_debug_level
Default: IPC_DEBUG_LEVEL_NONE.
ipc_debug_level_t
Definition: ipc.h:217
uint64_t size
Size in bytes.
Definition: ipc.h:64
Definition: ipc.h:42
int32_t object_id
-1 if this represents a session, >= 0 if this represents a domain object
Definition: ipc.h:33
result_t ipc_pack_request(uint32_t *buffer, const ipc_request_t *rq, ipc_object_t object)
Packs the IPC request described by rq and object into buffer.
uint32_t raw_data_section_size
in words
Definition: ipc.h:236
uint32_t * data_section
may point to domain header, may point to SFCI/SFCO
Definition: ipc.h:255
Represents an IPC object domain.
Definition: ipc.h:24
A wrapper around a session that will clone it for use from multiple threads when necessary.
Definition: ipc.h:53
uint8_t num_objects
How many objects to expect to be referenced.
Definition: ipc.h:109
int pre_padding
size of padding (in words) before aligned data section
Definition: ipc.h:253