Skip to content

Commit

Permalink
Fixes (#1207)
Browse files Browse the repository at this point in the history
* Fixed signed/unsigned issues and other cosmetics

* [WRAPPERS] Fixed missing `return`s in `my_` functions

* [EMU] More fixes

* [STEAM] Forgot one cleanup

* [WRAPPER] Fixed wrappedpulse callback signatures
  • Loading branch information
rajdakin authored Jan 18, 2024
1 parent e963d99 commit 3a2073f
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 63 deletions.
6 changes: 3 additions & 3 deletions src/custommem.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static size_t getMaxFreeBlock(void* block, size_t block_size, void* start)
// get start of block
if(start) {
blockmark_t *m = (blockmark_t*)start;
int maxsize = 0;
unsigned int maxsize = 0;
while(m->next.x32) { // while there is a subblock
if(!m->next.fill && m->next.size>maxsize) {
maxsize = m->next.size;
Expand All @@ -160,7 +160,7 @@ static size_t getMaxFreeBlock(void* block, size_t block_size, void* start)
return (maxsize>=sizeof(blockmark_t))?maxsize:0;
} else {
blockmark_t *m = LAST_BLOCK(block, block_size); // start with the end
int maxsize = 0;
unsigned int maxsize = 0;
while(m->prev.x32) { // while there is a subblock
if(!m->prev.fill && m->prev.size>maxsize) {
maxsize = m->prev.size;
Expand Down Expand Up @@ -1505,7 +1505,7 @@ void reserveHighMem()
if(!p || p[0]=='0')
#endif
return; // don't reserve by default
intptr_t cur = 1LL<<47;
uintptr_t cur = 1ULL<<47;
mapmem_t* m = mapallmem;
while(m && (m->end<cur)) {
m = m->next;
Expand Down
2 changes: 1 addition & 1 deletion src/elfs/elfdwarf_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ uintptr_t get_parent_registers(dwarf_unwind_t *unwind, const elfheader_t *ehdr,
#undef PARSE_INST
box_free(init_statuses);
box_free(init_table);
for (int i = 0; i < maxstacksize; ++i) {
for (uint64_t i = 0; i < maxstacksize; ++i) {
box_free(table_stack[i]);
}
box_free(table_stack);
Expand Down
6 changes: 3 additions & 3 deletions src/elfs/elfloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ int RelocateElfPlt(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t*
return -1;
}
if(need_resolver) {
if(pltResolver==~0LL) {
if(pltResolver==(uintptr_t)-1) {
pltResolver = AddBridge(my_context->system, vFE, PltResolver, 0, "PltResolver");
}
if(head->pltgot) {
Expand Down Expand Up @@ -1216,7 +1216,7 @@ int LoadNeededLibs(elfheader_t* h, lib_t *maplib, int local, int bindnow, box64c
DumpDynamicNeeded(h);
int cnt = 0;
// count the number of needed libs, and also grab soname
for (int i=0; i<h->numDynamic; ++i) {
for (size_t i=0; i<h->numDynamic; ++i) {
if(h->Dynamic[i].d_tag==DT_NEEDED)
++cnt;
if(h->Dynamic[i].d_tag==DT_SONAME)
Expand All @@ -1226,7 +1226,7 @@ int LoadNeededLibs(elfheader_t* h, lib_t *maplib, int local, int bindnow, box64c
if(h == my_context->elfs[0])
my_context->neededlibs = h->needed;
int j=0;
for (int i=0; i<h->numDynamic; ++i)
for (size_t i=0; i<h->numDynamic; ++i)
if(h->Dynamic[i].d_tag==DT_NEEDED)
h->needed->names[j++] = h->DynStrTab+h->delta+h->Dynamic[i].d_un.d_val;

Expand Down
8 changes: 4 additions & 4 deletions src/emu/x64compstrings.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ static int overrideIfDataInvalid(sse_regs_t* mem, int lmem, sse_regs_t* reg, int
return (i&1)?((reg->uw[i]>=mem->uw[j])):((reg->uw[i]<=mem->uw[j]));
case 0b10: // sb
return (i&1)?((reg->sb[i]>=mem->sb[j])):((reg->sb[i]<=mem->sb[j]));
case 0b11: // sw
default: // sw
return (i&1)?((reg->sw[i]>=mem->sw[j])):((reg->sw[i]<=mem->sw[j]));
}
break;
default: // the others
switch (imm8&1) {
case 0: // byte
case 0: // byte
return (reg->ub[i] == mem->ub[j]);
case 1: // word
default: // word
return (reg->uw[i] == mem->uw[j]);
}
}
Expand Down Expand Up @@ -117,4 +117,4 @@ uint32_t sse42_compare_string_implicit_len(x64emu_t* emu, sse_regs_t* mem, sse_r
while(lreg<16 && reg->ub[lreg]) ++lreg;
}
return sse42_compare_string_explicit_len(emu, mem, lmem, reg, lreg, imm8);
}
}
9 changes: 7 additions & 2 deletions src/emu/x64run.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ int Run(x64emu_t *emu, int step)
unimp = 1;
goto fini;
}
if(step==2) STEP2;
if(step==2) {
STEP2;
}
#endif
break;
case 2:
Expand All @@ -197,7 +199,9 @@ int Run(x64emu_t *emu, int step)
unimp = 1;
goto fini;
}
if(step==2) STEP2;
if(step==2) {
STEP2;
}
#endif
break;
}
Expand Down Expand Up @@ -397,6 +401,7 @@ int Run(x64emu_t *emu, int step)
break;
case 0x62: /* BOUND Gd, Ed */
if(rex.is32bits) {
nextop = F8;
FAKEED(0);
} else {
unimp = 1;
Expand Down
3 changes: 2 additions & 1 deletion src/emu/x64run66.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ uintptr_t Run66(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
return Run66F30F(emu, rex, addr);
#endif
}
return 0; // unreachable

case 0x1E: /* PUSH DS */
if(!rex.is32bits) {
Expand Down Expand Up @@ -900,4 +901,4 @@ uintptr_t Run66(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr)
return 0;
}
return addr;
}
}
3 changes: 2 additions & 1 deletion src/emu/x64run6764_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ uintptr_t Test6764_32(x64test_t *test, rex_t rex, int rep, int seg, uintptr_t ad
uintptr_t Run6764_32(x64emu_t *emu, rex_t rex, int rep, int seg, uintptr_t addr)
#endif
{
(void)rep;
uint8_t opcode;
uint8_t nextop;
int8_t tmp8s;
Expand Down Expand Up @@ -88,4 +89,4 @@ uintptr_t Run6764_32(x64emu_t *emu, rex_t rex, int rep, int seg, uintptr_t addr)
return 0;
}
return addr;
}
}
7 changes: 4 additions & 3 deletions src/emu/x64syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void* my_mremap(x64emu_t* emu, void* old_addr, size_t old_size, size_t new_size,
int32_t my_epoll_ctl(x64emu_t* emu, int32_t epfd, int32_t op, int32_t fd, void* event);
int32_t my_epoll_wait(x64emu_t* emu, int32_t epfd, void* events, int32_t maxevents, int32_t timeout);
int32_t my_epoll_pwait(x64emu_t* emu, int32_t epfd, void* events, int32_t maxevents, int32_t timeout, const sigset_t *sigmask);
pid_t my_vfork(x64emu_t* emu);
#endif
pid_t my_vfork(x64emu_t* emu);
int32_t my_fcntl(x64emu_t* emu, int32_t a, int32_t b, void* c);
int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], char* const envp[]);

Expand Down Expand Up @@ -401,7 +401,7 @@ void EXPORT x64Syscall(x64emu_t *emu)
printf_log(LOG_NONE, "%s", buff);
}
// check wrapper first
int cnt = sizeof(syscallwrap) / sizeof(scwrap_t);
uint32_t cnt = sizeof(syscallwrap) / sizeof(scwrap_t);
if(s<cnt && syscallwrap[s].nats) {
int sc = syscallwrap[s].nats;
switch(syscallwrap[s].nbpars) {
Expand Down Expand Up @@ -746,6 +746,7 @@ void EXPORT x64Syscall(x64emu_t *emu)
S_RAX = eventfd(S_EDI, 0);
if(S_RAX==-1)
S_RAX = -errno;
break;
#endif
case 317: // sys_seccomp
R_RAX = 0; // ignoring call
Expand Down Expand Up @@ -791,7 +792,7 @@ long EXPORT my_syscall(x64emu_t *emu)
uint32_t s = R_EDI;
printf_dump(LOG_DEBUG, "%04d| %p: Calling libc syscall 0x%02X (%d) %p %p %p %p %p\n", GetTID(), (void*)R_RIP, s, s, (void*)R_RSI, (void*)R_RDX, (void*)R_RCX, (void*)R_R8, (void*)R_R9);
// check wrapper first
int cnt = sizeof(syscallwrap) / sizeof(scwrap_t);
uint32_t cnt = sizeof(syscallwrap) / sizeof(scwrap_t);
if(s<cnt && syscallwrap[s].nats) {
int sc = syscallwrap[s].nats;
switch(syscallwrap[s].nbpars) {
Expand Down
2 changes: 1 addition & 1 deletion src/librarian/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static const char* essential_libs[] = {
"ld-linux-x86-64.so.2", "crashhandler.so", "libtcmalloc_minimal.so.0", "libtcmalloc_minimal.so.4"
};
static int isEssentialLib(const char* name) {
for (int i=0; i<sizeof(essential_libs)/sizeof(essential_libs[0]); ++i)
for (unsigned int i=0; i<sizeof(essential_libs)/sizeof(essential_libs[0]); ++i)
if(!strcmp(name, essential_libs[i]))
return 1;
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/librarian/library_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct library_s {
kh_bridgemap_t *gbridgemap; // global symbol bridgemap
kh_bridgemap_t *wbridgemap; // weak symbol bridgemap
kh_bridgemap_t *lbridgemap; // local symbol bridgemap
int dlopen; // idx to the dlopen idx (or 0 if not dlopen)
size_t dlopen; // idx to the dlopen idx (or 0 if not dlopen)
} library_t;

// type for map elements
Expand Down Expand Up @@ -124,6 +124,6 @@ void removeLinkMapLib(library_t* lib);
int FiniLibrary(library_t* lib, x64emu_t* emu);
void Free1Library(library_t **lib, x64emu_t* emu);

void RemoveDlopen(library_t** lib, int idx); // defined in wrappedlibdl.c
void RemoveDlopen(library_t** lib, size_t idx); // defined in wrappedlibdl.c

#endif //__LIBRARY_PRIVATE_H_
4 changes: 2 additions & 2 deletions src/libtools/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -1438,13 +1438,13 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "Repeated SIGSEGV with Access error on %p for
static void* old_pc = 0;
static void* old_addr = 0;
static int old_tid = 0;
static int old_prot = 0;
static uint32_t old_prot = 0;
int tid = GetTID();
int mapped = getMmapped((uintptr_t)addr);
const char* signame = (sig==SIGSEGV)?"SIGSEGV":((sig==SIGBUS)?"SIGBUS":((sig==SIGILL)?"SIGILL":"SIGABRT"));
if(old_code==info->si_code && old_pc==pc && old_addr==addr && old_tid==tid && old_prot==prot) {
printf_log(log_minimum, "%04d|Double %s (code=%d, pc=%p, addr=%p, prot=%02x)!\n", tid, signame, old_code, old_pc, old_addr, prot);
exit(-1);
exit(-1);
} else {
if((sig==SIGSEGV) && (info->si_code == SEGV_ACCERR) && ((prot&~PROT_CUSTOM)==5 || (prot&~PROT_CUSTOM)==7)) {
static uintptr_t old_addr = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/libtools/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ EXPORT int my_pthread_attr_setstacksize(x64emu_t* emu, void* attr, size_t stacks
{
(void)emu;
//aarch64 have an PTHREAD_STACK_MIN of 131072 instead of 16384 on x86_64!
if(stacksize<PTHREAD_STACK_MIN)
if(stacksize<(size_t)PTHREAD_STACK_MIN)
stacksize = PTHREAD_STACK_MIN;
return pthread_attr_setstacksize(getAlignedAttr(attr), stacksize);
}
Expand Down
4 changes: 2 additions & 2 deletions src/mallochook.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ char* box_realpath(const char* path, char* ret)

static size_t pot(size_t l) {
size_t ret = 0;
while (l>(1<<ret)) ++ret;
return 1<<ret;
while (l>(1u<<ret)) ++ret;
return 1u<<ret;
}

static int ispot(size_t l) {
Expand Down
4 changes: 1 addition & 3 deletions src/steam.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void pressure_vessel(int argc, const char** argv, int nextarg, const char* prog)
{
// skip all the parameter, but parse some of them
const char* runtime = getenv("PRESSURE_VESSEL_RUNTIME");
int ld_lib_path = 0;
// look for the comand first
const char* cmd = argv[nextarg];
int i = 0;
Expand All @@ -33,7 +32,6 @@ void pressure_vessel(int argc, const char** argv, int nextarg, const char* prog)
strcat(tmp, argv[nextarg]+strlen("--env-if-host=PRESSURE_VESSEL_APP_"));
char *p = strchr(tmp, '=');
*p ='\0'; ++p;
ld_lib_path = 1;
setenv(tmp, p, 1);
printf_log(LOG_DEBUG, "setenv(%s, %s, 1)\n", tmp, p);
}
Expand Down Expand Up @@ -181,4 +179,4 @@ void pressure_vessel(int argc, const char** argv, int nextarg, const char* prog)
//waitpid(v, &wstatus, 0);
exit(0);
}
}
}
18 changes: 10 additions & 8 deletions src/tools/gtkclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -4543,7 +4543,7 @@ static void wrapGTKClass(void* cl, size_t type)
GTKCLASSES()
if(type==8) {} // GInterface have no structure
else {
if(my_MetaFrames2==-1 && !strcmp(g_type_name(type), "MetaFrames")) {
if(my_MetaFrames2==(size_t)-1 && !strcmp(g_type_name(type), "MetaFrames")) {
my_MetaFrames2 = type;
wrapMetaFrames2Class((my_MetaFrames2Class_t*)cl);
} else
Expand Down Expand Up @@ -4781,7 +4781,7 @@ void* wrapCopyGTKClass(void* klass, size_t type)
GTKCLASSES()
if(type==8) {} // GInterface have no structure
else {
if(my_MetaFrames2==-1 && !strcmp(g_type_name(type), "MetaFrames")) {
if(my_MetaFrames2==(size_t)-1 && !strcmp(g_type_name(type), "MetaFrames")) {
my_MetaFrames2 = type;
sz = sizeof(my_MetaFrames2Class_t);
} else {
Expand All @@ -4791,6 +4791,7 @@ void* wrapCopyGTKClass(void* klass, size_t type)
}
#undef GTKIFACE
#undef GTKCLASS
(void)sz;
bridgeGTKClass(klass, type);
return klass;
}
Expand All @@ -4811,7 +4812,7 @@ void* wrapCopyGTKInterface(void* iface, size_t type)
GTKCLASSES()
if(type==8) {} // GInterface have no structure
else {
if(my_MetaFrames2==-1 && !strcmp(g_type_name(type), "MetaFrames")) {
if(my_MetaFrames2==(size_t)-1 && !strcmp(g_type_name(type), "MetaFrames")) {
my_MetaFrames2 = type;
sz = sizeof(my_MetaFrames2Class_t);
} else {
Expand All @@ -4821,6 +4822,7 @@ void* wrapCopyGTKInterface(void* iface, size_t type)
}
#undef GTKIFACE
#undef GTKCLASS
(void)sz;
bridgeGTKInterface(iface, type);
return iface;
}
Expand Down Expand Up @@ -5455,11 +5457,11 @@ void AutoBridgeGtk(void*(*ref)(size_t), void(*unref)(void*))
{
void* p;
#define GTKIFACE(A)
#define GTKCLASS(A) \
if(my_##A && my_##A!=-1) { \
p = ref(my_##A); \
bridgeGTKClass(p, my_##A); \
unref(p); \
#define GTKCLASS(A) \
if(my_##A && my_##A!=(size_t)-1) { \
p = ref(my_##A); \
bridgeGTKClass(p, my_##A); \
unref(p); \
}
GTKCLASSES()
#undef GTKIFACE
Expand Down
4 changes: 2 additions & 2 deletions src/tools/my_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ static double bogoMips = 100.;
void grabNCpu() {
nCPU = 1; // default number of CPU to 1
FILE *f = fopen("/proc/cpuinfo", "r");
size_t dummy;
ssize_t dummy;
if(f) {
nCPU = 0;
int bogo = 0;
size_t len = 500;
char* line = malloc(len);
while ((dummy = getline(&line, &len, f)) != -1) {
while ((dummy = getline(&line, &len, f)) != (ssize_t)-1) {
if(!strncmp(line, "processor\t", strlen("processor\t")))
++nCPU;
if(!bogo && !strncmp(line, "BogoMIPS\t", strlen("BogoMIPS\t"))) {
Expand Down
5 changes: 2 additions & 3 deletions src/wrapped/wrappedgobject2.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,12 @@ EXPORT void my_g_closure_set_marshal(x64emu_t* emu, void* closure, void* marshal

EXPORT void* my_g_cclosure_new(x64emu_t* emu, void* callback, void* data, void* destroy)
{
my->g_cclosure_new(findGCallbackFct(callback), data, findGClosureNotify_Fct(destroy));
return my->g_cclosure_new(findGCallbackFct(callback), data, findGClosureNotify_Fct(destroy));
}

EXPORT void* my_g_cclosure_new_swap(x64emu_t* emu, void* callback, void* data, void* destroy)
{
my->g_cclosure_new_swap(findGCallbackFct(callback), data, findGClosureNotify_Fct(destroy));
return my->g_cclosure_new_swap(findGCallbackFct(callback), data, findGClosureNotify_Fct(destroy));
}

EXPORT void my_g_closure_add_finalize_notifier(x64emu_t* emu, void* closure, void* data, void* f)
Expand Down Expand Up @@ -939,4 +939,3 @@ EXPORT void* my_g_type_value_table_peek(x64emu_t* emu, size_t type)
freeMy();

#include "wrappedlib_init.h"

4 changes: 2 additions & 2 deletions src/wrapped/wrappedgstreamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,15 +908,15 @@ EXPORT void* my_gst_structure_new_valist(x64emu_t* emu, void* name, void* first,
#else
CREATE_VALIST_FROM_VALIST(V, emu->scratch);
#endif
my->gst_structure_new_valist(name, first, VARARGS);
return my->gst_structure_new_valist(name, first, VARARGS);
}

EXPORT void* my_gst_make_element_message_details(x64emu_t* emu, void* name, uintptr_t* b)
{
if(!name)
return NULL;
CREATE_VALIST_FROM_VAARG(b, emu->scratch, 1);
my->gst_structure_new_valist("detail", name, VARARGS);
return my->gst_structure_new_valist("detail", name, VARARGS);
}

EXPORT int my_gst_pad_start_task(x64emu_t* emu, void* pad, void* f, void* data, void* d)
Expand Down
2 changes: 1 addition & 1 deletion src/wrapped/wrappedgtk3.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ EXPORT void my3_gtk_tree_view_column_set_cell_data_func(x64emu_t* emu, void* tre
EXPORT void* my3_gtk_tree_store_new(x64emu_t* emu, uint32_t n, uintptr_t* b)
{
uintptr_t c[n];
for(int i=0; i<n; ++i)
for(uint32_t i=0; i<n; ++i)
c[i] = getVArgs(emu, 1, b, i);
return my->gtk_tree_store_newv(n, c);
}
Expand Down
Loading

0 comments on commit 3a2073f

Please sign in to comment.