libtransistor
A userland library for the Nintendo Switch
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
ipc_helpers.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include<libtransistor/ipc.h>
13 #include<libtransistor/util.h>
14 
15 #include<string.h>
16 
17 static inline ipc_buffer_t ipc_make_buffer(void *addr, size_t size, uint32_t type) {
18  ipc_buffer_t buf;
19  buf.addr = addr;
20  buf.size = size;
21  buf.type = type;
22  return buf;
23 }
24 
25 static inline ipc_buffer_t ipc_buffer_from_string(const char *string, uint32_t type) {
26  ipc_buffer_t buf;
27  buf.addr = (void*) string;
28  buf.size = strlen(string) + 1;
29  buf.type = type;
30  return buf;
31 }
32 
33 static inline ipc_request_t ipc_make_request(uint32_t id) {
35  rq.request_id = id;
36  return rq;
37 }
38 
39 #define ipc_buffer_from_reference(ptr, type) ipc_make_buffer((ptr), sizeof(*(ptr)), type)
40 #define ipc_msg_raw_data_from_reference(msg, ptr) \
41  msg.raw_data_size = sizeof(*(ptr)); \
42  msg.raw_data = (uint32_t*) (ptr);
43 
44 #define ipc_buffer_from_value(val, type) ipc_make_buffer(&(val), sizeof(val), type)
45 #define ipc_msg_raw_data_from_value(msg, val) \
46  msg.raw_data_size = sizeof(val); \
47  msg.raw_data = (uint32_t*) (&(val));
48 
49 #define ipc_msg_set_buffers(msg, obj_arr, ptr_arr) \
50  ipc_buffer_t *(ptr_arr)[ARRAY_LENGTH(obj_arr)]; \
51  for(size_t i = 0; i < ARRAY_LENGTH(obj_arr); i++) { \
52  (ptr_arr)[i] = &(obj_arr)[i]; \
53  } \
54  (msg).num_buffers = ARRAY_LENGTH(obj_arr); \
55  (msg).buffers = (ptr_arr);
56 
57 #define ipc_msg_copy_handle_from_value(msg, handle) \
58  (msg).num_copy_handles = 1; \
59  (msg).copy_handles = &(handle);
60 
61 #define ipc_msg_copy_handle_from_reference(msg, handle) \
62  (msg).num_copy_handles = 1; \
63  (msg).copy_handles = handle;
64 
65 #ifdef __cplusplus
66 }
67 #endif
ipc_request_t ipc_default_request
An IPC request with default values set.
Various utililty functions.
Represents an unmarshalled outgoing IPC request.
Definition: ipc.h:74
Buffer for transfer over IPC.
Definition: ipc.h:62
Interprocess Communication data structures and functions.
uint64_t size
Size in bytes.
Definition: ipc.h:64