about summary refs log tree commit diff stats
path: root/src/libtools/threads.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-01-10 12:10:20 +0100
committerptitSeb <sebastien.chev@gmail.com>2025-01-10 12:10:20 +0100
commit1e681cead008f5d423e819db7b935c7a131ab170 (patch)
tree6a16a854c3e32b874904c909bc25e5a14e02541e /src/libtools/threads.c
parent53f2423578ffd8b21e59f034c161721e24ba83d4 (diff)
downloadbox64-1e681cead008f5d423e819db7b935c7a131ab170.tar.gz
box64-1e681cead008f5d423e819db7b935c7a131ab170.zip
Creating an emu structure for a thread will use a minimal stack now ([BOX32] too, also using MAP_32BIT attribute)
Diffstat (limited to 'src/libtools/threads.c')
-rw-r--r--src/libtools/threads.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/libtools/threads.c b/src/libtools/threads.c
index e14f71db..a630a7c0 100644
--- a/src/libtools/threads.c
+++ b/src/libtools/threads.c
@@ -198,18 +198,13 @@ x64emu_t* thread_get_emu()
 {
 	emuthread_t *et = (emuthread_t*)pthread_getspecific(thread_key);
 	if(!et) {
-		int stacksize = 2*1024*1024;
-		// try to get stack size of the thread
-		pthread_attr_t attr;
-		if(!pthread_getattr_np(pthread_self(), &attr)) {
-			size_t stack_size;
-        	void *stack_addr;
-			if(!pthread_attr_getstack(&attr, &stack_addr, &stack_size))
-				if(stack_size)
-					stacksize = stack_size;
-			pthread_attr_destroy(&attr);
-		}
-		void* stack = internal_mmap(NULL, stacksize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_GROWSDOWN, -1, 0);
+		// this should not happens. So if it happens, use a small stack
+		int stacksize = 256*1024;
+		void* stack = NULL;
+		if(box64_is32bits)
+			stack = mmap64(NULL, stacksize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_32BIT, -1, 0);
+		else
+			stack = internal_mmap(NULL, stacksize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_GROWSDOWN, -1, 0);
 		if(stack!=MAP_FAILED)
 			setProtection((uintptr_t)stack, stacksize, PROT_READ|PROT_WRITE);
 		x64emu_t *emu = NewX64Emu(my_context, 0, (uintptr_t)stack, stacksize, 1);