From: Cole Helbling <cole.e.helbling@outlook.com>
To: Alyssa Ross <hi@alyssa.is>, devel@spectrum-os.org
Subject: Re: [PATCH wayland] Support virtio_wl display sockets
Date: Wed, 08 Jul 2020 08:43:54 -0700 [thread overview]
Message-ID: <SJ0PR03MB5581479F3388047230F36EB3B3670@SJ0PR03MB5581.namprd03.prod.outlook.com> (raw)
In-Reply-To: <20200708151600.10607-1-hi@alyssa.is>
Alyssa Ross <hi@alyssa.is> writes:
> src/connection.c | 4 +
> src/meson.build | 16 +-
> src/virtio_wl.c | 344 +++++++++++++++++++++++
> src/virtio_wl.h | 23 ++
> src/wayland-os.c | 23 ++
> src/wayland-os.h | 3 +
> src/wayland-server.c | 20 +-
> src/wayland-shm.c | 24 +-
> tests/meson.build | 1 +
> tests/virtio_wl-test.c | 615 +++++++++++++++++++++++++++++++++++++++++
> 10 files changed, 1064 insertions(+), 9 deletions(-)
> create mode 100644 src/virtio_wl.c
> create mode 100644 src/virtio_wl.h
> create mode 100644 tests/virtio_wl-test.c
>
> diff --git a/src/virtio_wl.c b/src/virtio_wl.c
> new file mode 100644
> index 0000000..a1ee8ee
> --- /dev/null
> +++ b/src/virtio_wl.c
(snip)
> +static size_t
> +fdbuf_to_cmsg(struct msghdr *msg, const int *buf, size_t buflen)
> +{
> + // Check msg->msg_control is long enough to fit at least one fd.
> + if (msg->msg_controllen < CMSG_SPACE(sizeof(int))) {
> +
> + // If there's at least one fd in buf, set MSG_CTRUNC.
> + size_t i = 0;
> + while (i < buflen && !(msg->msg_flags & MSG_CTRUNC))
> + if (buf[i++] != -1)
> + msg->msg_flags |= MSG_CTRUNC;
> +
> + return 0;
> + }
> +
> + // cmsg(3):
> + // > When initializing a buffer that will contain a series of cmsghdr
> + // > structures (e.g., to be sent with sendmsg(2)), that buffer should
> + // > first be zero-initialized to en‐ sure the correct operation of
> + // > CMSG_NXTHDR().
This comment looks weird -- both the misalignment (tabs vs spaces, it
seems) and "en- sure" (probably reflow mistake).
> + memset(msg->msg_control, 0, msg->msg_controllen);
> +
> + // Set up the cmsg.
> + struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg);
> + cmsg->cmsg_level = SOL_SOCKET;
> + cmsg->cmsg_type = SCM_RIGHTS;
> +
> + // Copy as many fds as fit into cmsg.
> + size_t len = 0;
> + for (size_t i = 0; i < buflen; i++) {
> + if (buf[i] == -1)
> + continue;
> +
> + if (CMSG_LEN((len + 1) * sizeof(int)) > msg->msg_controllen) {
> + msg->msg_flags |= MSG_CTRUNC;
> + break;
> + }
> +
> + memcpy(CMSG_DATA(cmsg) + sizeof(int) * len, &buf[i], sizeof(int));
> + len++;
> + }
> +
> + cmsg->cmsg_len = CMSG_LEN(len * sizeof(int));
> + return len;
> +}
I can't comment on the code itself, as I'm unfamiliar with both Wayland
and C. :D
Cole
next prev parent reply other threads:[~2020-07-08 15:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-08 15:16 Alyssa Ross
2020-07-08 15:43 ` Cole Helbling [this message]
2020-07-08 21:07 ` [PATCH wayland v2] " Alyssa Ross
2020-07-26 6:03 ` [PATCH wayland v3] " Alyssa Ross
2020-07-27 18:37 ` Cole Helbling
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SJ0PR03MB5581479F3388047230F36EB3B3670@SJ0PR03MB5581.namprd03.prod.outlook.com \
--to=cole.e.helbling@outlook.com \
--cc=devel@spectrum-os.org \
--cc=hi@alyssa.is \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).