From owner-freebsd-bugs Fri Mar 30 5: 0: 9 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id D897037B71A for ; Fri, 30 Mar 2001 05:00:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f2UD01K32936; Fri, 30 Mar 2001 05:00:01 -0800 (PST) (envelope-from gnats) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 098E337B71D for ; Fri, 30 Mar 2001 04:52:27 -0800 (PST) (envelope-from nobody@FreeBSD.org) Received: (from nobody@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f2UCqR831862; Fri, 30 Mar 2001 04:52:27 -0800 (PST) (envelope-from nobody) Message-Id: <200103301252.f2UCqR831862@freefall.freebsd.org> Date: Fri, 30 Mar 2001 04:52:27 -0800 (PST) From: sonnet@teatime.org To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: i386/26216: alloca() couldn't detect thread stack limit Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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 -- /* test.c */ #include #include #include #include #include #include /* 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