Re: getcontext() -> Bus error?
Re: getcontext() -> Bus error?
- Subject: Re: getcontext() -> Bus error?
- From: Edd Dawson <email@hidden>
- Date: Mon, 04 Feb 2008 00:43:22 +0000
Kevin Van Vechten 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.
That seems to have stopped the bus error -- thanks! -- but now I'm getting what
I believe is fishy behaviour from swapcontext(). The following program prints
"about to swapcontext()..." indefinitely.
#define _XOPEN_SOURCE
#include <ucontext.h>
#include <stdio.h>
#include <stdlib.h>
void die(const char *msg)
{
perror(msg);
exit(666);
}
void f()
{
puts("in f()!");
}
int main()
{
char stack[4096];
ucontext_t ctx;
ucontext_t ctx2;
if (getcontext(&ctx) == -1)
die("getcontext failed\n");
if (getcontext(&ctx2) == -1)
die("getcontext failed\n");
ctx2.uc_stack.ss_sp = stack;
ctx2.uc_stack.ss_size = sizeof stack;
ctx2.uc_link = 0;
makecontext(&ctx2, &f, 0);
puts("about to swapcontext()...");
if (swapcontext(&ctx, &ctx2) == -1)
die("swapcontext failed\n");
return 0;
}
Again, this behaves as expected on my Linux machine.
I don't suppose there's a way for "regular people" to see rdar data?
Kind regards,
Edd
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden