qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: donno2048 <just4now666666@gmail.com>
Cc: qemu-devel@nongnu.org, donno2048 <just4now666666@gmail.com>
Subject: [PATCH 1/1] util/memfd: allow allocating 0 bytes
Date: Wed, 26 Mar 2025 16:19:27 +0000	[thread overview]
Message-ID: <20250326161927.15572-1-just4now666666@gmail.com> (raw)

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.

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");
     }
 
     *fd = mfd;
-- 
2.30.2



             reply	other threads:[~2025-03-26 16:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26 16:19 donno2048 [this message]
2025-05-05 15:46 ` [PATCH 1/1] util/memfd: allow allocating 0 bytes Elisha Hollander
2025-05-05 16:55 ` Marc-André Lureau
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=20250326161927.15572-1-just4now666666@gmail.com \
    --to=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).