]> git.proxmox.com Git - wasi-libc.git/commitdiff
Reduce over-allocation of stack (#365)
authorYAMAMOTO Takashi <yamamoto@midokura.com>
Mon, 19 Dec 2022 12:16:54 +0000 (21:16 +0900)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 2 Aug 2023 10:24:08 +0000 (12:24 +0200)
* Disable stack guard
* Stop rounding up stack size to PAGE_SIZE

libc-top-half/musl/src/internal/pthread_impl.h
libc-top-half/musl/src/thread/pthread_create.c

index a6d188bb3cfbbdcc1f91dba26edd6cb44dbb3ad9..1e7b9741dba75b158f702080c94a3cf9d87d0c0d 100644 (file)
@@ -216,7 +216,12 @@ extern hidden unsigned __default_stacksize;
 extern hidden unsigned __default_guardsize;
 
 #define DEFAULT_STACK_SIZE 131072
+#ifdef __wasilibc_unmodified_upstream
 #define DEFAULT_GUARD_SIZE 8192
+#else
+/* guard doesn't make much sense without mprotect. */
+#define DEFAULT_GUARD_SIZE 0
+#endif
 
 #define DEFAULT_STACK_MAX (8<<20)
 #define DEFAULT_GUARD_MAX (1<<20)
index 3b3a2642e14d44c297365e536f4f3b97af128fad..1ac920f13c8ddc998551eeb7daf4e36b005269be 100644 (file)
@@ -295,7 +295,17 @@ _Noreturn void wasi_thread_start(int tid, void *p)
 }
 #endif
 
+#ifdef __wasilibc_unmodified_upstream
 #define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE)
+#else
+/*
+ * As we allocate stack with malloc() instead of mmap/mprotect,
+ * there is no point to round it up to PAGE_SIZE.
+ * Instead, round up to a sane alignment.
+ * Note: PAGE_SIZE is rather big on WASM. (65536)
+ */
+#define ROUND(x) (((x)+16-1)&-16)
+#endif
 
 /* pthread_key_create.c overrides this */
 static volatile size_t dummy = 0;