Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getcontext() -> Bus error?




On Jan 31, 2008, at 7:42 PM, Anton Rang wrote:

On Jan 31, 2008, at 6:52 PM, Edd Dawson wrote:
int main(void)
{
ucontext_t ctx;
getcontext(&ctx);
return 0;
}
edd:guff developer$ gcc getcontext.c -o getcontext -W -Wall -ansi - pedantic
edd:guff developer$ ./getcontext
Bus error
edd:guff developer$


Why the bus error? What am I doing wrong?

This is a known issue where getcontext(3) is writing past the end of the ucontext_t struct when _XOPEN_SOURCE is not defined (rdar://problem/5578699 ). As a workaround, define _XOPEN_SOURCE before including ucontext.h.


While I don't understand why you're getting a bus error (haven't looked at the library source), the problem appears to go away if you declare ctx as a global instead of on the stack. Perhaps getcontext() just won't let you save context onto the stack....

The buffer overflow that wipes out the return address, causing the bus error. By using a global, the memory corruption still occurs, but doesn't manifest itself as a bus error with main() returning so quickly.


- Kevin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >getcontext() -> Bus error? (From: Edd Dawson <email@hidden>)
 >Re: getcontext() -> Bus error? (From: Anton Rang <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.