about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-01-11 10:25:27 +0100
committerptitSeb <sebastien.chev@gmail.com>2025-01-11 10:26:02 +0100
commitf489761e682b75ede8754e9f9be48fa29ebaeb10 (patch)
treeeaa00441feadd61e7f0f291f7dfebd1fd7d3db2d
parent56ccde005e9332662326b8446658e7a322633e46 (diff)
downloadbox64-f489761e682b75ede8754e9f9be48fa29ebaeb10.tar.gz
box64-f489761e682b75ede8754e9f9be48fa29ebaeb10.zip
[BOX32] Improved elf memory managment for 32bits process
-rw-r--r--src/box32.c4
-rw-r--r--src/dynarec/arm64/dynarec_arm64_f20f.c8
-rw-r--r--src/elfs/elfloader.c22
-rwxr-xr-xsrc/elfs/elfparser32.c10
-rw-r--r--src/include/debug.h1
-rw-r--r--src/librarian/librarian.c2
-rw-r--r--src/mallochook.c7
7 files changed, 34 insertions, 20 deletions
diff --git a/src/box32.c b/src/box32.c
index 7ef84fbf..1bac0faa 100644
--- a/src/box32.c
+++ b/src/box32.c
@@ -314,7 +314,7 @@ ptr_t to_cstring(char* p) {
         // create a new key, but need write lock!
         pthread_rwlock_unlock(&hash_lock);
         pthread_rwlock_wrlock(&hash_lock);
-        ret = to_ptrv(box_strdup(p));
+        ret = to_ptrv(box32_strdup(p));
         int r;
         k = kh_put(strings, const_strings, (char*)from_ptrv(ret), &r);
         kh_value(const_strings, k) = ret;
@@ -335,7 +335,7 @@ ptr_t to_cstring_d(char* p) {
     } else {
         ret = kh_value(const_strings, k);
         kh_del(strings, const_strings, k);
-        free(from_ptrv(ret));
+        box32_free(from_ptrv(ret));
     }
     pthread_rwlock_unlock(&hash_lock);
     return ret;
diff --git a/src/dynarec/arm64/dynarec_arm64_f20f.c b/src/dynarec/arm64/dynarec_arm64_f20f.c
index 551e25e7..0a2c49f2 100644
--- a/src/dynarec/arm64/dynarec_arm64_f20f.c
+++ b/src/dynarec/arm64/dynarec_arm64_f20f.c
@@ -271,7 +271,13 @@ uintptr_t dynarec64_F20F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int n
             GETGX(v0, 1);

             GETEXSD(d0, 0, 0);

             d1 = fpu_get_scratch(dyn, ninst);

-            FCVT_S_D(d1, d0);

+            if(box64_dynarec_fastround==2) {

+                FCVT_S_D(d1, d0);

+            } else {

+                u8 = sse_setround(dyn, ninst, x1, x2, x3);

+                FCVT_S_D(d1, d0);

+                x87_restoreround(dyn, ninst, u8);

+            }

             VMOVeS(v0, 0, d1, 0);

             break;

 

diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c
index d8e1022b..9d54ac10 100644
--- a/src/elfs/elfloader.c
+++ b/src/elfs/elfloader.c
@@ -80,22 +80,22 @@ void FreeElfHeader(elfheader_t** head)
     if(my_context)
         RemoveElfHeader(my_context, h);
 
-    box_free(h->PHEntries._64); //_64 or _32 doesn't mater for free, it's the same address
-    box_free(h->SHEntries._64);
-    box_free(h->SHStrTab);
-    box_free(h->StrTab);
-    box_free(h->Dynamic._64);
-    box_free(h->DynStr);
-    box_free(h->SymTab._64);
-    box_free(h->DynSym._64);
+    actual_free(h->PHEntries._64); //_64 or _32 doesn't mater for free, it's the same address
+    actual_free(h->SHEntries._64);
+    actual_free(h->SHStrTab);
+    actual_free(h->StrTab);
+    actual_free(h->Dynamic._64);
+    actual_free(h->DynStr);
+    actual_free(h->SymTab._64);
+    actual_free(h->DynSym._64);
 
     FreeElfMemory(h);
 
-    box_free(h->name);
-    box_free(h->path);
+    actual_free(h->name);
+    actual_free(h->path);
     if(h->file)
         fclose(h->file);
-    box_free(h);
+    actual_free(h);
 
     *head = NULL;
 }
