13 typedef enum TipcCommandType {
14 TipcCommandType_Close = 15,
43 u32 num_inout_buffers;
63 hipcMakeRequestInline(
armGetTls(), .type = TipcCommandType_Close);
71 *req->send_buffers++ = hipcMakeBuffer(buffer, size, mode);
76 *req->recv_buffers++ = hipcMakeBuffer(buffer, size, mode);
81 *req->exch_buffers++ = hipcMakeBuffer(buffer, size, mode);
86 *req->copy_handles++ = handle;
92 const bool is_in = (attr & SfBufferAttr_In) != 0;
93 const bool is_out = (attr & SfBufferAttr_Out) != 0;
95 if (attr & SfBufferAttr_HipcMapAlias) {
97 fmt->num_inout_buffers ++;
99 fmt->num_in_buffers ++;
101 fmt->num_out_buffers ++;
108 const bool is_in = (attr & SfBufferAttr_In);
109 const bool is_out = (attr & SfBufferAttr_Out);
111 if (attr & SfBufferAttr_HipcMapAlias) {
112 HipcBufferMode mode = HipcBufferMode_Normal;
113 if (attr & SfBufferAttr_HipcMapTransferAllowsNonSecure)
114 mode = HipcBufferMode_NonSecure;
115 if (attr & SfBufferAttr_HipcMapTransferAllowsNonDevice)
116 mode = HipcBufferMode_NonDevice;
119 tipcRequestInOutBuffer(req, (
void*)buf->ptr, buf->size, mode);
121 tipcRequestInBuffer(req, buf->ptr, buf->size, mode);
123 tipcRequestOutBuffer(req, (
void*)buf->ptr, buf->size, mode);
128 u32 request_id,
u32 data_size,
bool send_pid,
130 u32 num_handles,
const Handle* handles) {
132 fmt.request_id = request_id + 16;
133 fmt.data_size = data_size;
134 fmt.num_handles = num_handles;
135 fmt.send_pid = send_pid;
137 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr0);
138 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr1);
139 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr2);
140 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr3);
141 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr4);
142 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr5);
143 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr6);
144 _tipcRequestFormatProcessBuffer(&fmt, buffer_attrs.attr7);
147 .type = fmt.request_id,
148 .num_send_statics = 0,
149 .num_send_buffers = fmt.num_in_buffers,
150 .num_recv_buffers = fmt.num_out_buffers,
151 .num_exch_buffers = fmt.num_inout_buffers,
152 .num_data_words = (data_size + 3) / 4,
153 .num_recv_statics = 0,
154 .send_pid = fmt.send_pid,
155 .num_copy_handles = fmt.num_handles,
156 .num_move_handles = 0,
159 for (
u32 i = 0; i < num_handles; i ++)
160 tipcRequestHandle(&req, handles[i]);
162 _tipcRequestProcessBuffer(&req, &buffers[0], buffer_attrs.attr0);
163 _tipcRequestProcessBuffer(&req, &buffers[1], buffer_attrs.attr1);
164 _tipcRequestProcessBuffer(&req, &buffers[2], buffer_attrs.attr2);
165 _tipcRequestProcessBuffer(&req, &buffers[3], buffer_attrs.attr3);
166 _tipcRequestProcessBuffer(&req, &buffers[4], buffer_attrs.attr4);
167 _tipcRequestProcessBuffer(&req, &buffers[5], buffer_attrs.attr5);
168 _tipcRequestProcessBuffer(&req, &buffers[6], buffer_attrs.attr6);
169 _tipcRequestProcessBuffer(&req, &buffers[7], buffer_attrs.attr7);
171 return req.data_words;
176 return *res->copy_handles++;
181 return *res->move_handles++;
188 case SfOutHandleAttr_None:
190 case SfOutHandleAttr_HipcCopy:
191 *out = tipcResponseGetCopyHandle(res);
193 case SfOutHandleAttr_HipcMove:
194 *out = tipcResponseGetMoveHandle(res);
200 u32 out_size,
void** out_data,
207 Result rc = *res.data_words++;
212 *out_data = res.data_words;
214 for (
u32 i = 0; i < num_out_objects; i ++) {
215 tipcCreate(&out_objects[i], tipcResponseGetMoveHandle(&res));
218 _tipcResponseGetHandle(&res, out_handle_attrs.attr0, &out_handles[0]);
219 _tipcResponseGetHandle(&res, out_handle_attrs.attr1, &out_handles[1]);
220 _tipcResponseGetHandle(&res, out_handle_attrs.attr2, &out_handles[2]);
221 _tipcResponseGetHandle(&res, out_handle_attrs.attr3, &out_handles[3]);
222 _tipcResponseGetHandle(&res, out_handle_attrs.attr4, &out_handles[4]);
223 _tipcResponseGetHandle(&res, out_handle_attrs.attr5, &out_handles[5]);
224 _tipcResponseGetHandle(&res, out_handle_attrs.attr6, &out_handles[6]);
225 _tipcResponseGetHandle(&res, out_handle_attrs.attr7, &out_handles[7]);
232 const void* in_data,
u32 in_data_size,
233 void* out_data,
u32 out_data_size,
237 void* in = tipcMakeRequest(request_id,
238 in_data_size, disp.in_send_pid,
239 disp.buffer_attrs, disp.buffers,
240 disp.in_num_handles, disp.in_handles);
243 __builtin_memcpy(in, in_data, in_data_size);
248 rc = tipcParseResponse(out_data_size, &out,
249 disp.out_num_objects, disp.out_objects,
250 disp.out_handle_attrs, disp.out_handles);
253 __builtin_memcpy(out_data, out, out_data_size);
259 #define tipcDispatch(_s,_rid,...) \
260 tipcDispatchImpl((_s),(_rid),NULL,0,NULL,0,(TipcDispatchParams){ __VA_ARGS__ })
262 #define tipcDispatchIn(_s,_rid,_in,...) \
263 tipcDispatchImpl((_s),(_rid),&(_in),sizeof(_in),NULL,0,(TipcDispatchParams){ __VA_ARGS__ })
265 #define tipcDispatchOut(_s,_rid,_out,...) \
266 tipcDispatchImpl((_s),(_rid),NULL,0,&(_out),sizeof(_out),(TipcDispatchParams){ __VA_ARGS__ })
268 #define tipcDispatchInOut(_s,_rid,_in,_out,...) \
269 tipcDispatchImpl((_s),(_rid),&(_in),sizeof(_in),&(_out),sizeof(_out),(TipcDispatchParams){ __VA_ARGS__ })
Common Message Interface Framework protocol.
Horizon Inter-Process Communication protocol.
#define R_FAILED(res)
Checks whether a result code indicates failure.
Definition: result.h:12
#define R_SUCCEEDED(res)
Checks whether a result code indicates success.
Definition: result.h:10
tipc Service object structure
Definition: tipc.h:18
Result svcCloseHandle(Handle handle)
Closes a handle, decrementing the reference count of the corresponding kernel object.
Result svcSendSyncRequest(Handle session)
Sends an IPC synchronization request to a session.
static void tipcCreate(TipcService *s, Handle h)
Creates a tipc service object from an IPC session handle.
Definition: tipc.h:53
static void tipcClose(TipcService *s)
Closes a tipc service.
Definition: tipc.h:61
static void * armGetTls(void)
Gets the thread local storage buffer.
Definition: tls.h:14
#define NX_INLINE
Flags a function as (always) inline.
Definition: types.h:86
u32 Handle
Kernel object handle.
Definition: types.h:43
u32 Result
Function error code result type.
Definition: types.h:44
#define NX_CONSTEXPR
Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
Definition: types.h:92
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21