From d8ad42b2400340a46e6a11da81aa8e4afd1d6681 Mon Sep 17 00:00:00 2001 From: liuchang01 Date: Wed, 12 May 2021 14:49:20 +0800 Subject: [PATCH] Fix SIGSEGV caused by negative mmoffset in 32bit system --- util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 04aaadd5..8ba41bd5 100644 --- a/util.c +++ b/util.c @@ -213,9 +213,9 @@ void *mem_chunk(off_t base, size_t len, const char *devmem) } #ifdef _SC_PAGESIZE - mmoffset = base % sysconf(_SC_PAGESIZE); + mmoffset = base & (sysconf(_SC_PAGESIZE) - 1); #else - mmoffset = base % getpagesize(); + mmoffset = base & (getpagesize() - 1); #endif /* _SC_PAGESIZE */ /* * Please note that we don't use mmap() for performance reasons here,