• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: getcontext() -> Bus error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getcontext() -> Bus error?


  • Subject: Re: getcontext() -> Bus error?
  • From: Edd Dawson <email@hidden>
  • Date: Mon, 11 Feb 2008 19:10:56 +0000

Edd Dawson wrote:
Kevin Van Vechten wrote:

On Feb 3, 2008, at 4:43 PM, Edd Dawson wrote:
I hope this is my final question on the matter. The following code is failing on Leopard. The assert() in main() is triggered. The vector's size appears to be 3?!

#define _XOPEN_SOURCE
#include <ucontext.h>
#include <signal.h>

#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <vector>

struct context
{
    context(ucontext_t ctx, void (*func)()) :
        ctx_(ctx), func_(func), stack_(MINSIGSTKSZ)
    {
        ctx_.uc_stack.ss_sp = &stack_.front();
        ctx_.uc_stack.ss_size = stack_.size();
        ctx_.uc_link = 0;
        makecontext(&ctx_, func_, 0);
    }

    context(ucontext_t ctx) :
        ctx_(ctx), func_(0), stack_()
    {
    }

    static void change(context &from, context &to)
    {
        swapcontext(&from.ctx_, &to.ctx_);
    }

    ucontext_t ctx_;
    void (*func_)();
    std::vector<char> stack_;
};

std::vector<context *> all;

void die(const char *msg)
{
    perror(msg);
    exit(666);
}

void hello()
{
    puts("hello");
    assert(all.size() == 2);
    context::change(*all[1], *all[0]);
}

int main()
{
    ucontext_t ctx;
    if (getcontext(&ctx) == -1) die("getcontext failed");

    all.push_back(new context(ctx));

    if (getcontext(&ctx) == -1) die("getcontext failed");
    all.push_back(new context(ctx, &hello));

    assert(all.size() == 2);
    context::change(*all[0], *all[1]);

    return 0;
}

This all works fine when I move getcontext() in to the same function as the associated makecontext(), which makes sense from a certain point of view.


I can work with this, so problem solved as far as I'm concerned.

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


  • Follow-Ups:
    • Re: getcontext() -> Bus error?
      • From: Terry Lambert <email@hidden>
References: 
 >Re: getcontext() -> Bus error? (From: Edd Dawson <email@hidden>)
 >Re: getcontext() -> Bus error? (From: Kevin Van Vechten <email@hidden>)
 >Re: getcontext() -> Bus error? (From: Edd Dawson <email@hidden>)

  • Prev by Date: Re: FSEventStream with more than one Path
  • Next by Date: Re: getcontext() -> Bus error?
  • Previous by thread: Re: getcontext() -> Bus error?
  • Next by thread: Re: getcontext() -> Bus error?
  • Index(es):
    • Date
    • Thread