1.1 --- a/libipc/include/ipc/message.h Sun Jan 21 17:35:01 2024 +0100
1.2 +++ b/libipc/include/ipc/message.h Sun Jan 21 17:56:36 2024 +0100
1.3 @@ -50,6 +50,10 @@
1.4
1.5 unsigned int receive_items;
1.6
1.7 + /* Imported item counter. */
1.8 +
1.9 + unsigned int import_item;
1.10 +
1.11 /* Output details. */
1.12
1.13 unsigned int words;
1.14 @@ -149,3 +153,6 @@
1.15 l4_msgtag_t ipc_message_request_tag(ipc_message_t *msg, int op);
1.16
1.17 EXTERN_C_END
1.18 +
1.19 +/* vim: tabstop=2 expandtab shiftwidth=2
1.20 +*/
2.1 --- a/libipc/include/ipc/util_ipc.h Sun Jan 21 17:35:01 2024 +0100
2.2 +++ b/libipc/include/ipc/util_ipc.h Sun Jan 21 17:56:36 2024 +0100
2.3 @@ -1,7 +1,7 @@
2.4 /*
2.5 * Interprocess communication abstractions.
2.6 *
2.7 - * Copyright (C) 2018, 2019, 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
2.8 + * Copyright (C) 2018-2024 Paul Boddie <paul@boddie.org.uk>
2.9 *
2.10 * This program is free software; you can redistribute it and/or
2.11 * modify it under the terms of the GNU General Public License as
2.12 @@ -41,8 +41,8 @@
2.13 void _export_fpage(l4_msgtag_t tag, l4_msg_regs_t *mregs, int item, l4_snd_fpage_t fpage);
2.14 void _export_page(l4_msgtag_t tag, l4_msg_regs_t *mregs, int item, l4_umword_t hot_spot, l4_fpage_t fpage);
2.15 void _free_expected_capabilities(l4_buf_regs_t *bregs, int number);
2.16 -long _import_capability(l4_msgtag_t tag, l4_buf_regs_t *bregs, l4_msg_regs_t *mregs, int item, l4_cap_idx_t *ref, int *local);
2.17 -long _import_dataspace(l4_msgtag_t tag, l4_buf_regs_t *bregs, l4_msg_regs_t *mregs, int item, l4re_ds_t *mem, l4_addr_t *addr, int *local);
2.18 +long _import_capability(l4_msgtag_t tag, l4_buf_regs_t *bregs, l4_msg_regs_t *mregs, int item, int buf_item, l4_cap_idx_t *ref, int *local);
2.19 +long _import_dataspace(l4_msgtag_t tag, l4_buf_regs_t *bregs, l4_msg_regs_t *mregs, int item, int buf_item, l4re_ds_t *mem, l4_addr_t *addr, int *local);
2.20 long _import_fpage(l4_msgtag_t tag, l4_buf_regs_t *bregs, l4_msg_regs_t *mregs, int item, l4_snd_fpage_t *fpage);
2.21
2.22 /* Convenience operations. */
3.1 --- a/libipc/lib/src/message.c Sun Jan 21 17:35:01 2024 +0100
3.2 +++ b/libipc/lib/src/message.c Sun Jan 21 17:56:36 2024 +0100
3.3 @@ -213,6 +213,7 @@
3.4 msg->discarded_items = 0;
3.5 msg->words = 0;
3.6 msg->items = 0;
3.7 + msg->import_item = 0;
3.8
3.9 /* Message label overriding. */
3.10
3.11 @@ -279,7 +280,7 @@
3.12 void ipc_message_add_receive_capability(ipc_message_t *msg, l4_cap_idx_t cap)
3.13 {
3.14 (void) cap;
3.15 - return _expect_capability(&msg->bregs, msg->receive_items++);
3.16 + _expect_capability(&msg->bregs, msg->receive_items++);
3.17 }
3.18
3.19 /* Add a receive window flexpage item to the message. */
3.20 @@ -502,14 +503,16 @@
3.21 long err;
3.22 int local;
3.23
3.24 - err = _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, ref, &local);
3.25 + err = _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, msg->import_item, ref, &local);
3.26 if (err)
3.27 return err;
3.28
3.29 if (local)
3.30 return L4_EOK;
3.31
3.32 - return ipc_message_expect_capability(msg, item);
3.33 + err = ipc_message_expect_capability(msg, msg->import_item);
3.34 + msg->import_item += 1;
3.35 + return err;
3.36 }
3.37
3.38 /* Import from the message a dataspace, mapping it to an address, updating the
3.39 @@ -520,14 +523,16 @@
3.40 long err;
3.41 int local;
3.42
3.43 - err = _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, mem, addr, &local);
3.44 + err = _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, msg->import_item, mem, addr, &local);
3.45 if (err)
3.46 return err;
3.47
3.48 if (local)
3.49 return L4_EOK;
3.50
3.51 - return ipc_message_expect_capability(msg, item);
3.52 + err = ipc_message_expect_capability(msg, msg->import_item);
3.53 + msg->import_item += 1;
3.54 + return err;
3.55 }
3.56
3.57 /* Import from the message the capability at the given item position. */
3.58 @@ -535,8 +540,14 @@
3.59 long ipc_message_import_capability(ipc_message_t *msg, int item, l4_cap_idx_t *ref)
3.60 {
3.61 int local;
3.62 + long err;
3.63
3.64 - return _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, ref, &local);
3.65 + err = _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, msg->import_item, ref, &local);
3.66 + if (err)
3.67 + return err;
3.68 +
3.69 + msg->import_item += local ? 0 : 1;
3.70 + return L4_EOK;
3.71 }
3.72
3.73 /* Import from the message a dataspace, mapping it to an address. */
3.74 @@ -544,8 +555,14 @@
3.75 long ipc_message_import_dataspace(ipc_message_t *msg, int item, l4re_ds_t *mem, l4_addr_t *addr)
3.76 {
3.77 int local;
3.78 + long err;
3.79
3.80 - return _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, mem, addr, &local);
3.81 + err = _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, msg->import_item, mem, addr, &local);
3.82 + if (err)
3.83 + return err;
3.84 +
3.85 + msg->import_item += local ? 0 : 1;
3.86 + return L4_EOK;
3.87 }
3.88
3.89 /* Import from the message the flexpage at the given item position. */
4.1 --- a/libipc/lib/src/util_ipc.c Sun Jan 21 17:35:01 2024 +0100
4.2 +++ b/libipc/lib/src/util_ipc.c Sun Jan 21 17:56:36 2024 +0100
4.3 @@ -1,7 +1,7 @@
4.4 /*
4.5 * Interprocess communication abstractions.
4.6 *
4.7 - * Copyright (C) 2018, 2019, 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
4.8 + * Copyright (C) 2018-2024 Paul Boddie <paul@boddie.org.uk>
4.9 *
4.10 * This program is free software; you can redistribute it and/or
4.11 * modify it under the terms of the GNU General Public License as
4.12 @@ -126,8 +126,8 @@
4.13 /* Import from the message the capability at the given item position. */
4.14
4.15 long _import_capability(l4_msgtag_t tag, l4_buf_regs_t *bregs,
4.16 - l4_msg_regs_t *mregs, int item, l4_cap_idx_t *ref,
4.17 - int *local)
4.18 + l4_msg_regs_t *mregs, int item, int buf_item,
4.19 + l4_cap_idx_t *ref, int *local)
4.20 {
4.21 l4_snd_fpage_t fpage;
4.22 long err = _import_fpage(tag, bregs, mregs, item, &fpage);
4.23 @@ -142,7 +142,7 @@
4.24
4.25 if ((fpage.snd_base & 0x3e) == 0x38)
4.26 {
4.27 - *ref = bregs->br[item] & L4_CAP_MASK;
4.28 + *ref = bregs->br[buf_item] & L4_CAP_MASK;
4.29 *local = 0;
4.30 }
4.31
4.32 @@ -165,15 +165,15 @@
4.33 /* Import from the message a dataspace, mapping it to an address. */
4.34
4.35 long _import_dataspace(l4_msgtag_t tag, l4_buf_regs_t *bregs,
4.36 - l4_msg_regs_t *mregs, int item, l4re_ds_t *mem,
4.37 - l4_addr_t *addr, int *local)
4.38 + l4_msg_regs_t *mregs, int item, int buf_item,
4.39 + l4re_ds_t *mem, l4_addr_t *addr, int *local)
4.40 {
4.41 long err;
4.42 unsigned long size;
4.43
4.44 *mem = ipc_cap_alloc();
4.45
4.46 - err = _import_capability(tag, bregs, mregs, item, mem, local);
4.47 + err = _import_capability(tag, bregs, mregs, item, buf_item, mem, local);
4.48
4.49 if (err)
4.50 {