9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] 9vx native OS X gui
@ 2008-06-29 14:55 Josh Wood
  0 siblings, 0 replies; 6+ messages in thread
From: Josh Wood @ 2008-06-29 14:55 UTC (permalink / raw)
  To: 9fans; +Cc: Russ Cox

> 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



^ permalink raw reply	[flat|nested] 6+ messages in thread
* 9vx native OS X gui
@ 2008-06-28 19:47 Russ Cox
  2008-06-28 20:08 ` [9fans] " Pietro Gagliardi
  2008-06-28 20:08 ` Russ Cox
  0 siblings, 2 replies; 6+ messages in thread
From: Russ Cox @ 2008-06-28 19:47 UTC (permalink / raw)
  To: 9fans

The 9vx 0.11 source code includes OS X gui code,
a severely cleaned-up version of the drawterm code.

It is not built by default, but you can build it by using

	make 9vx/9vx PLAN9GUI=osx

Unfortunately, it seems to have one problem: the
Carbon app event loop appears to install its own
handler for EXC_BAD_ACCESS, the Mach equivalent
of SIGBUS/SIGSEGV.  When it gets that exception,
it passes it along, but first it pops up an annoying
"The application 9vx quit unexpectedly" dialog.
Even if you turn the popup off (with TinkerTool),
the handler must record that things are broken,
and the cursor turns into a pinwheel forever:
Carbon/Quartz/whatever-it's-called-today can't
fathom the idea that an EXC_BAD_ACCESS came in
and the app actually survived it.

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.

Russ



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-06-29 14:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-29 14:55 [9fans] 9vx native OS X gui Josh Wood
  -- 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

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).