Skip to content

Commit

Permalink
Added BOX86_MUTEX_ALIGNED to use pthread_mutext_t as-is
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Oct 15, 2023
1 parent 4b1b214 commit f716212
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ Need a workaround for SDL_GetJoystickGUIDInfo function for wrapped SDL2
* 0 : Don't use any workaround
* 1 : Use a workaround for program that use the private SDL_GetJoystickGUIDInfo function with 1 missing argument

#### BOX86_MUTEX_ALIGNED *
Will mutex are used as-is or wrapped to handle unaligned used
* 0 : Mutex will be wrapped in case unaligned mutexes are used (Default)
* 1 : Do no wrap mutex and use them as-is (faster, but might crash with SEGBUS error)

#### BOX86_LIBGL *
* libXXXX set the name for libGL (defaults to libGL.so.1).
* /PATH/TO/libGLXXX : Sets the name and path for libGL
Expand Down
1 change: 1 addition & 0 deletions src/include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern int box86_nogtk; // disabling the use of wrapped gtk
extern int box86_novulkan; // disabling the use of wrapped vulkan
extern int box86_mapclean;
extern int box86_showsegv;
extern int box86_mutex_aligned;
extern int allow_missing_symbols;
extern uintptr_t trace_start, trace_end;
extern char* trace_func;
Expand Down
16 changes: 9 additions & 7 deletions src/libtools/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,10 @@ static pthread_cond_t* get_cond(void* cond)
ret = (pthread_cond_t*)box_calloc(1, sizeof(pthread_cond_t));
k = kh_put(mapcond, mapcond, (uintptr_t)cond, &r);
kh_value(mapcond, k) = ret;
*(void**)cond = cond;
pthread_cond_init(ret, NULL);
} else
ret = kh_value(mapcond, k);
*(void**)cond = cond;
pthread_cond_init(ret, NULL);
} else
ret = kh_value(mapcond, k);
mutex_unlock(&my_context->mutex_thread);
Expand All @@ -549,7 +549,7 @@ static void del_cond(void* cond)
}
mutex_unlock(&my_context->mutex_thread);
}
pthread_mutex_t* getAlignedMutex(pthread_mutex_t* m);
static pthread_mutex_t* getAlignedMutex(pthread_mutex_t* m);

EXPORT int my_pthread_cond_broadcast_old(x86emu_t* emu, void* cond)
{
Expand Down Expand Up @@ -858,8 +858,10 @@ typedef struct aligned_mutex_s {
} aligned_mutex_t;
#define SIGNMTX *(uint32_t*)"MUTX"

pthread_mutex_t* getAlignedMutexWithInit(pthread_mutex_t* m, int init)
static pthread_mutex_t* getAlignedMutexWithInit(pthread_mutex_t* m, int init)
{
if(box86_mutex_aligned)
return m;
if(!m)
return NULL;
aligned_mutex_t* am = (aligned_mutex_t*)m;
Expand Down Expand Up @@ -891,15 +893,15 @@ pthread_mutex_t* getAlignedMutexWithInit(pthread_mutex_t* m, int init)
am->m = ret;
return ret;
}
pthread_mutex_t* getAlignedMutex(pthread_mutex_t* m)
static pthread_mutex_t* getAlignedMutex(pthread_mutex_t* m)
{
return getAlignedMutexWithInit(m, 1);
}

EXPORT int my_pthread_mutex_destroy(pthread_mutex_t *m)
{
/*if(!(((uintptr_t)m)&3))
return pthread_mutex_destroy(m);*/ // alignent to check...
if(box86_mutex_aligned)
return pthread_mutex_destroy(m);
aligned_mutex_t* am = (aligned_mutex_t*)m;
if(am->sign!=SIGNMTX) {
return 1; //???
Expand Down
14 changes: 14 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int box86_showbt = 0;
int box86_isglibc234 = 0;
int box86_nosandbox = 0;
int box86_malloc_hack = 0;
int box86_mutex_aligned = 0;
int box86_quit = 0;
#ifdef DYNAREC
int box86_dynarec = 1;
Expand Down Expand Up @@ -639,6 +640,19 @@ void LoadLogEnv()
printf_log(LOG_INFO, "Malloc hook will check for mmap/free occurrences\n");
}
}
p = getenv("BOX86_MUTEX_ALIGNED");
if(p) {
if(strlen(p)==1) {
if(p[0]>='0' && p[0]<='0'+1)
box86_mutex_aligned = p[0]-'0';
}
if(!box86_mutex_aligned) {
if(box86_mutex_aligned==1) {
printf_log(LOG_INFO, "BOX86 will not aligned mutexes\n");
} else
printf_log(LOG_INFO, "BOX86 will wrap mutex to for them aligned\n");
}
}
p = getenv("BOX86_NOPULSE");
if(p) {
if(strlen(p)==1) {
Expand Down
1 change: 1 addition & 0 deletions src/tools/rcfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ENTRYSTRING_(BOX86_LD_PRELOAD, ld_preload) \
ENTRYBOOL(BOX86_NOSANDBOX, box86_nosandbox) \
ENTRYBOOL(BOX86_LIBCEF, box86_libcef) \
ENTRYBOOL(BOX86_SDL2_JGUID, box86_sdl2_jguid) \
ENTRYBOOL(BOX86_MUTEX_ALIGNED, box86_mutex_aligned) \
ENTRYINT(BOX86_MALLOC_HACK, box86_malloc_hack, 0, 2, 2) \

#ifdef HAVE_TRACE
Expand Down

0 comments on commit f716212

Please sign in to comment.