1 /* 2 * Interprocess communication message abstraction. 3 * 4 * Copyright (C) 2018, 2019, 2021 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/re/c/dataspace.h> 25 #include <l4/sys/ipc.h> 26 #include <l4/sys/utcb.h> 27 #include <l4/sys/types.h> 28 29 #include <sys/types.h> 30 31 32 33 EXTERN_C_BEGIN 34 35 /* Message abstraction. */ 36 37 typedef struct 38 { 39 /* Common virtual registers. */ 40 41 l4_buf_regs_t bregs; 42 l4_msg_regs_t mregs; 43 44 /* Input details. */ 45 46 l4_msgtag_t tag; 47 unsigned int expected_items; 48 49 /* Output details. */ 50 51 unsigned int words; 52 unsigned int items; 53 54 /* Items transferred and not retained. */ 55 56 unsigned int discarded_items; 57 l4_cap_idx_t to_discard[L4_UTCB_GENERIC_DATA_SIZE]; 58 59 /* Message label overriding. */ 60 61 l4_umword_t new_label; 62 63 /* Server control. */ 64 65 int terminating; 66 67 } ipc_message_t; 68 69 70 71 /* Special status codes. */ 72 73 #define IPC_MESSAGE_SENT 0x01d10000 74 75 /* Capability annotations. */ 76 77 #define IPC_DISCARD_CAP_FLAG (1 << (L4_CAP_SHIFT - 2)) 78 #define discard_cap(x) (x | IPC_DISCARD_CAP_FLAG) 79 80 81 82 /* Message operations. */ 83 84 /* Lifecycle operations. */ 85 86 void ipc_message_new(ipc_message_t *msg); 87 long ipc_message_expect(ipc_message_t *msg, unsigned int expected_items); 88 void ipc_message_request(ipc_message_t *msg, int op, l4_cap_idx_t endpoint); 89 void ipc_message_send(ipc_message_t *msg, int op, l4_cap_idx_t endpoint); 90 void ipc_message_wait(ipc_message_t *msg, l4_umword_t *label); 91 void ipc_message_reply(ipc_message_t *msg); 92 void ipc_message_discard(ipc_message_t *msg); 93 void ipc_message_free(ipc_message_t *msg); 94 95 /* Helper operations. */ 96 97 void ipc_message_open(ipc_message_t *msg); 98 void ipc_message_prepare(ipc_message_t *msg); 99 void ipc_message_preserve_buffer_registers(ipc_message_t *msg); 100 void ipc_message_preserve_message_registers(ipc_message_t *msg); 101 void ipc_message_reset(ipc_message_t *msg); 102 void ipc_message_restore_buffer_registers(ipc_message_t *msg); 103 void ipc_message_restore_message_registers(ipc_message_t *msg); 104 105 /* Population operations. */ 106 107 void ipc_message_add_capability(ipc_message_t *msg, l4_cap_idx_t cap); 108 void ipc_message_add_data(ipc_message_t *msg, const char *value, size_t length); 109 void ipc_message_add_item(ipc_message_t *msg, l4_cap_idx_t cap); 110 void ipc_message_add_fpage(ipc_message_t *msg, l4_snd_fpage_t fpage); 111 void ipc_message_add_page(ipc_message_t *msg, l4_umword_t hot_spot, l4_fpage_t fpage); 112 void ipc_message_add_string(ipc_message_t *msg, const char *value); 113 void ipc_message_add_word(ipc_message_t *msg, l4_umword_t value); 114 void ipc_message_propagate_item(ipc_message_t *msg, l4_cap_idx_t cap); 115 void *ipc_message_reserve_data(ipc_message_t *msg, size_t length); 116 void *ipc_message_reserve_words(ipc_message_t *msg, size_t length); 117 void ipc_message_send_error(ipc_message_t *msg, long error); 118 119 /* Access operations. */ 120 121 l4_umword_t ipc_message_get_word(ipc_message_t *msg, unsigned int word); 122 l4_umword_t *ipc_message_get_word_address(ipc_message_t *msg, unsigned int word); 123 unsigned int ipc_message_number_of_items(ipc_message_t *msg); 124 unsigned int ipc_message_number_of_words(ipc_message_t *msg); 125 126 /* Supporting operations. */ 127 128 void ipc_message_discard_capability(ipc_message_t *msg, l4_cap_idx_t cap); 129 void ipc_message_discard_dataspace(ipc_message_t *msg, l4re_ds_t mem, l4_addr_t addr); 130 long ipc_message_expect_capabilities(ipc_message_t *msg, int number); 131 long ipc_message_expect_capability(ipc_message_t *msg, int item); 132 void ipc_message_export_capability(ipc_message_t *msg, int item, l4_cap_idx_t ref); 133 void ipc_message_export_fpage(ipc_message_t *msg, int item, l4_snd_fpage_t fpage); 134 void ipc_message_export_page(ipc_message_t *msg, int item, l4_umword_t hot_spot, l4_fpage_t fpage); 135 long ipc_message_import_capability(ipc_message_t *msg, int item, l4_cap_idx_t *ref); 136 long ipc_message_import_dataspace(ipc_message_t *msg, int item, l4re_ds_t *mem, l4_addr_t *addr); 137 long ipc_message_import_fpage(ipc_message_t *msg, int item, l4_snd_fpage_t *fpage); 138 void ipc_message_propagate_capability(ipc_message_t *msg, int item, l4_cap_idx_t ref); 139 l4_msgtag_t ipc_message_reply_tag(ipc_message_t *msg); 140 l4_msgtag_t ipc_message_request_tag(ipc_message_t *msg, int op); 141 142 EXTERN_C_END