1.1 --- a/libipc/include/ipc/util_ipc.h Tue Mar 07 19:10:40 2023 +0100
1.2 +++ b/libipc/include/ipc/util_ipc.h Thu Mar 09 19:27:22 2023 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Interprocess communication abstractions.
1.6 *
1.7 - * Copyright (C) 2018, 2019, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2019, 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -41,8 +41,8 @@
1.13 void _export_fpage(l4_msgtag_t tag, l4_msg_regs_t *mregs, int item, l4_snd_fpage_t fpage);
1.14 void _export_page(l4_msgtag_t tag, l4_msg_regs_t *mregs, int item, l4_umword_t hot_spot, l4_fpage_t fpage);
1.15 void _free_expected_capabilities(l4_buf_regs_t *bregs, int number);
1.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);
1.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);
1.18 +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);
1.19 +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);
1.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);
1.21
1.22 /* Convenience operations. */
2.1 --- a/libipc/lib/src/direct.c Tue Mar 07 19:10:40 2023 +0100
2.2 +++ b/libipc/lib/src/direct.c Thu Mar 09 19:27:22 2023 +0100
2.3 @@ -1,7 +1,7 @@
2.4 /*
2.5 * Interprocess communication abstractions.
2.6 *
2.7 - * Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
2.8 + * Copyright (C) 2018, 2019, 2021, 2023 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 @@ -54,7 +54,16 @@
2.13
2.14 long ipc_import_capability(l4_msgtag_t tag, int item, l4_cap_idx_t *ref)
2.15 {
2.16 - return _import_capability(tag, l4_utcb_br(), l4_utcb_mr(), item, ref);
2.17 + int local;
2.18 + long err = _import_capability(tag, l4_utcb_br(), l4_utcb_mr(), item, ref, &local);
2.19 +
2.20 + if (err)
2.21 + return err;
2.22 +
2.23 + if (local)
2.24 + return L4_EOK;
2.25 +
2.26 + return ipc_expect_capability(item);
2.27 }
2.28
2.29 /* Import a dataspace, mapping it to an address, updating the buffer registers
2.30 @@ -62,5 +71,17 @@
2.31
2.32 long ipc_import_dataspace(l4_msgtag_t tag, int item, l4re_ds_t *mem, l4_addr_t *addr)
2.33 {
2.34 - return _import_dataspace(tag, l4_utcb_br(), l4_utcb_mr(), item, mem, addr);
2.35 + int local;
2.36 + long err = _import_dataspace(tag, l4_utcb_br(), l4_utcb_mr(), item, mem, addr, &local);
2.37 +
2.38 + if (err)
2.39 + return err;
2.40 +
2.41 + if (local)
2.42 + return L4_EOK;
2.43 +
2.44 + return ipc_expect_capability(item);
2.45 }
2.46 +
2.47 +/* vim: tabstop=2 expandtab shiftwidth=2
2.48 +*/
3.1 --- a/libipc/lib/src/message.c Tue Mar 07 19:10:40 2023 +0100
3.2 +++ b/libipc/lib/src/message.c Thu Mar 09 19:27:22 2023 +0100
3.3 @@ -481,11 +481,15 @@
3.4 long ipc_message_import_capability(ipc_message_t *msg, int item, l4_cap_idx_t *ref)
3.5 {
3.6 long err;
3.7 + int local;
3.8
3.9 - err = _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, ref);
3.10 + err = _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, ref, &local);
3.11 if (err)
3.12 return err;
3.13
3.14 + if (local)
3.15 + return L4_EOK;
3.16 +
3.17 return ipc_message_expect_capability(msg, item);
3.18 }
3.19
3.20 @@ -495,11 +499,15 @@
3.21 long ipc_message_import_dataspace(ipc_message_t *msg, int item, l4re_ds_t *mem, l4_addr_t *addr)
3.22 {
3.23 long err;
3.24 + int local;
3.25
3.26 - err = _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, mem, addr);
3.27 + err = _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, mem, addr, &local);
3.28 if (err)
3.29 return err;
3.30
3.31 + if (local)
3.32 + return L4_EOK;
3.33 +
3.34 return ipc_message_expect_capability(msg, item);
3.35 }
3.36
4.1 --- a/libipc/lib/src/util_ipc.c Tue Mar 07 19:10:40 2023 +0100
4.2 +++ b/libipc/lib/src/util_ipc.c Thu Mar 09 19:27:22 2023 +0100
4.3 @@ -61,7 +61,7 @@
4.4 /* Indicate the expectation of a capability in return. */
4.5
4.6 bregs->bdr = 0;
4.7 - bregs->br[item] = L4_RCV_ITEM_SINGLE_CAP | future;
4.8 + bregs->br[item] = L4_RCV_ITEM_SINGLE_CAP | future | L4_RCV_ITEM_LOCAL_ID;
4.9
4.10 return L4_EOK;
4.11 }
4.12 @@ -126,7 +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 + l4_msg_regs_t *mregs, int item, l4_cap_idx_t *ref,
4.18 + int *local)
4.19 {
4.20 l4_snd_fpage_t fpage;
4.21 long err = _import_fpage(tag, bregs, mregs, item, &fpage);
4.22 @@ -134,15 +135,30 @@
4.23 if (err)
4.24 return err;
4.25
4.26 - /* Check for a received capability. */
4.27 + /* Check for a received capability and update the supplied capability
4.28 + index. */
4.29 +
4.30 + /* Inter-task capability transfer. */
4.31 +
4.32 + if ((fpage.snd_base & 0x3e) == 0x38)
4.33 + {
4.34 + *ref = bregs->br[item] & L4_CAP_MASK;
4.35 + *local = 0;
4.36 + }
4.37
4.38 - if ((fpage.snd_base & 0x3e) != 0x38)
4.39 + /* Local capability transfer. */
4.40 +
4.41 + else if ((fpage.snd_base & 0x3e) == 0x3e)
4.42 + {
4.43 + *ref = l4_fpage_obj(fpage.fpage);
4.44 + *local = 1;
4.45 + }
4.46 +
4.47 + /* Unsupported item. */
4.48 +
4.49 + else
4.50 return -L4_EIO;
4.51
4.52 - /* Update the supplied capability index. */
4.53 -
4.54 - *ref = bregs->br[item] & L4_CAP_MASK;
4.55 -
4.56 return L4_EOK;
4.57 }
4.58
4.59 @@ -150,18 +166,19 @@
4.60
4.61 long _import_dataspace(l4_msgtag_t tag, l4_buf_regs_t *bregs,
4.62 l4_msg_regs_t *mregs, int item, l4re_ds_t *mem,
4.63 - l4_addr_t *addr)
4.64 + l4_addr_t *addr, int *local)
4.65 {
4.66 long err;
4.67 unsigned long size;
4.68
4.69 *mem = ipc_cap_alloc();
4.70
4.71 - err = _import_capability(tag, bregs, mregs, item, mem);
4.72 + err = _import_capability(tag, bregs, mregs, item, mem, local);
4.73
4.74 if (err)
4.75 {
4.76 - ipc_cap_free_um(*mem);
4.77 + if (!*local)
4.78 + ipc_cap_free_um(*mem);
4.79 return err;
4.80 }
4.81