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