diff --git a/src/elfs/elfparser32.c b/src/elfs/elfparser32.c
index 376bb34d..c12ab40d 100755
--- a/src/elfs/elfparser32.c
+++ b/src/elfs/elfparser32.c
@@ -24,7 +24,7 @@ static int LoadSH(FILE *f, Elf32_Shdr *s, void** SH, const char* name, uint32_t
     if (type==SHT_SYMTAB && s->sh_size%sizeof(Elf32_Sym)) {
         printf_log(LOG_INFO, "Section Header \"%s\" (off=%d, size=%d) has size (not multiple of %ld)\n", name, s->sh_offset, s->sh_size, sizeof(Elf32_Sym));
     }
-    *SH = box_calloc(1, s->sh_size);
+    *SH = actual_calloc(1, s->sh_size);
     fseeko64(f, s->sh_offset ,SEEK_SET);
     if(fread(*SH, s->sh_size, 1, f)!=1) {
             printf_log(LOG_INFO, "Cannot read Section Header \"%s\" (off=%d, size=%d)\n", name, s->sh_offset, s->sh_size);
@@ -115,7 +115,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)
         return NULL;
     }
 
-    elfheader_t *h = box_calloc(1, sizeof(elfheader_t));
+    elfheader_t *h = actual_calloc(1, sizeof(elfheader_t));
     h->name = box_strdup(name);
     h->entrypoint = header.e_entry;
     h->numPHEntries = header.e_phnum;
@@ -130,7 +130,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)
             fseeko64(f, header.e_shoff, SEEK_SET);
             Elf32_Shdr section;
             if(fread(&section, sizeof(Elf32_Shdr), 1, f)!=1) {
-                box_free(h);
+                actual_free(h);
                 printf_log(LOG_INFO, "Cannot read Initial Section Header\n");
                 return NULL;
             }
@@ -138,7 +138,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)
         }
         // now read all section headers
         printf_log(LOG_DEBUG, "Read %d Section header\n", h->numSHEntries);
-        h->SHEntries._32 = (Elf32_Shdr*)box_calloc(h->numSHEntries, sizeof(Elf32_Shdr));
+        h->SHEntries._32 = (Elf32_Shdr*)actual_calloc(h->numSHEntries, sizeof(Elf32_Shdr));
         fseeko64(f, header.e_shoff ,SEEK_SET);
         if(fread(h->SHEntries._32, sizeof(Elf32_Shdr), h->numSHEntries, f)!=h->numSHEntries) {
                 FreeElfHeader(&h);
@@ -154,7 +154,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)
     }
 
     printf_log(LOG_DEBUG, "Read %d Program header\n", h->numPHEntries);
-    h->PHEntries._32 = (Elf32_Phdr*)box_calloc(h->numPHEntries, sizeof(Elf32_Phdr));
+    h->PHEntries._32 = (Elf32_Phdr*)actual_calloc(h->numPHEntries, sizeof(Elf32_Phdr));
     fseeko64(f, header.e_phoff ,SEEK_SET);
     if(fread(h->PHEntries._32, sizeof(Elf32_Phdr), h->numPHEntries, f)!=h->numPHEntries) {
             FreeElfHeader(&h);
diff --git a/src/include/debug.h b/src/include/debug.h
index ec1fb9d5..c710a249 100644
--- a/src/include/debug.h
+++ b/src/include/debug.h
@@ -196,6 +196,7 @@ void* box32_realloc(void* p, size_t s);
 void box32_free(void* p);
 void* box32_memalign(size_t align, size_t s);
 size_t box32_malloc_usable_size(void* p);
+char* box32_strdup(const char* s);
 
 #define actual_calloc(A, B)             (box64_is32bits?box32_calloc(A, B):box_calloc(A, B))
 #define actual_malloc(A)                (box64_is32bits?box32_malloc(A):box_malloc(A))
diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c
index 1d61aa2d..415278ae 100644
--- a/src/librarian/librarian.c
+++ b/src/librarian/librarian.c
@@ -266,7 +266,7 @@ static int AddNeededLib_add(lib_t** maplib, int local, needed_libs_t* needed, in
                 return 1;
             }
             lm->l_addr = (Elf32_Addr)to_ptrv(GetElfDelta(lib->e.elf));
-            lm->l_name = to_ptrv(lib->name);
+            lm->l_name = to_cstring(lib->name);
             lm->l_ld = to_ptrv(GetDynamicSection(lib->e.elf));
         } else
         #endif
diff --git a/src/mallochook.c b/src/mallochook.c
index ebd7a017..8094ca37 100644
--- a/src/mallochook.c
+++ b/src/mallochook.c
@@ -236,6 +236,13 @@ size_t box32_malloc_usable_size(void* p)
     else
         return box_malloc_usable_size(p);
 }
+
+char* box32_strdup(const char* s) {
+    char* ret = box32_calloc(1, strlen(s)+1);
+    memcpy(ret, s, strlen(s));
+    return ret;
+}
+
 #endif
 
 // redefining all libc memory allocation routines