From owner-freebsd-questions Sat Jun 23 13:17:41 2001 Delivered-To: freebsd-questions@freebsd.org Received: from bingnet2.cc.binghamton.edu (bingnet2.cc.binghamton.edu [128.226.1.18]) by hub.freebsd.org (Postfix) with ESMTP id A675737B405 for ; Sat, 23 Jun 2001 13:17:38 -0700 (PDT) (envelope-from zzhang@cs.binghamton.edu) Received: from opal (cs.binghamton.edu [128.226.123.101]) by bingnet2.cc.binghamton.edu (8.11.4/8.11.4) with ESMTP id f5NKHbL27828 for ; Sat, 23 Jun 2001 16:17:37 -0400 (EDT) Date: Sat, 23 Jun 2001 16:17:36 -0400 (EDT) From: Zhihui Zhang X-Sender: zzhang@opal To: freebsd-questions@freebsd.org Subject: sbrk() and segment fault Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Out of curiosity, I tried the following program on FreeBSD 4.3-Release: #include #include main() { char * ret, * endpt; endpt = sbrk(0); printf("endpt = %x after sbrk\n", (int)endpt); #if 1 ret = brk(endpt); if (ret == (char *) -1) { printf("brk of %x failed\n", endpt); exit(0); } #endif printf("brk of %x succeed\n", (int)endpt); } dell# cc sbrk2.c; a.out endpt = 8049708 after sbrk Segmentation fault (core dumped) If I change #if 1 to #if 0, then it runs OK. So why brk() to the SAME address can cause problem? Is it some roundup done in obreak() in vm_unix.c? Or maybe my understanding of break is not complete. Thanks for any help. -Zhihui To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message