From 6ed4c9c908a0394d7de2c73dc5efa9343a967fdb Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Mon, 3 Jul 2023 14:02:10 +0100 Subject: [PATCH] Increase default native stack size (#2332) Calling `__wasi_sock_addr_resolve` syscall causes native stack overflow. Given this is a standard function available in WAMR, we should have at least the default stack size large enough to handle this case. The socket tests were updated so they also run in separate thread, but the simple retro program is: ```C void *th(void *p) { struct addrinfo *res; getaddrinfo("amazon.com", NULL, NULL, &res); return NULL; } int main(int argc, char **argv) { pthread_t pt; pthread_create(&pt, NULL, th, NULL); pthread_join(pt, NULL); return 0; } ``` --- core/config.h | 2 +- .../libraries/lib-socket/test/nslookup.c | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/config.h b/core/config.h index 2c382d17..0d99d580 100644 --- a/core/config.h +++ b/core/config.h @@ -384,7 +384,7 @@ #define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024) #define APP_THREAD_STACK_SIZE_MIN (48 * 1024) #else -#define APP_THREAD_STACK_SIZE_DEFAULT (32 * 1024) +#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024) #define APP_THREAD_STACK_SIZE_MIN (24 * 1024) #endif #endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \ diff --git a/core/iwasm/libraries/lib-socket/test/nslookup.c b/core/iwasm/libraries/lib-socket/test/nslookup.c index 37150f1e..543a3fb2 100644 --- a/core/iwasm/libraries/lib-socket/test/nslookup.c +++ b/core/iwasm/libraries/lib-socket/test/nslookup.c @@ -5,6 +5,8 @@ #include #include +#include +#include #ifdef __wasi__ #include #include @@ -39,11 +41,27 @@ test_nslookup(int af) freeaddrinfo(res); } +void * +test_nslookup_mt(void *params) +{ + int *af = (int *)params; + test_nslookup(*af); +} + int main() { - test_nslookup(AF_INET); /* for ipv4 */ - test_nslookup(AF_INET6); /* for ipv6 */ + int afs[] = { AF_INET, AF_INET6 }; + + for (int i = 0; i < sizeof(afs) / sizeof(afs[0]); i++) { + pthread_t th; + + printf("Testing %d in main thread...\n", afs[i]); + test_nslookup(afs[i]); + printf("Testing %d in a new thread...\n", afs[i]); + pthread_create(&th, NULL, test_nslookup_mt, &afs[i]); + pthread_join(th, NULL); + } return 0; }