From owner-freebsd-questions Sat Jan 2 15:16:34 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA13485 for freebsd-questions-outgoing; Sat, 2 Jan 1999 15:16:34 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from genius.cirx.org (r00t.m1.ntu.edu.tw [140.112.240.59]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA13472 for ; Sat, 2 Jan 1999 15:16:27 -0800 (PST) (envelope-from clkao@CirX.ORG) Received: (from clkao@localhost) by genius.cirx.org (8.9.1/8.9.1) id HAA00880; Sun, 3 Jan 1999 07:15:52 +0800 (CST) (envelope-from clkao@CirX.ORG) Date: Sun, 3 Jan 1999 07:15:52 +0800 (CST) Message-Id: <199901022315.HAA00880@genius.cirx.org> X-Authentication-Warning: genius.cirx.org: clkao set sender to clkao@CirX.ORG using -f From: Chia-liang Kao To: freebsd-questions@FreeBSD.ORG Subject: setjmp/longjmp corrupts stack? Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, I have a little program attached below causing SIGSEGV. But the program works out dramatically if the function being called in main() (haha()) changes to hehe(). In my track record, the stack corrupted right after longjmp to j2. But if I change the haha() in main() to hehe(), although the result is as expected, the stack is somewhat corrupted too. Like the following: (gdb) bt #0 haha () at testjmp.c:18 #1 0x804852d in main () at testjmp.c:35 #2 0xefbfd704 in ?? () #3 0x6b6c633d in ?? () Error accessing memory address 0x52455355: Bad address. The situation is met also when calling longjmp to j2, too. My box is 3.0-CURRENT FreeBSD 3.0-CURRENT #2: Sat Jan 2 05:26:13 CST 1999. The result tested on Linux 2.0.34 is the same; while it works as expected(well, it's just my expectation, perhaps the POSIX definition is not as what I thought. But I can't find any other useful info on man pages either) on Solaris 2.6. Regards, CLK ====================== #include #include jmp_buf j1, j2; void haha() { int r; static int cnt; /* ... */ printf("send\n"); if(!(r =setjmp(j2))) { /* go back */ longjmp(j1, ++cnt); } /* resume */ printf("resume\n"); return; } void hehe() { haha(); } int main() { int r; if((r = setjmp(j1))) { printf("jmp %d\n", r); if(r == 1) longjmp(j2, 1); else exit(0); } printf("main\n"); haha(); printf("after longjmp\n"); return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message