TweetFollow Us on Twitter

Winter 92 - KON & BAL'S PUZZLE PAGE

KON & BAL'S PUZZLE PAGE

KONSTANTIN OTHMER AND BRUCE LEAK

[IMAGE 103-105_Puzzle_Page_rev1.GIF]

See if you can solve this programming puzzle, presented in the form of a dialog between Konstantin Othmer (KON) and Bruce Leak (BAL). The dialog gives clues to help you. Keep guessing until you're done; your score is the number to the left of the clue that gave you the correct answer. These problems are supposed to be tough. If you don't get a high score, at least you'll learn interesting Macintosh trivia.

KON I wrote this program that crashes with a bus error and I can't figure out what's going wrong.

BAL If it's crashing with a bus error, that's easy: just figure out where the bogus bus error address came from.

110 KON Well, that's the problem. I look around and there's not a bad address anywhere.

BAL Let me see.

105 KON OK.

Bus Error at 1B586
1B582	BFEXTU (A3){D6; $00}, D0
1B586	*ADDQ.W	#$4,A3
1B588	MOVE.L(A2)+,D1

Register A3 has $70E368, and A2 has $70DEDC. So that's your puzzle; what do you do now?

BAL Hmmm. Suppose I trace a few times.

100 KON No problem; everything seems to work OK.

BAL What if I type "Go" and hope for the best?

95 KON You crash immediately with an address error at $1B5A4. The code is trying to do an RTS, but the stack is trashed.

BAL Well that's just a little ways down from where I was before. Anything funny happening in between?

90 KON Nope, just a loop that doesn't touch the stack or anything.

BAL Was the stack OK when I crashed the first time?

85 KON No, the top address on the stack was garbage.

BAL OK, so I run the program again and break just before this routine gets called and check the stack.

80 KON The stack is OK. Everything looks fine. You're at a JSR (A0).

BAL Is A0 OK?

75 KON Yep, it points to the code you were looking at before--at $1B582.

BAL So I step in and look at the stack.

70 KON You crash immediately with a bus error at $82.

BAL Huh? Sounds like someone jumped to $0.

65 KON A0 looked OK. It was just doing a JSR (A0).

BAL Some weird MacsBug bug?

60 KON In this case, no.

BAL All I did was step into a subroutine and I crash somewhere totally different?

55 KON Pretty cool, huh?

BAL Are the registers OK? What does the stack look like?

50

KON Garbage everywhere. The stack has all kinds of noise on it, and the registers seem pretty fragged.

BAL Hmmm. I try it again; this time I set a breakpoint a few instructions before the JSR (A0).

KON OK.

BAL Is everything OK?

45 KON The registers, stack, and code look OK.

BAL So I trace a few instructions, up to the JSR.

40 KON You crash immediately after the first trace with a bus error at $0104B0CA.

BAL Well that address is garbage. Was it in any register or on the stack before I traced?

35 KON Nope.

BAL What happened to the stack?

30 KON There's 56 extra bytes on it now.

BAL What? Is my machine possessed?

KON It's just a computer.

BAL Some interrupt nastiness happening?

25 KON When you crash, you're at interrupt level 1.

BAL Now we're getting somewhere. Does MacsBug enable interrupts when I trace?

20 KON Yes.

BAL So where's the level 1 interrupt vector kept?

15 KON $64.

BAL I DM it and see if it's OK.

10 KON It's $104B07C. Pretty close to where you crashed.

BAL So it sounds like someone is trashing the interrupt vectors, and all the interrupts are held pending when I'm in MacsBug. As soon as I do anything that returns control to the Macintosh, I blow up. So I step spy on $64 and see who trashes it.

0 KON It's a routine that assumed a buffer was being allocated but wasn't. So the buffer pointer was NIL, and the routine wrote all over low memory, including the exception vectors.

BAL Nasty.

KON Yeah. So how could you catch this before the vectors get trashed?

BAL Doesn't EvenBetterBusError catch writes to NIL?

KON Only at VBL time, and the chances of a VBL interrupt happening before the VBL vector gets trashed are mighty slim.

BAL You could initialize pointer variables to a bus error number like $50FFC001 instead of NIL. If you did that, you'd crash at the write and know immediately what was wrong.

KON Cool.


