9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Josh Wood <josh@utopian.net>
To: 9fans@9fans.net
Cc: Russ Cox <rsc@swtch.com>
Subject: Re: [9fans] 9vx native OS X gui
Date: Sun, 29 Jun 2008 07:55:45 -0700	[thread overview]
Message-ID: <AD3677EA-B5B2-4029-B2AC-52F528E513F7@utopian.net> (raw)

> I assume the fix would be to install an EXC_BAD_ACCESS
> handler after kicking off the app event loop.  That would
> make sure that Carbon never saw it.
> But I don't know how to do that.


I don't have a 10.5 mac to see if this is moot with the changes to
CrashReporter.app.

mach/mach.h has thread_set_exception_ports() to install handlers for
mach exceptions. There is also a task_ version for all the threads in
a task.

The basics are like:

	/* recieve right */
	kret = mach_port_allocate(mach_task_self(),
							MACH_PORT_RIGHT_RECIEVE,
							&exception_port);

	/* send right */
	kret = mach_port_insert_right(mach_task_self(),
							exception_port,
							exception_port,
							MACH_MSG_TYPE_MAKE_SEND);

	/* select exc type */
	kret = thread_set_exception_ports(mach_thread_self(),
								EXC_MASK_BAD_ACCESS,
								exception_port,
								EXCEPTION_DEFAULT,
								THEAD_STATE_NONE);

Then you do what you want with the exception; in the common case that
means set up fake sigcontext and deliver to signal handler code.

Amit Singh's osx kernel book has example code (http://macosxbook.com/
book/src/ in fig. 9-38). http://tinyurl.com/46dsgp is a production
example with comments @ the phrase ``Mach's exception mechanism''.

It's Apple's bug, and that's too far to have to go to work around it,
IMO, but the technique might be interesting or handy for this kind of
software atop osx.

-Josh



             reply	other threads:[~2008-06-29 14:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-29 14:55 Josh Wood [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-06-28 19:47 Russ Cox
2008-06-28 20:08 ` [9fans] " Pietro Gagliardi
2008-06-28 20:08 ` Russ Cox
2008-06-28 20:40   ` underspecified
2008-06-28 22:17     ` Anant Narayanan
2008-06-28 22:28       ` Pietro Gagliardi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AD3677EA-B5B2-4029-B2AC-52F528E513F7@utopian.net \
    --to=josh@utopian.net \
    --cc=9fans@9fans.net \
    --cc=rsc@swtch.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).