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 | #include <string.h> |
paul@181 | 23 | |
paul@181 | 24 | #include "cap_alloc.h" |
paul@181 | 25 | #include "message.h" |
paul@181 | 26 | #include "mem_ipc.h" |
paul@181 | 27 | #include "util_ipc.h" |
paul@181 | 28 | |
paul@181 | 29 | |
paul@181 | 30 | |
paul@181 | 31 | /* Calculate the given length rounded up to whole word increments. */ |
paul@181 | 32 | |
paul@181 | 33 | static size_t get_size_in_words(size_t length) |
paul@181 | 34 | { |
paul@181 | 35 | size_t mask = sizeof(l4_umword_t) - 1; |
paul@181 | 36 | return (length + mask) & ~mask; |
paul@181 | 37 | } |
paul@181 | 38 | |
paul@181 | 39 | |
paul@181 | 40 | |
paul@181 | 41 | /* Message operations. */ |
paul@181 | 42 | |
paul@181 | 43 | /* Discard capabilities for transfer to other tasks. */ |
paul@181 | 44 | |
paul@181 | 45 | void ipc_message_discard(ipc_message_t *msg) |
paul@181 | 46 | { |
paul@181 | 47 | unsigned int i; |
paul@181 | 48 | |
paul@181 | 49 | for (i = 0; i < msg->discarded_items; i++) |
paul@181 | 50 | ipc_cap_free_um(msg->to_discard[i]); |
paul@181 | 51 | } |
paul@181 | 52 | |
paul@181 | 53 | /* Initialise a message structure with the given number of expected items. */ |
paul@181 | 54 | |
paul@181 | 55 | long ipc_message_expect(ipc_message_t *msg, unsigned int expected_items) |
paul@181 | 56 | { |
paul@181 | 57 | long err = ipc_message_expect_capabilities(msg, expected_items); |
paul@181 | 58 | |
paul@181 | 59 | if (err) |
paul@181 | 60 | return err; |
paul@181 | 61 | |
paul@181 | 62 | /* Restore the buffer registers immediately. */ |
paul@181 | 63 | |
paul@181 | 64 | ipc_message_restore_buffer_registers(msg); |
paul@181 | 65 | |
paul@181 | 66 | return L4_EOK; |
paul@181 | 67 | } |
paul@181 | 68 | |
paul@181 | 69 | /* Free capabilities expected in messages. */ |
paul@181 | 70 | |
paul@181 | 71 | void ipc_message_free(ipc_message_t *msg) |
paul@181 | 72 | { |
paul@181 | 73 | _free_expected_capabilities(&msg->bregs, msg->expected_items); |
paul@181 | 74 | } |
paul@181 | 75 | |
paul@181 | 76 | /* Clear message attributes for sending and response handling. */ |
paul@181 | 77 | |
paul@181 | 78 | void ipc_message_new(ipc_message_t *msg) |
paul@181 | 79 | { |
paul@181 | 80 | /* Set a default for expected items. */ |
paul@181 | 81 | |
paul@181 | 82 | msg->expected_items = 0; |
paul@181 | 83 | ipc_message_reset(msg); |
paul@181 | 84 | } |
paul@181 | 85 | |
paul@181 | 86 | /* Open an incoming message by resetting sending state and preserving the |
paul@181 | 87 | message registers plus the buffer registers for the expected number of |
paul@181 | 88 | items. */ |
paul@181 | 89 | |
paul@181 | 90 | void ipc_message_open(ipc_message_t *msg) |
paul@181 | 91 | { |
paul@181 | 92 | ipc_message_reset(msg); |
paul@181 | 93 | ipc_message_preserve_buffer_registers(msg); |
paul@181 | 94 | ipc_message_preserve_message_registers(msg); |
paul@181 | 95 | } |
paul@181 | 96 | |
paul@181 | 97 | /* Preserve the buffer registers. */ |
paul@181 | 98 | |
paul@181 | 99 | void ipc_message_preserve_buffer_registers(ipc_message_t *msg) |
paul@181 | 100 | { |
paul@181 | 101 | unsigned int i; |
paul@181 | 102 | |
paul@181 | 103 | /* Reference the UTCB virtual registers. */ |
paul@181 | 104 | |
paul@181 | 105 | l4_buf_regs_t *bregs = l4_utcb_br(); |
paul@181 | 106 | |
paul@181 | 107 | msg->bregs.bdr = bregs->bdr; |
paul@181 | 108 | |
paul@181 | 109 | for (i = 0; i < msg->expected_items; i++) |
paul@181 | 110 | msg->bregs.br[i] = bregs->br[i]; |
paul@181 | 111 | } |
paul@181 | 112 | |
paul@181 | 113 | /* Preserve the message registers. */ |
paul@181 | 114 | |
paul@181 | 115 | void ipc_message_preserve_message_registers(ipc_message_t *msg) |
paul@181 | 116 | { |
paul@181 | 117 | /* Compute the number of message register words affected. */ |
paul@181 | 118 | |
paul@181 | 119 | unsigned int i, affected_words = l4_msgtag_words(msg->tag) + |
paul@181 | 120 | 2 * l4_msgtag_items(msg->tag); |
paul@181 | 121 | |
paul@181 | 122 | /* Reference the UTCB virtual registers. */ |
paul@181 | 123 | |
paul@181 | 124 | l4_msg_regs_t *mregs = l4_utcb_mr(); |
paul@181 | 125 | |
paul@181 | 126 | /* Copy message register information. */ |
paul@181 | 127 | |
paul@181 | 128 | for (i = 0; i < affected_words; i++) |
paul@181 | 129 | msg->mregs.mr[i] = mregs->mr[i]; |
paul@181 | 130 | } |
paul@181 | 131 | |
paul@181 | 132 | /* Restore the message and buffer registers. */ |
paul@181 | 133 | |
paul@181 | 134 | void ipc_message_prepare(ipc_message_t *msg) |
paul@181 | 135 | { |
paul@181 | 136 | ipc_message_restore_buffer_registers(msg); |
paul@181 | 137 | ipc_message_restore_message_registers(msg); |
paul@181 | 138 | } |
paul@181 | 139 | |
paul@181 | 140 | /* Restore buffer registers so that item expectations can be set. */ |
paul@181 | 141 | |
paul@181 | 142 | void ipc_message_restore_buffer_registers(ipc_message_t *msg) |
paul@181 | 143 | { |
paul@181 | 144 | unsigned int i; |
paul@181 | 145 | |
paul@181 | 146 | /* Reference the UTCB virtual registers. */ |
paul@181 | 147 | |
paul@181 | 148 | l4_buf_regs_t *bregs = l4_utcb_br(); |
paul@181 | 149 | |
paul@181 | 150 | /* Restore buffer register information. */ |
paul@181 | 151 | |
paul@181 | 152 | bregs->bdr = msg->bregs.bdr; |
paul@181 | 153 | |
paul@181 | 154 | for (i = 0; i < msg->expected_items; i++) |
paul@181 | 155 | bregs->br[i] = msg->bregs.br[i]; |
paul@181 | 156 | } |
paul@181 | 157 | |
paul@181 | 158 | /* Restore message registers to communicate recorded data and items. */ |
paul@181 | 159 | |
paul@181 | 160 | void ipc_message_restore_message_registers(ipc_message_t *msg) |
paul@181 | 161 | { |
paul@181 | 162 | /* Compute the number of message register words affected. */ |
paul@181 | 163 | |
paul@181 | 164 | unsigned int i, affected_words = msg->words + 2 * msg->items; |
paul@181 | 165 | |
paul@181 | 166 | /* Reference the UTCB virtual registers. */ |
paul@181 | 167 | |
paul@181 | 168 | l4_msg_regs_t *mregs = l4_utcb_mr(); |
paul@181 | 169 | |
paul@181 | 170 | /* Restore message register information. */ |
paul@181 | 171 | |
paul@181 | 172 | for (i = 0; i < affected_words; i++) |
paul@181 | 173 | mregs->mr[i] = msg->mregs.mr[i]; |
paul@181 | 174 | } |
paul@181 | 175 | |
paul@181 | 176 | /* Prepare and send a reply using the message. */ |
paul@181 | 177 | |
paul@181 | 178 | void ipc_message_reply(ipc_message_t *msg) |
paul@181 | 179 | { |
paul@181 | 180 | ipc_message_prepare(msg); |
paul@181 | 181 | msg->tag = util_ipc_reply(ipc_message_reply_tag(msg)); |
paul@181 | 182 | } |
paul@181 | 183 | |
paul@181 | 184 | /* Prepare and send a request using the message, involving the given operation, |
paul@181 | 185 | directed at the indicated endpoint. Open a message for the reply. */ |
paul@181 | 186 | |
paul@181 | 187 | void ipc_message_request(ipc_message_t *msg, int op, l4_cap_idx_t endpoint) |
paul@181 | 188 | { |
paul@181 | 189 | ipc_message_prepare(msg); |
paul@181 | 190 | msg->tag = util_ipc_request(ipc_message_request_tag(msg, op), endpoint); |
paul@181 | 191 | ipc_message_open(msg); |
paul@181 | 192 | } |
paul@181 | 193 | |
paul@181 | 194 | /* Prepare and send a message, involving the given operation, directed at the |
paul@181 | 195 | indicated endpoint. No reply is expected. */ |
paul@181 | 196 | |
paul@181 | 197 | void ipc_message_send(ipc_message_t *msg, int op, l4_cap_idx_t endpoint) |
paul@181 | 198 | { |
paul@181 | 199 | ipc_message_prepare(msg); |
paul@181 | 200 | msg->tag = util_ipc_send(ipc_message_request_tag(msg, op), endpoint); |
paul@181 | 201 | } |
paul@181 | 202 | |
paul@181 | 203 | /* Reset the state of the message for sending purposes. */ |
paul@181 | 204 | |
paul@181 | 205 | void ipc_message_reset(ipc_message_t *msg) |
paul@181 | 206 | { |
paul@181 | 207 | /* Initialise words and items for sending. */ |
paul@181 | 208 | |
paul@181 | 209 | msg->discarded_items = 0; |
paul@181 | 210 | msg->words = 0; |
paul@181 | 211 | msg->items = 0; |
paul@181 | 212 | |
paul@181 | 213 | /* Message label overriding. */ |
paul@181 | 214 | |
paul@181 | 215 | msg->new_label = 0; |
paul@181 | 216 | |
paul@181 | 217 | /* Server control. */ |
paul@181 | 218 | |
paul@181 | 219 | msg->terminating = 0; |
paul@181 | 220 | } |
paul@181 | 221 | |
paul@181 | 222 | /* Wait for an incoming message. */ |
paul@181 | 223 | |
paul@181 | 224 | void ipc_message_wait(ipc_message_t *msg, l4_umword_t *label) |
paul@181 | 225 | { |
paul@181 | 226 | msg->tag = l4_ipc_wait(l4_utcb(), label, L4_IPC_NEVER); |
paul@181 | 227 | } |
paul@181 | 228 | |
paul@181 | 229 | |
paul@181 | 230 | |
paul@181 | 231 | /* Add a capability to the message. */ |
paul@181 | 232 | |
paul@181 | 233 | void ipc_message_add_capability(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 234 | { |
paul@181 | 235 | ipc_message_export_capability(msg, msg->items++, cap); |
paul@181 | 236 | if (cap & IPC_DISCARD_CAP_FLAG) |
paul@181 | 237 | ipc_message_discard_capability(msg, cap & ~IPC_DISCARD_CAP_FLAG); |
paul@181 | 238 | } |
paul@181 | 239 | |
paul@181 | 240 | /* Add an item to the message. */ |
paul@181 | 241 | |
paul@181 | 242 | void ipc_message_add_item(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 243 | { |
paul@181 | 244 | ipc_message_export_capability(msg, msg->items++, cap); |
paul@181 | 245 | if (cap & IPC_DISCARD_CAP_FLAG) |
paul@181 | 246 | ipc_message_discard_capability(msg, cap & ~IPC_DISCARD_CAP_FLAG); |
paul@181 | 247 | } |
paul@181 | 248 | |
paul@181 | 249 | /* Add a flexpage to the message using a type to combine the "hot spot" and |
paul@181 | 250 | flexpage. */ |
paul@181 | 251 | |
paul@181 | 252 | void ipc_message_add_fpage(ipc_message_t *msg, l4_snd_fpage_t fpage) |
paul@181 | 253 | { |
paul@181 | 254 | ipc_message_export_fpage(msg, msg->items++, fpage); |
paul@181 | 255 | } |
paul@181 | 256 | |
paul@181 | 257 | /* Add a flexpage to the message. */ |
paul@181 | 258 | |
paul@181 | 259 | void ipc_message_add_page(ipc_message_t *msg, l4_umword_t hot_spot, |
paul@181 | 260 | l4_fpage_t fpage) |
paul@181 | 261 | { |
paul@181 | 262 | ipc_message_export_page(msg, msg->items++, hot_spot, fpage); |
paul@181 | 263 | } |
paul@181 | 264 | |
paul@181 | 265 | /* Add a word value to the message. */ |
paul@181 | 266 | |
paul@181 | 267 | void ipc_message_add_word(ipc_message_t *msg, l4_umword_t value) |
paul@181 | 268 | { |
paul@181 | 269 | /* NOTE: Should raise an exception if there are items. */ |
paul@181 | 270 | |
paul@181 | 271 | if (!msg->items) |
paul@181 | 272 | msg->mregs.mr[msg->words++] = value; |
paul@181 | 273 | } |
paul@181 | 274 | |
paul@181 | 275 | /* Add the given dimensioned data to the message. */ |
paul@181 | 276 | |
paul@181 | 277 | void ipc_message_add_data(ipc_message_t *msg, const char *value, size_t length) |
paul@181 | 278 | { |
paul@181 | 279 | void *target = ipc_message_reserve_data(msg, length); |
paul@181 | 280 | |
paul@181 | 281 | memcpy(target, value, length); |
paul@181 | 282 | } |
paul@181 | 283 | |
paul@181 | 284 | /* Add the given null-terminated character string to the message. */ |
paul@181 | 285 | |
paul@181 | 286 | void ipc_message_add_string(ipc_message_t *msg, const char *value) |
paul@181 | 287 | { |
paul@181 | 288 | ipc_message_add_data(msg, value, strlen(value) + 1); |
paul@181 | 289 | } |
paul@181 | 290 | |
paul@181 | 291 | /* Propagate the given item to the message. */ |
paul@181 | 292 | |
paul@181 | 293 | void ipc_message_propagate_item(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 294 | { |
paul@181 | 295 | ipc_message_propagate_capability(msg, msg->items++, cap); |
paul@181 | 296 | } |
paul@181 | 297 | |
paul@181 | 298 | /* Indicate an error condition in the message. */ |
paul@181 | 299 | |
paul@181 | 300 | void ipc_message_send_error(ipc_message_t *msg, long error) |
paul@181 | 301 | { |
paul@181 | 302 | msg->new_label = error; |
paul@181 | 303 | } |
paul@181 | 304 | |
paul@181 | 305 | /* Return a word value from the message. */ |
paul@181 | 306 | |
paul@181 | 307 | l4_umword_t ipc_message_get_word(ipc_message_t *msg, unsigned int word) |
paul@181 | 308 | { |
paul@181 | 309 | return msg->mregs.mr[word]; |
paul@181 | 310 | } |
paul@181 | 311 | |
paul@181 | 312 | /* Return a pointer to a word in the message. */ |
paul@181 | 313 | |
paul@181 | 314 | l4_umword_t *ipc_message_get_word_address(ipc_message_t *msg, unsigned int word) |
paul@181 | 315 | { |
paul@181 | 316 | return &msg->mregs.mr[word]; |
paul@181 | 317 | } |
paul@181 | 318 | |
paul@181 | 319 | /* Return the number of received items. */ |
paul@181 | 320 | |
paul@181 | 321 | unsigned int ipc_message_number_of_items(ipc_message_t *msg) |
paul@181 | 322 | { |
paul@181 | 323 | return l4_msgtag_items(msg->tag); |
paul@181 | 324 | } |
paul@181 | 325 | |
paul@181 | 326 | /* Return the number of received words. */ |
paul@181 | 327 | |
paul@181 | 328 | unsigned int ipc_message_number_of_words(ipc_message_t *msg) |
paul@181 | 329 | { |
paul@181 | 330 | return l4_msgtag_words(msg->tag); |
paul@181 | 331 | } |
paul@181 | 332 | |
paul@181 | 333 | /* Message tag generation. */ |
paul@181 | 334 | |
paul@181 | 335 | l4_msgtag_t ipc_message_reply_tag(ipc_message_t *msg) |
paul@181 | 336 | { |
paul@181 | 337 | return l4_msgtag(msg->new_label, msg->words, msg->items, 0); |
paul@181 | 338 | } |
paul@181 | 339 | |
paul@181 | 340 | l4_msgtag_t ipc_message_request_tag(ipc_message_t *msg, int op) |
paul@181 | 341 | { |
paul@181 | 342 | return l4_msgtag(op, msg->words, msg->items, 0); |
paul@181 | 343 | } |
paul@181 | 344 | |
paul@181 | 345 | /* Reserve space for dimensioned data, returning a pointer to use to add the |
paul@181 | 346 | data. The length of the data is incorporated into the message. */ |
paul@181 | 347 | |
paul@181 | 348 | void *ipc_message_reserve_data(ipc_message_t *msg, size_t length) |
paul@181 | 349 | { |
paul@181 | 350 | /* Indicate the length of the data. */ |
paul@181 | 351 | |
paul@181 | 352 | ipc_message_add_word(msg, length); |
paul@181 | 353 | |
paul@181 | 354 | /* Reserve the space. */ |
paul@181 | 355 | |
paul@181 | 356 | return ipc_message_reserve_words(msg, length); |
paul@181 | 357 | } |
paul@181 | 358 | |
paul@181 | 359 | /* Reserve space for dimensioned data, returning a pointer to use to add the |
paul@181 | 360 | data. The length is not incorporated into the message. */ |
paul@181 | 361 | |
paul@181 | 362 | void *ipc_message_reserve_words(ipc_message_t *msg, size_t length) |
paul@181 | 363 | { |
paul@181 | 364 | /* Calculate the rounded-up size of the data and the necessary padding. */ |
paul@181 | 365 | |
paul@181 | 366 | size_t size = get_size_in_words(length); |
paul@181 | 367 | size_t padding = size - length; |
paul@181 | 368 | void *target; |
paul@181 | 369 | |
paul@181 | 370 | /* NOTE: Should test the length against the capacity of the message. */ |
paul@181 | 371 | |
paul@181 | 372 | /* Obtain the location of the next word, where the data will be copied. */ |
paul@181 | 373 | |
paul@181 | 374 | target = &msg->mregs.mr[msg->words]; |
paul@181 | 375 | |
paul@181 | 376 | /* Pad the data and update the number of words. */ |
paul@181 | 377 | |
paul@181 | 378 | memset(target + length, 0, padding); |
paul@181 | 379 | msg->words += size / sizeof(l4_umword_t); |
paul@181 | 380 | |
paul@181 | 381 | return target; |
paul@181 | 382 | } |
paul@181 | 383 | |
paul@181 | 384 | |
paul@181 | 385 | |
paul@181 | 386 | /* Discard a capability after replying. */ |
paul@181 | 387 | |
paul@181 | 388 | void ipc_message_discard_capability(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 389 | { |
paul@181 | 390 | msg->to_discard[msg->discarded_items++] = cap; |
paul@181 | 391 | } |
paul@181 | 392 | |
paul@181 | 393 | /* Discard a dataspace. */ |
paul@181 | 394 | |
paul@181 | 395 | void ipc_message_discard_dataspace(ipc_message_t *msg, l4re_ds_t mem, l4_addr_t addr) |
paul@181 | 396 | { |
paul@181 | 397 | ipc_message_discard_capability(msg, mem); |
paul@181 | 398 | ipc_detach_dataspace((void *) addr); |
paul@181 | 399 | } |
paul@181 | 400 | |
paul@181 | 401 | /* Reserve the given number slots from zero for incoming capabilities. */ |
paul@181 | 402 | |
paul@181 | 403 | long ipc_message_expect_capabilities(ipc_message_t *msg, int number) |
paul@181 | 404 | { |
paul@181 | 405 | msg->expected_items = number; |
paul@181 | 406 | return _expect_capabilities(&msg->bregs, number); |
paul@181 | 407 | } |
paul@181 | 408 | |
paul@181 | 409 | /* Reserve a slot for an incoming capability. */ |
paul@181 | 410 | |
paul@181 | 411 | long ipc_message_expect_capability(ipc_message_t *msg, int item) |
paul@181 | 412 | { |
paul@181 | 413 | if (item >= (int) msg->expected_items) |
paul@181 | 414 | msg->expected_items = item + 1; |
paul@181 | 415 | |
paul@181 | 416 | return _expect_capability(&msg->bregs, item); |
paul@181 | 417 | } |
paul@181 | 418 | |
paul@181 | 419 | /* Export a capability at the given position in the message. */ |
paul@181 | 420 | |
paul@181 | 421 | void ipc_message_export_capability(ipc_message_t *msg, int item, l4_cap_idx_t ref) |
paul@181 | 422 | { |
paul@181 | 423 | msg->mregs.mr[msg->words + item * 2] = 0 | L4_ITEM_MAP; |
paul@181 | 424 | msg->mregs.mr[msg->words + item * 2 + 1] = l4_obj_fpage(ref, 0, L4_FPAGE_RWX).raw; |
paul@181 | 425 | } |
paul@181 | 426 | |
paul@181 | 427 | /* Export a flexpage at the given position in the message. Here, the snd_base |
paul@181 | 428 | member of the flexpage structure is used to hold the "hot spot" value. */ |
paul@181 | 429 | |
paul@181 | 430 | void ipc_message_export_fpage(ipc_message_t *msg, int item, l4_snd_fpage_t fpage) |
paul@181 | 431 | { |
paul@181 | 432 | msg->mregs.mr[msg->words + item * 2] = l4_map_control(fpage.snd_base, L4_FPAGE_CACHEABLE, 0); |
paul@181 | 433 | msg->mregs.mr[msg->words + item * 2 + 1] = fpage.fpage.raw; |
paul@181 | 434 | } |
paul@181 | 435 | |
paul@181 | 436 | /* Export a flexpage at the given position in the message. */ |
paul@181 | 437 | |
paul@181 | 438 | void ipc_message_export_page(ipc_message_t *msg, int item, l4_umword_t hot_spot, l4_fpage_t fpage) |
paul@181 | 439 | { |
paul@181 | 440 | msg->mregs.mr[msg->words + item * 2] = l4_map_control(hot_spot, L4_FPAGE_CACHEABLE, 0); |
paul@181 | 441 | msg->mregs.mr[msg->words + item * 2 + 1] = fpage.raw; |
paul@181 | 442 | } |
paul@181 | 443 | |
paul@181 | 444 | /* Import from the message the capability at the given item position, updating |
paul@181 | 445 | the buffer registers for future capabilities. */ |
paul@181 | 446 | |
paul@181 | 447 | long ipc_message_import_capability(ipc_message_t *msg, int item, l4_cap_idx_t *ref) |
paul@181 | 448 | { |
paul@181 | 449 | long err; |
paul@181 | 450 | |
paul@181 | 451 | err = _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, ref); |
paul@181 | 452 | if (err) |
paul@181 | 453 | return err; |
paul@181 | 454 | |
paul@181 | 455 | return ipc_message_expect_capability(msg, item); |
paul@181 | 456 | } |
paul@181 | 457 | |
paul@181 | 458 | /* Import from the message a dataspace, mapping it to an address, updating the |
paul@181 | 459 | buffer registers for future capabilities. */ |
paul@181 | 460 | |
paul@181 | 461 | long ipc_message_import_dataspace(ipc_message_t *msg, int item, l4re_ds_t *mem, l4_addr_t *addr) |
paul@181 | 462 | { |
paul@181 | 463 | long err; |
paul@181 | 464 | |
paul@181 | 465 | err = _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, mem, addr); |
paul@181 | 466 | if (err) |
paul@181 | 467 | return err; |
paul@181 | 468 | |
paul@181 | 469 | return ipc_message_expect_capability(msg, item); |
paul@181 | 470 | } |
paul@181 | 471 | |
paul@181 | 472 | /* Import from the message the flexpage at the given item position. */ |
paul@181 | 473 | |
paul@181 | 474 | long ipc_message_import_fpage(ipc_message_t *msg, int item, l4_snd_fpage_t *fpage) |
paul@181 | 475 | { |
paul@181 | 476 | return _import_fpage(msg->tag, &msg->bregs, &msg->mregs, item, fpage); |
paul@181 | 477 | } |
paul@181 | 478 | |
paul@181 | 479 | /* Export a capability, discarding it by propagating it to the recipient. */ |
paul@181 | 480 | |
paul@181 | 481 | void ipc_message_propagate_capability(ipc_message_t *msg, int item, l4_cap_idx_t ref) |
paul@181 | 482 | { |
paul@181 | 483 | ipc_message_export_capability(msg, item, ref); |
paul@181 | 484 | ipc_message_discard_capability(msg, ref); |
paul@181 | 485 | } |