qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 3/3] linux-user/syscall.c: do_ppoll: eliminate large alloc


From: Michael Tokarev
Subject: Re: [PATCH v3 3/3] linux-user/syscall.c: do_ppoll: eliminate large alloca
Date: Thu, 14 Sep 2023 11:26:02 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0

14.09.2023 11:18, Daniel P. Berrangé wrote:
On Thu, Sep 14, 2023 at 10:43:37AM +0300, Michael Tokarev wrote:
do_ppoll() in linux-user/syscall.c uses alloca() to allocate
an array of struct pullfds on the stack.  The only upper
boundary for number of entries for this array is so that
whole thing fits in INT_MAX.  This is definitely too much
for stack allocation.

Use heap allocation when large number of entries is requested
(currently 32, arbitrary), and continue to use alloca() for

Typo ? The code uses 64 rather than 32.

Yeah, it's a typo, after a few iterations trying to split this
all into pieces and editing in the process.


-    struct pollfd *pfd = NULL;
+    struct pollfd *pfd = NULL, *heap_pfd = NULL;

g_autofree struct pollfd *heap_pdf = NULL;

...
out:
+    g_free(heap_pfd);

This can be dropped with g_autofree usage

Yes, I know this, - this was deliberate choice.
Personally I'm just too used to old-school explicit resource deallocations.
Here, there's a single place where everything gets freed, so there's little
reason to use fancy modern automatic deallocations. To my taste anyway.
Maybe some future modifications adding some future ppoll3.. :)

Sure thing I can drop that and change it to autofree.

Thanks,

/mjt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]