* [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
* Re: [PATCH 1/1] util/memfd: allow allocating 0 bytes 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 1 sibling, 0 replies; 6+ messages in thread From: Elisha Hollander @ 2025-05-05 15:46 UTC (permalink / raw) Cc: qemu-devel [-- Attachment #1: Type: text/plain, Size: 1087 bytes --] ping On Wed, Mar 26, 2025, 18:20 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. > > 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 > > [-- Attachment #2: Type: text/html, Size: 1665 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] util/memfd: allow allocating 0 bytes 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 1 sibling, 1 reply; 6+ messages in thread From: Marc-André Lureau @ 2025-05-05 16:55 UTC (permalink / raw) To: donno2048; +Cc: qemu-devel 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] util/memfd: allow allocating 0 bytes 2025-05-05 16:55 ` Marc-André Lureau @ 2025-05-05 17:03 ` Elisha Hollander 2025-05-05 17:28 ` Marc-André Lureau 0 siblings, 1 reply; 6+ messages in thread From: Elisha Hollander @ 2025-05-05 17:03 UTC (permalink / raw) To: Marc-André Lureau; +Cc: qemu-devel [-- Attachment #1: Type: text/plain, Size: 1561 bytes --] Not necessarily fdopen, can't remember why I chose it, we just need any pointer as no data will be written into the buffer anyways On Mon, May 5, 2025, 19:55 Marc-André Lureau <marcandre.lureau@gmail.com> wrote: > 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 > [-- Attachment #2: Type: text/html, Size: 2281 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] util/memfd: allow allocating 0 bytes 2025-05-05 17:03 ` Elisha Hollander @ 2025-05-05 17:28 ` Marc-André Lureau 2025-05-06 5:07 ` Elisha Hollander 0 siblings, 1 reply; 6+ messages in thread From: Marc-André Lureau @ 2025-05-05 17:28 UTC (permalink / raw) To: Elisha Hollander; +Cc: qemu-devel Hi On Mon, May 5, 2025 at 9:03 PM Elisha Hollander <just4now666666@gmail.com> wrote: > > Not necessarily fdopen, can't remember why I chose it, we just need any pointer as no data will be written into the buffer anyways > NULL should be acceptable then. You need to explain in greater details what you are trying to solve. > > On Mon, May 5, 2025, 19:55 Marc-André Lureau <marcandre.lureau@gmail.com> wrote: >> >> 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 -- Marc-André Lureau ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] util/memfd: allow allocating 0 bytes 2025-05-05 17:28 ` Marc-André Lureau @ 2025-05-06 5:07 ` Elisha Hollander 0 siblings, 0 replies; 6+ messages in thread From: Elisha Hollander @ 2025-05-06 5:07 UTC (permalink / raw) To: Marc-André Lureau; +Cc: qemu-devel [-- Attachment #1: Type: text/plain, Size: 2644 bytes --] > You need to explain in greater details > what you are trying to solve. As I mentioned earlier, let's say you don't initialize the vertical display end registers, and set the minimum scanline register, the emulation will then have to allocate some display buffer, but because the vertical display end is initilized as 0 the buffer will be empty and the program break. Minimal example: mov al, 0x20 mov dx, 0x3c0 out dx, al mov dx, 0x3b4 ;mov ax, 0xff12 ;out dx, ax mov ax, 0xf09 out dx, ax uncommenting the commented lines will solve the issue. On Mon, May 5, 2025, 20:28 Marc-André Lureau <marcandre.lureau@gmail.com> wrote: > Hi > > On Mon, May 5, 2025 at 9:03 PM Elisha Hollander > <just4now666666@gmail.com> wrote: > > > > Not necessarily fdopen, can't remember why I chose it, we just need any > pointer as no data will be written into the buffer anyways > > > > NULL should be acceptable then. You need to explain in greater details > what you are trying to solve. > > > > > On Mon, May 5, 2025, 19:55 Marc-André Lureau <marcandre.lureau@gmail.com> > wrote: > >> > >> 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 > > > > -- > Marc-André Lureau > [-- Attachment #2: Type: text/html, Size: 3977 bytes --] ^ permalink raw reply [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).