[CRIU] [PATCHv4 3/8] aio: Allow expressions in NR_IOEVENTS_IN_PAGES macro

Dmitry Safonov dima at arista.com
Thu May 10 21:14:43 MSK 2018


The macro is used only in aio_estimate_nr_reqs():
unsigned int k_max_reqs = NR_IOEVENTS_IN_NPAGES(size/PAGE_SIZE);

Which compiler may evaluate as (((PAGE_SIZE*size)/PAGE_SIZE) - ...)
It works as long as PAGE_SIZE is long.
The patches set converts PAGE_SIZE to use sysconf() returning
(unsigned), non-long type and making the aio macro overflowing.

I do not see any value making PAGE_SIZE (unsigned long) typed.

Cc: Kirill Tkhai <ktkhai at virtuozzo.com>
Signed-off-by: Dmitry Safonov <dima at arista.com>
---
 criu/aio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/criu/aio.c b/criu/aio.c
index 27c251df587d..45651f2d3f36 100644
--- a/criu/aio.c
+++ b/criu/aio.c
@@ -13,7 +13,7 @@
 #include "images/mm.pb-c.h"
 #include <compel/compel.h>
 
-#define NR_IOEVENTS_IN_NPAGES(npages) ((PAGE_SIZE * npages - sizeof(struct aio_ring)) / sizeof(struct io_event))
+#define NR_IOEVENTS_IN_NPAGES(npages) ((PAGE_SIZE * (npages) - sizeof(struct aio_ring)) / sizeof(struct io_event))
 
 int dump_aio_ring(MmEntry *mme, struct vma_area *vma)
 {
-- 
2.13.6



More information about the CRIU mailing list