Section A.5. Rosetta


A.5. Rosetta

We briefly discussed Rosetta in Section 2.11.9. Rosetta is a binary translation process that allows unmodified PowerPC executables to run on x86-based Macintosh computers. Rosetta's implementation consists of a program (/usr/libexec/oah/translate), a daemon (/usr/libexec/oah/translated), a collection of library/framework shims (/usr/libexec/oah/Shims/*), and support in the kernel, which has explicit knowledge of the translate program.

$ sysctl kern.exec.archhandler.powerpc # read-only variable kern.exec.archhandler.powerpc: /usr/libexec/oah/translate $ strings /mach_kernel ... /usr/libexec/oah/translate ...


The translate program can also be used from the command line to run programs under Rosetta. Figure A4 shows the source for a program that can be run both natively and under Rosetta to highlight the byte-ordering difference (see Section A.6) between the PowerPC and x86 platforms.

Figure A4. Running a program both natively and under Rosetta

// endian.c #include <stdio.h> int main(void) {     int i = 0xaabbccdd;     char *c = (char *)&i;     printf("%hhx %hhx %hhx %hhx\n", c[0], c[1], c[2], c[3]);     return 0; } $ gcc -Wall -arch i386 -arch ppc -o endian endian.c $ time ./endian # native (little-endian) dd cc bb aa ./endian  0.00s user 0.00s system 77% cpu 0.004 total $ time /usr/libexec/oah/translate ./endian # under Rosetta (big-endian) aa bb cc dd /usr/libexec/oah/translate ./endian  0.01s user 0.08s system 97% cpu 0.089 total

Rather than directly using translate, Universal binaries can be forced to run under Rosetta through several more appropriate means, such as the following.

  • Set the "Open using Rosetta" option in the Info window of an application. This adds an entry to the LSPrefsFatApplications dictionary in the per-user com.apple.LaunchServices.plist file.

  • Add the key named LSPrefersPPC, with its value being TRue, in the Info.plist file of an application.

  • Use the sysctlbyname() library function in a program to set the value of the sysctl named sysctl.proc_exec_affinity to CPU_TYPE_POWERPC. Thereafter, a Universal binary launched through fork() and exec() will cause the PowerPC version to run.

Whereas Rosetta has support for AltiVec, it does not support executables that require a G5 processor (which means it also does not support 64-bit PowerPC executables).

Note that Rosetta reports a PowerPC G4 processor to programs. Running the host_info program from Figure 61 under Rosetta will show the following:

... cpu ppc7400 (PowerPC 7400, type=0x12 subtype=0xa threadtype=0x0 ...





Mac OS X Internals. A Systems Approach
Mac OS X Internals: A Systems Approach
ISBN: 0321278542
EAN: 2147483647
Year: 2006
Pages: 161
Authors: Amit Singh

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net