about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-10-24 11:40:22 +0200
committerptitSeb <sebastien.chev@gmail.com>2022-10-24 11:40:22 +0200
commite2a993a4255e1d17a067727b959afce507c20eec (patch)
treee740b862960e888847269e7d86d2829910d8420b /src
parentd0b5c79b81ecdcf2df4833dece74449b90766fea (diff)
downloadbox64-e2a993a4255e1d17a067727b959afce507c20eec.tar.gz
box64-e2a993a4255e1d17a067727b959afce507c20eec.zip
custom Alloc now allocate memory rounded up to 8bytes align
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/custommem.c b/src/custommem.c
index a874062e..9a34d2f6 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -255,8 +255,16 @@ static size_t sizeBlock(void* sub)
     return s->next.size;
 }
 
+static size_t roundSize(size_t size)
+{
+    if(!size)
+        return size;
+    return (size+7)&~7LL;   // 8 bytes align in size
+}
+
 void* customMalloc(size_t size)
 {
+    size = roundSize(size);
     // look for free space
     void* sub = NULL;
     pthread_mutex_lock(&mutex_blocks);
@@ -304,7 +312,7 @@ void* customMalloc(size_t size)
 }
 void* customCalloc(size_t n, size_t size)
 {
-    size_t newsize = n*size;
+    size_t newsize = roundSize(n*size);
     void* ret = customMalloc(newsize);
     memset(ret, 0, newsize);
     return ret;
@@ -313,6 +321,7 @@ void* customRealloc(void* p, size_t size)
 {
     if(!p)
         return customMalloc(size);
+    size = roundSize(size);
     uintptr_t addr = (uintptr_t)p;
     pthread_mutex_lock(&mutex_blocks);
     for(int i=0; i<n_blocks; ++i) {