about summary refs log tree commit diff stats
path: root/src/libtools
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-10-07 17:17:55 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-10-07 17:17:55 +0200
commitf073415510929646b7e2d5e254c4932b46b40233 (patch)
tree4adb71907705a9b6335de19ae05e1e177c31e6ca /src/libtools
parent4c69bcd97aff691b464f01ebed057cfcb912612b (diff)
downloadbox64-f073415510929646b7e2d5e254c4932b46b40233.tar.gz
box64-f073415510929646b7e2d5e254c4932b46b40233.zip
[BOX32] More work on 32bits wrapped functions
Diffstat (limited to 'src/libtools')
-rw-r--r--src/libtools/my_x11_defs.h7
-rw-r--r--src/libtools/my_x11_defs_32.h7
-rwxr-xr-xsrc/libtools/myalign32.c16
-rw-r--r--src/libtools/threads.c2
-rwxr-xr-xsrc/libtools/threads32.c22
5 files changed, 42 insertions, 12 deletions
diff --git a/src/libtools/my_x11_defs.h b/src/libtools/my_x11_defs.h
index 2e8ede07..483046f0 100644
--- a/src/libtools/my_x11_defs.h
+++ b/src/libtools/my_x11_defs.h
@@ -954,4 +954,11 @@ typedef struct my_XDevice_s {
      my_XInputClassInfo_t*  classes;
 } my_XDevice_t;
 
+typedef struct my_XcursorCursors_s {
+    void*      dpy;     //Display*
+    int        ref;
+    int        ncursor;
+    void*      cursors; //Cursor*
+} my_XcursorCursors_t;
+
 #endif//MY_X11_DEFS
\ No newline at end of file
diff --git a/src/libtools/my_x11_defs_32.h b/src/libtools/my_x11_defs_32.h
index 322ebd2d..2fed047a 100644
--- a/src/libtools/my_x11_defs_32.h
+++ b/src/libtools/my_x11_defs_32.h
@@ -887,4 +887,11 @@ typedef struct __attribute__((packed, aligned(4))) my_XDevice_32_s {
      ptr_t  classes;    //my_XInputClassInfo_t*
 } my_XDevice_32_t;
 
+typedef struct __attribute__((packed, aligned(4))) my_XcursorCursors_32_s {
+    ptr_t      dpy;     //Display*
+    int        ref;
+    int        ncursor;
+    ptr_t      cursors; //Cursor*
+} my_XcursorCursors_32_t;
+
 #endif//MY_X11_DEFS_32
