Morphing into MIG

When we last left off, we were able to cook up a service name of our choosing, and resolve it from a client. If we hooked up launchd stuff, we could also make it demand-launch (maybe that’s for another day). But we didn’t actually do anything with that resolution. There are several reasons for that, first, because actually crafting a message and sending/receiving it was covered by a prior article. But even more than that, there are actually a substantial number of design decisions around this task, and plowing ahead requires a lot of text.

I’ll start with the previous server/client, and flesh it out in small steps. In between the steps, I’ll outline design decisions, maybe some history, and pitfalls/sharp edges to be aware of.

Making a mach server

(This is a sort of simplified retelling of http://fdiv.net/2011/01/14/machportt-inter-process-communication with some added lore. You should probably start there.)

Much of the magic behind macOS and iOS (and all the derived xOSs - watch, appleTV, the stripped down versions in cables and touch bars and wherever else these things invariably end up) is performed with the assistance of other processes (including the kernel). Communicating between them is accomplished by various ways, but for macOS, the underlying mechanism is a client/server IPC mechanism powered by Mach, and the underlying currency is the mach port (mach_port_t).

Mirror, Mirror, or, Don't fly off the Handle

During my time at Apple, I dealt with a lot of rather low-level systems treachery. It’s poorly documented, even internally, and asking for help has roughly even odds on getting a passive aggressive non-answer.

The cool trick for today is creating a “memory object.” A memory object is one or more physical pages that are wrapped in a mach port. With this, you can pass the port to another process, who can map the pages, creating shared memory. Or you can map the pages again in your own address space, to create a mirror, or with different permissions so you can expose read-only pages at an interface boundary while still having the pages be writable at a different address.

Tweaking Synology’s DNS Server For Great Justice

Years ago I purchased a Synology NAS (a DS1812+, if you must know). I also purchased some hard drives for it, and a 2GB stick of RAM (bringing its total up to 3GB). Under the hood it’s a dual-core Cedarview Atom x86 CPU, and it runs a Linux distro wherein the owner of the device also has root access (i.e., you own what you own, like in the good old days). It’s also got dual GB NICs, some USB ports, etc.

In addition to storing substantial slabs of data, you can install services on these devices, so in effect they’re more like mini servers than the NAS name might imply. It’s busybox-based though, so a lot of the normal Linux commands act weird or don’t have useful aliases (more, not less, only a subset of vi commands work, etc).

One of the services I opted to install was a DNS server, in the hopes that it would allow me to move some per-machine hosts file management stuff to it, and that our previously-rootless devices (read: iPads, iPhones, etc) would also be able to finally take advantage of a local caching name server with internal friendly names for devices that don’t participate in Bonjour.

memset() vs. bzero() — Ultimate Showdown

There are a few functions used to zero out memory on most unix variants. memset(), bzero(), and calloc() are all a few such functions. calloc() isn’t very useful for clearing already allocated memory, so it won’t be appearing much more in this article. However, the other two are somewhat more interesting than meets the eye.

90% Easy, 10% Impossible

90% Easy, 10% Impossible Pie ChartFrom time to time, I get these insatiable urges to read what other Cocoa developers blog about. Sometimes they’re informative, sometimes they’re funny, sometimes they read like college textbooks, and sometimes they’re just downright terrible, but I read them anyway. It comes and goes in waves, every 2 or 3 months. A couple weeks ago, one such binge happened, and I started reading Aaron Hillegass’ critique of NSController (since I was hating it at the time, and wanted to feel justified in hating it). In the critique, the following statement was made:

QTKit QCheatKit

QuickTime LogoApple has been busily working to 64-bit-ify all of the frameworks they plan to continue supporting into the future (Snow Leopard and beyond). However, QuickTime is scheduled for some nice Cocoaification, so it didn’t get much 64-bit love. QTKit, the 64-bit impostor, pretends to be the 64-bit way forward, but unfortunately this is far from useful.

QuickTime is all C function stuff, rather verbose and boring. It’s also 32-bit only. The 64-bit front end on it is a framework called QTKit. However, 64-bit QTKit is little more than an impostor that secretly makes things messier during the 32-to-64-bit transition.

Silicon Dioxide (SiO₂)

QuartzCrystal LogoIn the wee small hours of this morning, Kineme Interactive Media released its first commercial product, QuartzCrystal.

QuartzCrystal is an offline renderer that turns Quartz Compositions into portable QuickTime movies. It supports 3rd party plugins, as well as patches that do not work in safe-mode-only environments (such as QuickTime Pro). It also supports software scene antialiasing, so if you have a Mac with plenty of RAM and a hard-core video card, you can make spectacularly beautiful renderings of your plugins, effects, and compositions.

Beside QuartzCrystal, the only other product that renders and encodes compositions to movies is Apple’s own QuickTime Pro, which doesn’t support plugins, unsafe patches, or antialiasing.

QuartzCrystal Main Window Screenshot

Data Integrity a Posteriori

Danger: Corrosive Liquids.  Wear Protective Equipment.Data integrity is a hot topic these days. With data volumes on the rise and hard drive half-lives falling, protecting data has become important in many different fields.

Conventionally, a storage medium will report its life expectancy in terms of MTBF, or Mean Time Between Failures. This is often measured in hours. However, it’s not always this simple. Usage patterns and environmental characteristics take a heavy toll on how long our storage devices last.

Python's Flying Circus

Lately I’ve been working on integrating (or, more accurately, attempting to integrate) the Python scripting language into some plugins for an application we develop plugins for. We’ve wrapped many libraries with varying levels of success, so this one wasn’t going to be much different. Or, so we thought.

Mac OS Xodus

(First, yes I do realize the ‘X’ in ‘OS X’ is pronounced “ten” not “ecks.” I simply like the portmanteau.)

With the release of Leopard, I discovered the need to migrate my existing Tiger system onto an external drive. I needed it to be bootable, and I wanted to have a little discontinuity as possible. Apple generally makes this pretty easy, but it’s still a bit involved. I write this article from my migrated system, currently booting Tiger off of a USB drive.

Zero Grams of Trans Fat Binaries

tons of xcode build targetsPeople like their applications to work. Even better, they like them to work, even when things change. For the WinTel world, this isn’t a big deal (Vista aside ;), because the underlying CPU architecture hasn’t really changed, from a program’s point of view, in the past two decades. Unless you have a weird program that’s designed for AMD’s 3DNow! instruction set and you switch to an Intel CPU, or perhaps an application designed for a more esoteric old SIMD architecture, your application should run just fine (as long as your Operating System is ok with it).

Mac OS X doesn’t have the luxury of working on the same underlying CPU though, so things need to be handled a little bit differently. The solution Apple came up with was

iPhoto-Thunderbird Bridge

iPhoto logoFor years, iPhoto users have been stuck using a limited number of email clients to send their photos easily. This was mostly remedied by the iPhoto Mailer Patcher, but it left out non-applescript aware applications because, after all, iPhoto uses applescript to interface with them. One of the more notable omissions is Thunderbird.

Finally, this void has also been filled, via the iPhoto Thunderbird Bridge. It’s still quite primitive, but all the basics are there for iPhoto-Thunderbird integration.

If you’re an iPhoto/Thunderbird user, give it a whirl.

Leaky NSSpeechSynthesizer

NSSpeechSynthesizer, the Cocoa class responsible for giving applications a voice under OS X, is leaky. Creating and destroying thousands of instances of this class slowly consumes all the available memory in a system, leading to degrading performance and eventual application instability.

The disappointing part is that this bug was first noticed almost two years ago.