KONSTANTIN OTHMER AND BRUCE LEAK As a mere lad, Bruce pulled the programmer's key out of the stone and swore allegiance to the Lady of the Leak. Years later, while good King Bruce was doing penance for his wandering ways, young KON of Locksley had to defend the crown against the Mongol hordes attempting to draw directly to the screen. Upon his return, King Bruce declared, "Let there be time," and there was. Today young KON and his sovereign do battle against the forces of evil lurking in your local heap.*

SCORING

  • 100-110 Be honest.
  • 75-95 Next time we find a bug, we're  calling you .
  • 50-70 So this has happened to you!
  • 25-45 No doubt about it, these puzzles are tough.
  • 0-20 Well, maybe next time . . . *

Thanks to Scott Douglass for reviewing this column.*

 
AAPL
$433.26
Apple Inc.
-1.32
MSFT
$34.87
Microsoft Corpora
+0.79
GOOG
$909.18
Google Inc.
+5.31

MacTech Search:
Community Search:

Software Updates via MacUpdate

OnyX 2.6.9 - Maintenance and optimizatio...
OnyX is a multifunctional utility for OS X. It allows you to verify the startup disk and the structure of its System files, to run miscellaneous tasks of system maintenance, to configure the hidden... Read more
Apple iTunes 11.0.3 - Manage your music,...
Apple iTunes lets you organize and play digital music and video on your computer. It can automatically download new music, app, and book purchases across all your devices and computers. And it's a... Read more
Spotify 0.9.0.133. - Stream music, creat...
Spotify is a new way to enjoy music. Simply download and install. Before you know it you'll be singing along to the genre, artist, or song of your choice. With Spotify you are never far away from... Read more
JollysFastVNC 1.46 - Fast VNC client. (S...
JollysFastVNC is a VNC client which aims to become the best VNC client on the Mac. When I started ScreenRecycler I thought that there are enough VNC clients out there to support it. When the program... Read more
Skitch 2.5.2 - Take screenshots, annotat...
Skitch allows you to take screenshots on your Mac, edit them and share them with others. It makes the sharing process seamless by making it a natural workflow to send the image (with edited arrows... Read more
Backblaze 2.1.0.608 - Online backup serv...
Backblaze is an online backup service, available fo $5/month for unlimited storage. With half of the founding team heralding from Apple, Backblaze is deeply committed to the Mac platform. The... Read more
The Cave 1.0.0 - Adventure game featurin...
The Cave is an adventure game that offers a unique blend of fast-paced action, mind-bending puzzles, and winning humor. Assemble your team and embark on a journey into the shadowy underworld. Once... Read more
StatsBar 1.4 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Thunderbird 17.0.6 - Email client from M...
As of July 2012, Thunderbird is no longer being actively developed, although security improvements will continue to be released as needed. Thunderbird is a free, open-source, cross-platform e-mail... Read more
Adobe Flash Player 11.8.800.50 - Multime...
Adobe Flash Player is a cross-platform, browser-based application runtime that provides uncompromised viewing of expressive applications, content, and videos across browsers and operating systems.... Read more

This Week at 148Apps: May 13-17, 2013
We Are Your App Review Source   | Read more »
Second Home – Xbox Live Indie Developers...
The indie game development scene has been around for an incredibly long time; pretty much ever since people had the opportunity to program for themselves. However it wasn’t until shareware became a common method of distribution the 90s that it began... | Read more »
The Simpsons: Tapped Out Adds New Charac...
The Simpsons: Tapped Out Adds New Character and Locations In Latest Update Posted by Andrew Stevens on May 17th, 2013 [ permalink ] | Read more »
Fast & Furious 6: The Game Review
Fast & Furious 6: The Game Review By Jennifer Allen on May 17th, 2013 Our Rating: :: SPEEDY YET SLOW PACEDUniversal App - Designed for iPhone and iPad It’s not that Fast & Furious 6 isn’t a fun drag racer, it’s just that... | Read more »
N.O.V.A. 3 – Near Orbit Vanguard Allianc...
N.O.V.A. 3 – Near Orbit Vanguard Alliance Is Free For Today Only Posted by Andrew Stevens on May 17th, 2013 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Turbo Racing League Is Now Available, Pr...
Turbo Racing League Is Now Available, Provides Players A Chance To Win Cash Prizes Posted by Andrew Stevens on May 17th, 2013 [ permalink ] | Read more »
Running with Friends Review
Running with Friends Review By Blake Grundman on May 17th, 2013 Our Rating: :: FAMILIAR, YET FUNUniversal App - Designed for iPhone and iPad A game may look and play identically to other titles on the market, but this is one that... | Read more »
Festival de Cannes Lets You Experience T...
Festival de Cannes Lets You Experience The Festival In Real Time Posted by Andrew Stevens on May 17th, 2013 [ permalink ] | Read more »
Sonic the Hedgehog’s Remastered Version...
The original Sonic the Hedgehog has been remastered for iOS, a la Sonic CD. | Read more »
tenXer Tracks All Your Activities And Re...
tenXer Tracks All Your Activities And Reports Them For You Posted by Andrew Stevens on May 17th, 2013 [ permalink ] iPhone App - Designed for the iPhone, compatible with the iPad | Read more »

Price Scanner via MacPrices.net

Apple now offering full line of refurbished iMacs...
Apple has Apple Certified Refurbished 2012 iMacs in stock today for up to $330 off MSRP – 15% off. Each iMac comes with an Apple one-year warranty, and shipping is free: - 21″ 2.7GHz iMac: $1099 $100... Read more
Save up to $200 on MacBooks with Apple Education p...
Purchase a new 2012 MacBook Pro, MacBook Pro with Retina Display, or MacBook Air at The Apple Store for Education and take up to $200 off MSRP. All teachers, students, and staff of any educational... Read more
15″ MacBook Pros (Apple refurbished) in stock star...
The Apple Store has several Apple Certified Refurbished 15-inch MacBook Pros in stock today, with models starting at $1489. Each MacBook Pro comes with Apple’s one-year warranty, and home shipping (... Read more
Save up to $100 on iMacs with Apple Education disc...
Take up to $100 off the price of a new 21″ or 27″ iMac at The Apple Store for Education. All students, teachers, and staff at any educational institution qualify for the discount, and shipping is... Read more
Mac mini Server on sale for $50 off MSRP
B&H Photo has the 2012 Mac mini Server on sale for $949 including free shipping plus NY sales tax only. Their price is $50 off MSRP, and it’s the lowest price available for this model. B&H... Read more
Steve Jobs Triumphs Posthumously In Platform Wars...
The Register’s Paul Kunert says it’s finally official – the epic battle of legendary Apple CEO Steve Jobs is finally won, now that he has toppled the PC platform from beyond the grave, in the UK, at... Read more
Microsoft Surface Pro vs Apple MacBook Air 11in
Stuff has posted a concise comparo review of the Microsoft Surface Pro tablet PC versus Apple’s 11.6-inch MacBook Air, noting that both machines offer a full desktop OS and a current-generation Intel... Read more
Pixelmator 2.2 First Week Downloads Top Half a Mil...
The Pixelmator Team has announced that Pixelmator 2.2 downloads have topped half a million since last Thursday, making it the most successful release in Pixelmator history. With over 100 new features... Read more
AppleCare Protection Plans on sale for up to $105...
B&H Photo has 3-Year AppleCare Warranties on sale for up to $105 off MSRP including free shipping plus NY sales tax only: - Mac Laptops 15″ and Above: $244 $105 off MSRP - Mac Laptops 13″ and... Read more
27″ Apple Display (refurbished) available for $829...
The Apple Store has Apple Certified Refurbished 27″ Thunderbolt Displays available for $829 including free shipping. That’s $170 off the cost of new models. Read more

Jobs Board

*Apple* Retail - Manager - Apple (Unite...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, youre a master of them all. In the stores fast-paced, dynamic Read more
*Apple* At-Home Team Manager - Apple (U...
Changing the world is all in a day's work at Apple . If you love innovation, here's your chance to make a career of it. You'll work hard. But the job comes with more than Read more
*Apple* Retail - Manager - Apple Inc. (...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you're a master of them all. In the store's fast-paced, dynamic Read more
*Apple* Support Engineer - Systemtec, I...
Apple Support Engineer SYSTEMTEC. FIND YOUR NEW CAREER PATH! Technology projects within organizations present unique opportunities. By offering your expertise within a Read more
*Apple* Engineer - DP Professionals Inc...
DP Professionals is seeking an Apple Engineer for a contract in Charleston, SC. The Apple Engineer will provide Mac and iOS device and application support, and Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.