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.lur...@gmail.com>
wrote:

> Hi
>
> On Wed, Mar 26, 2025 at 8:21 PM donno2048 <just4now666...@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 <just4now666...@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
>

Reply via email to