Date: Fri, 30 Mar 2001 04:52:27 -0800 (PST) From: sonnet@teatime.org To: freebsd-gnats-submit@FreeBSD.org Subject: i386/26216: alloca() couldn't detect thread stack limit Message-ID: <200103301252.f2UCqR831862@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 26216 >Category: i386 >Synopsis: alloca() couldn't detect thread stack limit >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Mar 30 05:00:01 PST 2001 >Closed-Date: >Last-Modified: >Originator: Soonmyung Hong >Release: 3-Stable/4-Stable >Organization: Innovay Inc >Environment: FreeBSD alfheim.innovay.com 3.5-STABLE FreeBSD 3.5-STABLE #3: Wed Jul 26 19:37:39 KST 2000 root@alfheim.innovay.com:/usr/src/sys/compile/ALFHEIM i386 FreeBSD hel.innovay.com 4.2-STABLE FreeBSD 4.2-STABLE #2: Wed Feb 28 17:22:54 KST 2001 root@hel.innovay.com:/usr/src/sys/compile/HEL i386 >Description: On pthread environment, each thread has their own stack limit. when user requested larger than current thread's stack size to alloca(), alloca() return invalid pointer. It must be NULL pointer. >How-To-Repeat: gcc -ansi -pedantic -g -Wall -pthread -o test test.c ./test ./test <stacksize> -- /* test.c */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <pthread.h> /* the stderr time ticker thread */ static void *ticker(void *_arg) { int kb = (int)_arg; char *ptr; if (NULL != (ptr = alloca(kb * 1024))) { printf("alloca(%dKB) return %p\n", kb, ptr); memset(ptr, 0xdf, kb * 1024); } else { printf("alloca(%dKB) return NULL\n", kb); } return NULL; } int main(int argc, char *argv[]) { pthread_attr_t thread_attr; pthread_t ticker_thread; size_t stacksize; int i; signal(SIGPIPE, SIG_IGN); pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); if (2 == argc) { stacksize = (size_t) strtoul(argv[1], (char **)NULL, 10); if (!pthread_attr_setstacksize(&thread_attr, stacksize*1024)) { printf("set stacksize = %dKB\n", stacksize); } } if (!pthread_attr_getstacksize(&thread_attr, &stacksize)) { printf("stack size = %dKB\n", stacksize/1024); } for (i = 4; i < 65536 ; i += 8) { pthread_create(&ticker_thread, &thread_attr, ticker, (void *)i); sleep(1); } return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103301252.f2UCqR831862>