10 #include "../arm/tls.h"
11 #include "../kernel/svc.h"
13 #define HIPC_AUTO_RECV_STATIC UINT8_MAX
14 #define HIPC_RESPONSE_NO_PID UINT32_MAX
31 u32 num_send_statics : 4;
32 u32 num_send_buffers : 4;
33 u32 num_recv_buffers : 4;
34 u32 num_exch_buffers : 4;
35 u32 num_data_words : 10;
36 u32 recv_static_mode : 4;
38 u32 recv_list_offset : 11;
39 u32 has_special_header : 1;
44 u32 num_copy_handles : 4;
45 u32 num_move_handles : 4;
61 u32 address_high : 22;
68 u32 address_high : 16;
101 typedef enum HipcBufferMode {
102 HipcBufferMode_Normal = 0,
103 HipcBufferMode_NonSecure = 1,
104 HipcBufferMode_Invalid = 2,
105 HipcBufferMode_NonDevice = 3,
112 .address_high = (
u32)((uintptr_t)buffer >> 36),
113 .address_mid = (
u32)((uintptr_t)buffer >> 32),
115 .address_low = (
u32)(uintptr_t)buffer,
122 .size_low = (
u32)size,
123 .address_low = (
u32)(uintptr_t)buffer,
125 .address_high = (
u32)((uintptr_t)buffer >> 36),
126 .size_high = (
u32)(size >> 32),
127 .address_mid = (
u32)((uintptr_t)buffer >> 32),
134 .address_low = (
u32)((uintptr_t)buffer),
135 .address_high = (
u32)((uintptr_t)buffer >> 32),
142 return (
void*)(desc->address_low | ((uintptr_t)desc->address_mid << 32) | ((uintptr_t)desc->address_high << 36));
152 return (
void*)(desc->address_low | ((uintptr_t)desc->address_mid << 32) | ((uintptr_t)desc->address_high << 36));
157 return desc->size_low | ((size_t)desc->size_high << 32);
163 Handle* copy_handles = NULL;
164 if (meta.num_copy_handles) {
165 copy_handles = (
Handle*)base;
166 base = copy_handles + meta.num_copy_handles;
170 Handle* move_handles = NULL;
171 if (meta.num_move_handles) {
172 move_handles = (
Handle*)base;
173 base = move_handles + meta.num_move_handles;
178 if (meta.num_send_statics) {
180 base = send_statics + meta.num_send_statics;
185 if (meta.num_send_buffers) {
187 base = send_buffers + meta.num_send_buffers;
192 if (meta.num_recv_buffers) {
194 base = recv_buffers + meta.num_recv_buffers;
199 if (meta.num_exch_buffers) {
201 base = exch_buffers + meta.num_exch_buffers;
205 u32* data_words = NULL;
206 if (meta.num_data_words) {
207 data_words = (
u32*)base;
208 base = data_words + meta.num_data_words;
213 if (meta.num_recv_statics)
217 .send_statics = send_statics,
218 .send_buffers = send_buffers,
219 .recv_buffers = recv_buffers,
220 .exch_buffers = exch_buffers,
221 .data_words = data_words,
222 .recv_list = recv_list,
223 .copy_handles = copy_handles,
224 .move_handles = move_handles,
231 bool has_special_header = meta.send_pid || meta.num_copy_handles || meta.num_move_handles;
236 .num_send_statics = meta.num_send_statics,
237 .num_send_buffers = meta.num_send_buffers,
238 .num_recv_buffers = meta.num_recv_buffers,
239 .num_exch_buffers = meta.num_exch_buffers,
240 .num_data_words = meta.num_data_words,
241 .recv_static_mode = meta.num_recv_statics ? (meta.num_recv_statics != HIPC_AUTO_RECV_STATIC ? 2u + meta.num_recv_statics : 2u) : 0u,
243 .recv_list_offset = 0,
244 .has_special_header = has_special_header,
248 if (has_special_header) {
252 .send_pid = meta.send_pid,
253 .num_copy_handles = meta.num_copy_handles,
254 .num_move_handles = meta.num_move_handles,
257 base = (
u8*)base +
sizeof(
u64);
261 return hipcCalcRequestLayout(meta, base);
264 #define hipcMakeRequestInline(_base,...) hipcMakeRequest((_base),(HipcMetadata){ __VA_ARGS__ })
270 __builtin_memcpy(&hdr, base,
sizeof(hdr));
271 base = (
u8*)base +
sizeof(hdr);
272 u32 num_recv_statics = 0;
276 if (hdr.recv_static_mode) {
277 if (hdr.recv_static_mode == 2u)
278 num_recv_statics = HIPC_AUTO_RECV_STATIC;
279 else if (hdr.recv_static_mode > 2u)
280 num_recv_statics = hdr.recv_static_mode - 2u;
285 if (hdr.has_special_header) {
286 __builtin_memcpy(&sphdr, base,
sizeof(sphdr));
287 base = (
u8*)base +
sizeof(sphdr);
290 if (sphdr.send_pid) {
292 base = (
u8*)base +
sizeof(
u64);
298 .num_send_statics = hdr.num_send_statics,
299 .num_send_buffers = hdr.num_send_buffers,
300 .num_recv_buffers = hdr.num_recv_buffers,
301 .num_exch_buffers = hdr.num_exch_buffers,
302 .num_data_words = hdr.num_data_words,
303 .num_recv_statics = num_recv_statics,
304 .send_pid = sphdr.send_pid,
305 .num_copy_handles = sphdr.num_copy_handles,
306 .num_move_handles = sphdr.num_move_handles,
311 .data = hipcCalcRequestLayout(meta, base),
320 __builtin_memcpy(&hdr, base,
sizeof(hdr));
321 base = (
u8*)base +
sizeof(hdr);
325 response.num_statics = hdr.num_send_statics;
326 response.num_data_words = hdr.num_data_words;
327 response.pid = HIPC_RESPONSE_NO_PID;
330 if (hdr.has_special_header)
333 __builtin_memcpy(&sphdr, base,
sizeof(sphdr));
334 base = (
u8*)base +
sizeof(sphdr);
337 response.num_copy_handles = sphdr.num_copy_handles;
338 response.num_move_handles = sphdr.num_move_handles;
341 if (sphdr.send_pid) {
342 response.pid = *(
u64*)base;
343 base = (
u8*)base +
sizeof(
u64);
348 response.copy_handles = (
Handle*)base;
349 base = response.copy_handles + response.num_copy_handles;
352 response.move_handles = (
Handle*)base;
353 base = response.move_handles + response.num_move_handles;
357 base = response.statics + response.num_statics;
360 response.data_words = (
u32*)base;
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
u32 Handle
Kernel object handle.
Definition: types.h:43
#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