\ No newline at end of file
diff --git a/src/libtools/myalign32.c b/src/libtools/myalign32.c
index 63ae2951..e14912a0 100755
--- a/src/libtools/myalign32.c
+++ b/src/libtools/myalign32.c
@@ -201,6 +201,7 @@ size_t myStackAlignScanf32(const char* fmt, uint32_t* st, uint64_t* mystack, siz
                     case '#':
                     case '+': 
                     case '-': ++p; break; // formating, ignored
+                    case '[': state += 60; ++p; break;
                     case 'm': state = 0; ++p; break; // no argument
                     case 'n':
                     case 'p': state = 30; break; // pointers
@@ -251,6 +252,13 @@ size_t myStackAlignScanf32(const char* fmt, uint32_t* st, uint64_t* mystack, siz
                 state = 0;
                 ++p;
                 break;
+            case 61:
+                switch(*p) {
+                    case ']': state = 50; break;
+                    case '\\': ++p; if(*p) ++p; break;
+                    default: ++p; break;
+                }
+                break;
             default:
                 // whaaaat?
                 state = 0;
@@ -321,6 +329,7 @@ void myStackAlignScanf32_final(const char* fmt, uint32_t* st, uint64_t* mystack,
                     case '#':
                     case '+': 
                     case '-': ++p; break; // formating, ignored
+                    case '[': state += 60; ++p; break;
                     case 'm': state = 0; ++p; break; // no argument
                     case 'n':
                     case 'p': state = 30; break; // pointers
@@ -381,6 +390,13 @@ void myStackAlignScanf32_final(const char* fmt, uint32_t* st, uint64_t* mystack,
                 ++p;
                 if(!--n) return;
                 break;
+            case 61:
+                switch(*p) {
+                    case ']': state = 50; break;
+                    case '\\': ++p; if(*p) ++p; break;
+                    default: ++p; break;
+                }
+                break;
             default:
                 // whaaaat?
                 state = 0;
diff --git a/src/libtools/threads.c b/src/libtools/threads.c
index 6ca80bba..e19b3fda 100644
--- a/src/libtools/threads.c
+++ b/src/libtools/threads.c
@@ -166,7 +166,7 @@ void thread_set_emu(x64emu_t* emu)
 {
 	emuthread_t *et = (emuthread_t*)pthread_getspecific(thread_key);
 	if(!emu) {
-		if(et) box_free(et);
+		if(et) emuthread_destroy(et);
 		pthread_setspecific(thread_key, NULL);
 		return;
 	}
diff --git a/src/libtools/threads32.c b/src/libtools/threads32.c
index ae2a48c7..adbfd894 100755
--- a/src/libtools/threads32.c
+++ b/src/libtools/threads32.c
@@ -111,7 +111,7 @@ static void emuthread_cancel(void* p)
 		my32_longjmp(et->emu, ((i386_unwind_buff_t*)et->cancels[i])->__cancel_jmp_buf, 1);
 		DynaRun(et->emu);	// will return after a __pthread_unwind_next()
 	}
-	free(et->cancels);
+	box_free(et->cancels);
 	et->cancels=NULL;
 	et->cancel_size = et->cancel_cap = 0;
 }
@@ -246,7 +246,7 @@ void* my32_prepare_thread(x64emu_t *emu, void* f, void* arg, int ssize, void** p
 	int stacksize = (ssize)?ssize:(2*1024*1024);	//default stack size is 2Mo
 	//void* stack = malloc(stacksize);
 	void* stack = mmap64(NULL, stacksize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_GROWSDOWN|MAP_32BIT, -1, 0);
-	emuthread_t *et = (emuthread_t*)calloc(1, sizeof(emuthread_t));
+	emuthread_t *et = (emuthread_t*)box_calloc(1, sizeof(emuthread_t));
     x64emu_t *emuthread = NewX64Emu(emu->context, (uintptr_t)f, (uintptr_t)stack, stacksize, 1);
 	SetupX64Emu(emuthread, emu);
 	et->emu = emuthread;
@@ -271,7 +271,7 @@ EXPORT void my32___pthread_register_cancel(x64emu_t* emu, i386_unwind_buff_t* bu
 	emuthread_t *et = (emuthread_t*)thread_get_et();
 	if(et->cancel_cap == et->cancel_size) {
 		et->cancel_cap+=8;
-		et->cancels = realloc(et->cancels, sizeof(i386_unwind_buff_t*)*et->cancel_cap);
+		et->cancels = box_realloc(et->cancels, sizeof(i386_unwind_buff_t*)*et->cancel_cap);
 	}
 	et->cancels[et->cancel_size++] = buff;
 }
@@ -456,7 +456,7 @@ static pthread_cond_t* add_cond(void* cond)
 	if(!ret)
 		c = kh_value(mapcond, k);	// already there... reinit an existing one?
 	else 
-		c = kh_value(mapcond, k) = (pthread_cond_t*)calloc(1, sizeof(pthread_cond_t));
+		c = kh_value(mapcond, k) = (pthread_cond_t*)box_calloc(1, sizeof(pthread_cond_t));
 	//*(ptr_t*)cond = to_ptrv(cond);
 	mutex_unlock(&my_context->mutex_thread);
 	return c;
@@ -471,7 +471,7 @@ static pthread_cond_t* get_cond(void* cond)
 		khint_t k = kh_get(mapcond, mapcond, (uintptr_t)cond);
 		if(k==kh_end(mapcond)) {
 			printf_log(LOG_DEBUG, "BOX32: Note: phtread_cond not found, create a new empty one\n");
-			ret = (pthread_cond_t*)calloc(1, sizeof(pthread_cond_t));
+			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;
 			//*(ptr_t*)cond = to_ptrv(cond);
@@ -490,7 +490,7 @@ static void del_cond(void* cond)
 	mutex_lock(&my_context->mutex_thread);
 	khint_t k = kh_get(mapcond, mapcond, *(uintptr_t*)cond);
 	if(k!=kh_end(mapcond)) {
-		free(kh_value(mapcond, k));
+		box_free(kh_value(mapcond, k));
 		kh_del(mapcond, mapcond, k);
 	}
 	mutex_unlock(&my_context->mutex_thread);
@@ -715,7 +715,7 @@ EXPORT int my32_pthread_attr_setstackaddr(x64emu_t* emu, void* attr, void* p)
 EXPORT int my32_pthread_attr_setstacksize(x64emu_t* emu, void* attr, size_t p)
 {
 	// PTHREAD_STACK_MIN on x86 might be lower than the current platform...
-	if(p>=65536 && p<PTHREAD_STACK_MIN && !(p&4095))
+	if(p>=0xc000 && p<PTHREAD_STACK_MIN && !(p&4095))
 		p = PTHREAD_STACK_MIN;
 	return pthread_attr_setstacksize(get_attr(attr), p);
 }
@@ -832,7 +832,7 @@ pthread_mutex_t* getAlignedMutex(pthread_mutex_t* m)
 		pthread_rwlock_unlock(&m_lock);
 		pthread_rwlock_wrlock(&m_lock);
 		k = kh_put(mutex, unaligned_mutex, (uintptr_t)m, &r);
-		ret = kh_value(unaligned_mutex, k) = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t));
+		ret = kh_value(unaligned_mutex, k) = (pthread_mutex_t*)box_calloc(1, sizeof(pthread_mutex_t));
 		memcpy(ret, m, 24);
 	}
 	pthread_rwlock_unlock(&m_lock);
@@ -847,7 +847,7 @@ EXPORT int my32_pthread_mutex_destroy(pthread_mutex_t *m)
 		kh_del(mutex, unaligned_mutex, k);
 		pthread_rwlock_unlock(&m_lock);
 		int ret = pthread_mutex_destroy(n);
-		free(n);
+		box_free(n);
 		return ret;
 	}
 	pthread_rwlock_unlock(&m_lock);
@@ -939,14 +939,14 @@ void fini_pthread_helper_32(box64context_t* context)
 	pthread_cond_t *cond;
 	kh_foreach_value(mapcond, cond, 
 		pthread_cond_destroy(cond);
-		free(cond);
+		box_free(cond);
 	);
 	kh_destroy(mapcond, mapcond);
 	mapcond = NULL;
 	pthread_mutex_t *m;
 	kh_foreach_value(unaligned_mutex, m, 
 		pthread_mutex_destroy(m);
-		free(m);
+		box_free(m);
 	);
 	kh_destroy(mutex, unaligned_mutex);