qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: donno2048 <just4now666666@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 1/1] util/memfd: allow allocating 0 bytes
Date: Mon, 5 May 2025 20:55:29 +0400	[thread overview]
Message-ID: <CAJ+F1CKzKuO940euRhCb=tx_UQ-Ncs6k4yctipeT1v4vkinu3w@mail.gmail.com> (raw)
In-Reply-To: <20250326161927.15572-1-just4now666666@gmail.com>

Hi

On Wed, Mar 26, 2025 at 8:21 PM donno2048 <just4now666666@gmail.com> wrote:
>
> This silently fixes issues resulting from trying to allocate 0 bytes.
>
> Fixes error, for example, for writing byte 0x20 to port 0x3c0, then word 0xf09 to port 0x3b4 when CPU is initiated, which shouldn't break.
>

This is worth a test.

> Signed-off-by: donno2048 <just4now666666@gmail.com>
> ---
>  util/memfd.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/util/memfd.c b/util/memfd.c
> index 07beab174d..4f2c4ea1dd 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -131,9 +131,13 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,
>          }
>      }
>
> -    ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);
> -    if (ptr == MAP_FAILED) {
> -        goto err;
> +    if (size != 0) {
> +        ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);
> +        if (ptr == MAP_FAILED) {
> +            goto err;
> +        }
> +    } else {
> +        ptr = fdopen(mfd, "rw");

I don't understand fdopen() here, it returns a FILE*

>      }
>
>      *fd = mfd;
> --
> 2.30.2
>
>


-- 
Marc-André Lureau


  parent reply	other threads:[~2025-05-05 16:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26 16:19 [PATCH 1/1] util/memfd: allow allocating 0 bytes donno2048
2025-05-05 15:46 ` Elisha Hollander
2025-05-05 16:55 ` Marc-André Lureau [this message]
2025-05-05 17:03   ` Elisha Hollander
2025-05-05 17:28     ` Marc-André Lureau
2025-05-06  5:07       ` Elisha Hollander

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='CAJ+F1CKzKuO940euRhCb=tx_UQ-Ncs6k4yctipeT1v4vkinu3w@mail.gmail.com' \
    --to=marcandre.lureau@gmail.com \
    --cc=just4now666666@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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.
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).