Skip to content

Commit

Permalink
[ANDROID][BOX32] Fix __libc_init, Fix Some Warnings (#1887)
Browse files Browse the repository at this point in the history
* [ANDROID][BOX32] Fix __libc_init, Fix Some Warnings

* Fix More Warnings

* Revert fillALProcWrapper() change
  • Loading branch information
KreitinnSoftware authored Sep 29, 2024
1 parent 874238f commit a6baf1f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 27 deletions.
17 changes: 11 additions & 6 deletions src/custommem.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,13 @@ void* internal_customRealloc(void* p, size_t size, int is32bits)
return newp;
}
mutex_unlock(&mutex_blocks);
if(n_blocks)
if(n_blocks) {
if(is32bits) {
return box_realloc(p, size);
} else
} else {
printf_log(LOG_INFO, "Warning, block %p not found in p_blocks for realloc, malloc'ing again without free\n", (void*)addr);
}
}
return internal_customMalloc(size, is32bits);
}
void* customRealloc(void* p, size_t size)
Expand All @@ -588,8 +590,9 @@ void* customRealloc32(void* p, size_t size)

void internal_customFree(void* p, int is32bits)
{
if(!p)
if(!p) {
return;
}
uintptr_t addr = (uintptr_t)p;
mutex_lock(&mutex_blocks);
blocklist_t* l = findBlock(addr);
Expand All @@ -601,11 +604,13 @@ void internal_customFree(void* p, int is32bits)
return;
}
mutex_unlock(&mutex_blocks);
if(n_blocks)
if(is32bits)
if(n_blocks) {
if(is32bits) {
box_free(p);
else
} else {
printf_log(LOG_INFO, "Warning, block %p not found in p_blocks for Free\n", (void*)addr);
}
}
}
void customFree(void* p)
{
Expand Down
16 changes: 8 additions & 8 deletions src/elfs/elfload_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static const char* DumpSection(Elf64_Shdr *s, char* SST) {
return "SHT_NULL";
#define GO(A) \
case A: \
sprintf(buff, #A " Name=\"%s\"(%d) off=0x%lX, size=%ld, attr=0x%04lX, addr=%p(%02lX), link/info=%d/%d", \
sprintf(buff, #A " Name=\"%s\"(%d) off=0x%llX, size=%lld, attr=0x%04llX, addr=%p(%02llX), link/info=%d/%d", \
SST+s->sh_name, s->sh_name, s->sh_offset, s->sh_size, s->sh_flags, (void*)s->sh_addr, s->sh_addralign, s->sh_link, s->sh_info); \
break
GO(SHT_PROGBITS);
Expand Down Expand Up @@ -67,7 +67,7 @@ static const char* DumpDynamic(Elf64_Dyn *s) {
return "DT_NULL: End Dynamic Section";
#define GO(A, Add) \
case A: \
sprintf(buff, #A " %s=0x%lX", (Add)?"Addr":"Val", (Add)?s->d_un.d_ptr:s->d_un.d_val); \
sprintf(buff, #A " %s=0x%llX", (Add)?"Addr":"Val", (Add)?s->d_un.d_ptr:s->d_un.d_val); \
break
GO(DT_NEEDED, 0);
GO(DT_PLTRELSZ, 0);
Expand Down Expand Up @@ -139,7 +139,7 @@ static const char* DumpDynamic(Elf64_Dyn *s) {
#endif
#undef GO
default:
sprintf(buff, "0x%lX unknown type", s->d_tag);
sprintf(buff, "0x%llX unknown type", s->d_tag);
}
return buff;
}
Expand All @@ -150,7 +150,7 @@ static const char* DumpPHEntry(Elf64_Phdr *e)
memset(buff, 0, sizeof(buff));
switch(e->p_type) {
case PT_NULL: sprintf(buff, "type: %s", "PT_NULL"); break;
#define GO(T) case T: sprintf(buff, "type: %s, Off=%lx vaddr=%p paddr=%p filesz=%lu memsz=%lu flags=%x align=%lu", #T, e->p_offset, (void*)e->p_vaddr, (void*)e->p_paddr, e->p_filesz, e->p_memsz, e->p_flags, e->p_align); break
#define GO(T) case T: sprintf(buff, "type: %s, Off=%llx vaddr=%p paddr=%p filesz=%llu memsz=%llu flags=%x align=%llu", #T, e->p_offset, (void*)e->p_vaddr, (void*)e->p_paddr, e->p_filesz, e->p_memsz, e->p_flags, e->p_align); break
GO(PT_LOAD);
GO(PT_DYNAMIC);
GO(PT_INTERP);
Expand All @@ -166,7 +166,7 @@ static const char* DumpPHEntry(Elf64_Phdr *e)
GO(PT_GNU_RELRO);
#endif
#undef GO
default: sprintf(buff, "type: %x, Off=%lx vaddr=%p paddr=%p filesz=%lu memsz=%lu flags=%x align=%lu", e->p_type, e->p_offset, (void*)e->p_vaddr, (void*)e->p_paddr, e->p_filesz, e->p_memsz, e->p_flags, e->p_align); break;
default: sprintf(buff, "type: %x, Off=%llx vaddr=%p paddr=%p filesz=%llu memsz=%llu flags=%x align=%llu", e->p_type, e->p_offset, (void*)e->p_vaddr, (void*)e->p_paddr, e->p_filesz, e->p_memsz, e->p_flags, e->p_align); break;
}
return buff;
}
Expand Down Expand Up @@ -233,7 +233,7 @@ static const char* DumpSym(elfheader_t *h, Elf64_Sym* sym, int version)
const char* vername = (version==-1)?"(none)":((version==0)?"*local*":((version==1)?"*global*":GetSymbolVersion(h, version)));
int veropt = GetSymbolVersionFlag(h, version)?0:1;
memset(buff, 0, sizeof(buff));
sprintf(buff, "\"%s\", value=%p, size=%ld, info/other=%d/%d index=%d (%sver=%d/%s)",
sprintf(buff, "\"%s\", value=%p, size=%lld, info/other=%d/%d index=%d (%sver=%d/%s)",
h->DynStr+sym->st_name, (void*)sym->st_value, sym->st_size,
sym->st_info, sym->st_other, sym->st_shndx, veropt?"opt":"", version, vername);
return buff;
Expand Down Expand Up @@ -379,7 +379,7 @@ void DumpRelTable64(elfheader_t *h, int cnt, Elf64_Rel *rel, const char* name)
const char* elfname = ElfName(h);
printf_dump(LOG_NEVER, "ELF Dump %s Table(%d) @%p\n", name, cnt, rel);
for (int i = 0; i<cnt; ++i)
printf_dump(LOG_NEVER, " %s:Rel[%d] = %p (0x%lX: %s, sym=0x%0lX/%s)\n", elfname,
printf_dump(LOG_NEVER, " %s:Rel[%d] = %p (0x%llX: %s, sym=0x%0lX/%s)\n", elfname,
i, (void*)rel[i].r_offset, rel[i].r_info, DumpRelType64(ELF64_R_TYPE(rel[i].r_info)),
ELF64_R_SYM(rel[i].r_info), IdxSymName(h, ELF64_R_SYM(rel[i].r_info)));
printf_dump(LOG_NEVER, "ELF Dump Rel Table=====\n");
Expand All @@ -394,7 +394,7 @@ void DumpRelATable64(elfheader_t *h, int cnt, Elf64_Rela *rela, const char* name
const char* elfname = ElfName(h);
printf_dump(LOG_NEVER, "ELF Dump %s Table(%d) @%p\n", name, cnt, rela);
for (int i = 0; i<cnt; ++i)
printf_dump(LOG_NEVER, " %s:%s[%d] = %p (0x%lX: %s, sym=0x%lX/%s) Addend=0x%lx\n", elfname, name,
printf_dump(LOG_NEVER, " %s:%s[%d] = %p (0x%llX: %s, sym=0x%llX/%s) Addend=0x%llx\n", elfname, name,
i, (void*)rela[i].r_offset, rela[i].r_info, DumpRelType64(ELF64_R_TYPE(rela[i].r_info)),
ELF64_R_SYM(rela[i].r_info), IdxSymName(h, ELF64_R_SYM(rela[i].r_info)),
rela[i].r_addend);
Expand Down
8 changes: 5 additions & 3 deletions src/elfs/elfloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,10 +1512,12 @@ static void* find_dl_iterate_phdr_Fct(void* fct)
#undef SUPER

EXPORT int my32_dl_iterate_phdr(x64emu_t *emu, void* F, void *data)
#ifndef BOX32
{ }
#ifdef BOX32
;
#else
;
{
return -1;
}
#endif
EXPORT int my_dl_iterate_phdr(x64emu_t *emu, void* F, void *data) {
if(box64_is32bits) return my32_dl_iterate_phdr(emu, F, data);
Expand Down
2 changes: 1 addition & 1 deletion src/librarian/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ int IsSameLib(library_t* lib, const char* path)
ret=1;
} else {
char rpath[PATH_MAX];
box_realpath(path, rpath);
(void) box_realpath(path, rpath);
if(!strcmp(rpath, lib->path))
ret=1;
if(lib->type==LIB_EMULATED && lib->e.elf->path && !strcmp(lib->e.elf->path, rpath)) {
Expand Down
3 changes: 2 additions & 1 deletion src/tools/gtkclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -5543,14 +5543,15 @@ my_GtkTypeInfo_t* findFreeGtkTypeInfo(my_GtkTypeInfo_t* fcts, size_t parent)
my_gtktypeinfo_##A.class_size = fcts->class_size; \
my_gtktypeinfo_##A.class_init_func = (fcts->class_init_func)?((GetNativeFnc((uintptr_t)fcts->class_init_func))?GetNativeFnc((uintptr_t)fcts->class_init_func):my_gtk_class_init_##A):NULL; \
fct_gtk_class_init_##A = (uintptr_t)fcts->class_init_func; \
my_gtktypeinfo_##A.object_init_func = (fcts->object_init_func)?((GetNativeFnc((uintptr_t)fcts->object_init_func))?GetNativeFnc((uintptr_t)fcts->object_init_func):my_gtk_object_init_##A):NULL; \
my_gtktypeinfo_##A.object_init_func = (fcts->object_init_func)?((GetNativeFnc((uintptr_t)fcts->object_init_func))?(void (*)(void *, void *))GetNativeFnc((uintptr_t)fcts->object_init_func):my_gtk_object_init_##A):NULL; \

This comment has been minimized.

Copy link
@ptitSeb

ptitSeb Sep 29, 2024

Owner

This change broke the build on my side, so I will remove it (it should be all in ( ) , but I prefer to let it as-is.
What kind of warning were you trying to fix?
because ̀ANYTHING*tovoid*` or the other way around is fine to me, and I use that a lot and don't plan to change it...

fct_gtk_object_init_##A = (uintptr_t)fcts->object_init_func; \
my_gtktypeinfo_##A.reserved_1 = fcts->reserved_1; \
my_gtktypeinfo_##A.reserved_2 = fcts->reserved_2; \
my_gtktypeinfo_##A.base_class_init_func = (fcts->base_class_init_func)?((GetNativeFnc((uintptr_t)fcts->base_class_init_func))?GetNativeFnc((uintptr_t)fcts->base_class_init_func):my_gtk_base_class_init_##A):NULL; \
fct_gtk_base_class_init_##A = (uintptr_t)fcts->base_class_init_func; \
return &my_gtktypeinfo_##A; \
}

SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for GtkTypeInfo callback\n");
Expand Down
10 changes: 5 additions & 5 deletions src/wrapped/wrappedgobject2.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,15 @@ static my_GParamSpecTypeInfo_t* findFreeGParamSpecTypeInfo(my_GParamSpecTypeInfo
#undef GO
#define GO(A) if(ref_GParamSpecTypeInfo_##A == 0) { \
ref_GParamSpecTypeInfo_##A = fcts; \
my_GParamSpecTypeInfo_##A.instance_init = (fcts->instance_init)?((GetNativeFnc((uintptr_t)fcts->instance_init))?GetNativeFnc((uintptr_t)fcts->instance_init):my_funcs_instance_init_##A):NULL; \
my_GParamSpecTypeInfo_##A.instance_init = (fcts->instance_init)?((GetNativeFnc((uintptr_t)fcts->instance_init))?(void (*)(void *))GetNativeFnc((uintptr_t)fcts->instance_init):my_funcs_instance_init_##A):NULL; \
fct_funcs_instance_init_##A = (uintptr_t)fcts->instance_init; \
my_GParamSpecTypeInfo_##A.finalize = (fcts->finalize)?((GetNativeFnc((uintptr_t)fcts->finalize))?GetNativeFnc((uintptr_t)fcts->finalize):my_funcs_finalize_##A):NULL; \
my_GParamSpecTypeInfo_##A.finalize = (fcts->finalize)?((GetNativeFnc((uintptr_t)fcts->finalize))?(void (*)(void *))GetNativeFnc((uintptr_t)fcts->finalize):my_funcs_finalize_##A):NULL; \
fct_funcs_finalize_##A = (uintptr_t)fcts->finalize; \
my_GParamSpecTypeInfo_##A.value_set_default = (fcts->value_set_default)?((GetNativeFnc((uintptr_t)fcts->value_set_default))?GetNativeFnc((uintptr_t)fcts->value_set_default):my_funcs_value_set_default_##A):NULL; \
my_GParamSpecTypeInfo_##A.value_set_default = (fcts->value_set_default)?((GetNativeFnc((uintptr_t)fcts->value_set_default))?(void (*)(void *, void *))GetNativeFnc((uintptr_t)fcts->value_set_default):my_funcs_value_set_default_##A):NULL; \
fct_funcs_value_set_default_##A = (uintptr_t)fcts->value_set_default; \
my_GParamSpecTypeInfo_##A.value_validate = (fcts->value_validate)?((GetNativeFnc((uintptr_t)fcts->value_validate))?GetNativeFnc((uintptr_t)fcts->value_validate):my_funcs_value_validate_##A):NULL; \
my_GParamSpecTypeInfo_##A.value_validate = (fcts->value_validate)?((GetNativeFnc((uintptr_t)fcts->value_validate))?(int (*)(void *, void *))GetNativeFnc((uintptr_t)fcts->value_validate):my_funcs_value_validate_##A):NULL; \
fct_funcs_value_validate_##A = (uintptr_t)fcts->value_validate; \
my_GParamSpecTypeInfo_##A.values_cmp = (fcts->values_cmp)?((GetNativeFnc((uintptr_t)fcts->values_cmp))?GetNativeFnc((uintptr_t)fcts->values_cmp):my_funcs_values_cmp_##A):NULL; \
my_GParamSpecTypeInfo_##A.values_cmp = (fcts->values_cmp)?((GetNativeFnc((uintptr_t)fcts->values_cmp))?(int (*)(void *, void *, void *))GetNativeFnc((uintptr_t)fcts->values_cmp):my_funcs_values_cmp_##A):NULL; \
fct_funcs_values_cmp_##A = (uintptr_t)fcts->values_cmp; \
return &my_GParamSpecTypeInfo_##A; \
}
Expand Down
2 changes: 0 additions & 2 deletions src/wrapped/wrappedopenal.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ void my_alRequestFoldbackStop(x64emu_t* emu);

#include "wrappedlib_init.h"



void fillALProcWrapper()
{
int cnt, ret;
Expand Down
6 changes: 6 additions & 0 deletions src/wrapped32/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,20 @@ EXPORT int my32_statvfs(x64emu_t* emu, void* f, void* r)
}

// some my32_XXX declare and defines
#ifdef ANDROID
void my32___libc_init(x64emu_t* emu, void* raw_args , void (*onexit)(void) , int (*main)(int, char**, char**), void const * const structors );
#else
int32_t my32___libc_start_main(x64emu_t* emu, int *(main) (int, char * *, char * *),
int argc, char * * ubp_av, void (*init) (void), void (*fini) (void),
void (*rtld_fini) (void), void (* stack_end)); // implemented in x64run_private.c
#endif

EXPORT void my32___libc_init_first(x64emu_t* emu, int argc, char* arg0, char** b)
{
// do nothing specific for now
return;
}

uint32_t my32_syscall(x64emu_t *emu); // implemented in x64syscall.c
void EXPORT my32___stack_chk_fail(x64emu_t* emu)
{
Expand Down
2 changes: 1 addition & 1 deletion src/wrapped32/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ GO(fallocate64, iFiill)
//GOM(modify_ldt, iFEipL) // there is suposedly no glibc wrapper for this one

#ifdef ANDROID
GOM(__libc_init, vFEpppp)
//GOM(__libc_init, vFEpppp)
GO(__errno, pFv)
#else
// Those symbols don't exist in non-Android builds
Expand Down

0 comments on commit a6baf1f

Please sign in to comment.