qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] util/memfd: allow allocating 0 bytes
@ 2025-03-26 16:19 donno2048
  2025-05-05 15:46 ` Elisha Hollander
  2025-05-05 16:55 ` Marc-André Lureau
  0 siblings, 2 replies; 6+ messages in thread
From: donno2048 @ 2025-03-26 16:19 UTC (permalink / raw)
  Cc: qemu-devel, donno2048

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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-05-06  5:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-05-05 17:03   ` Elisha Hollander
2025-05-05 17:28     ` Marc-André Lureau
2025-05-06  5:07       ` Elisha Hollander

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).