64-Bit Transition Guide
“Huge” Data ObjectsIf your application may need random access to exceptionally large (>2GB) data sets, it is easier to support thesedata sets in a
As a special exception, the System Preferences application provides a 32-bit fallback mode. If the user selectsa system preferences pane without a 64-
There are many differences between 32-bit and 64-bit environments in OS X, including tool usage changes,changes to the size and alignment of data type
While almost all UNIX and Linux implementations use LP64, other operating systems use various data models.Windows, for example, uses LLP64, in which l
Note: Floating-point data type sizes are the same whether you are generating a 32-bit or 64-bitexecutable. However, the size of long double is 128 bi
Finally, never underestimate the convenience of a generic exchange format such as XML. ●LibrariesAll libraries used by 64-bit applications or kernel e
Before you begin to update your code, you should familiarize yourself with the document Mac TechnologyOverview . After reading that document, the firs
For code that is truly architecture-specific (such as assembly language code), you should continue to usearchitecture-specific tests. Be aware, howeve
#endifAvoid casting pointers to non pointers. You should generally avoid casting a pointer to a non-pointer typefor any reason (particularly when perf
Format stringTypePRIuNuintN _tPRIdLEASTNint_leastN _tPRIuLEASTNuint_leastN _tPRIdFASTNint_fastN _tPRIuFASTNuint_fastN _tPRIdPTRintptr_tPRIuPTRuintptr_
ContentsIntroduction to 64-Bit Transition Guide 6What Is 64-Bit Computing? 6Who Should Read This Document? 6Organization of This Document 6See Also 7S
For the most part, if you always use the sizeof function when allocating data structures and avoid assigningpointers to non-pointer types, the size an
int foo0;int foo1;int foo2;long long bar;};#pragma options align=resetYou should use this option only when absolutely necessary, because there is a pe
Use 64-bit types for pointer arithmetic results. Because the size of pointers is a 64-bit value, the result ofpointer arithmetic is also a 64-bit valu
A more common problem is storing a pointer temporarily in a variable of type int. In most cases, the compilerwill warn you that a pointer is being ass
●If you want the mask value to contain zeros in the upper 32 bits on a 64-bit architecture, the usualfixed-width mask will work as expected, because
There is a performance cost associated with pragmas, however; memory accesses to unaligned data fieldsresult in a performance penalty. Because there a
5.Constants (unless modified by a suffix, such as 0x8L) are treated as the smallest size that will hold thevalue. Numbers written in hexadecimal may b
Problem: The expected result (and the result from a 32-bit executable) is 0x80000000. The result generatedby a 64-bit executable, however, is 0xffffff
On Intel-based Macintosh computers, 64-bit code uses the Intel 64 (formerly EM64T) extensions to the Intelassembly language ISA. This section summariz
DescriptionIntel 64 Architecture 64-bit variantIA32 32-bit registerRegister 13 (new)R13 *----Register 14 (new)R14 *----Register 15 (new)R15 *----All o
Instruction Changes 29For More Information 29Compiling 64-Bit Code 31Compiling 64-Bit Code Using GCC 31New Flags and Features for 64-Bit Architectures
●http://developer.intel.com/technology/intel64/index.htm—Intel 64 Architecture technology page (Intel). ●http://software.intel.com/en-us/parallel/—In
The first part of this document describes issues you should consider when bringing code to a 64-bit architecture.You should read through those chapter
-WconversionAlthough not technically new for 64-bit architectures, this option is mostly useful when transitioning32-bit code to 64-bit. This flag cau
With Xcode 1.0 and later, you can build multiarchitecture binaries (MABs). Because each target can define theset of architectures for the target being
If you want to specify additional per-architecture compiler flags, you can use the PER_ARCH_CFLAGS_<arch>family of build settings, where <arc
Beginning in OS X v10.5, most OS X APIs are available to 64-bit applications. Going forward, Apple plans tomake new APIs 64-bit-compatible unless othe
These data types go by many names in various technology areas, but in terms of their underlying representation,the affected data types are one of thos
In certain technology areas (Carbon particularly), a few APIs have been deprecated for 32-bit use beginningin OS X v10.5. Most of these APIs are not a
Kernel and I/O Kit APIsAs of v10.8, 32-bit kernel extensions are no longer supported. Drivers and other kernel extensions for earlierversions of OS X
Other C Application APIsIn general, most C API changes are in the use of int and long within function prototypes. Similarly, manydata types based on i
Additional Tips For 64-Bit KEXTs 61Document Revision History 672012-12-13 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.4Contents
In some cases, you may find it useful to support plug-ins written for an architecture other than the one yourapplication is running on at the time. Yo
In general, the sheer number of exceptions and edge cases involved makes programmatic function-callmarshaling highly impractical, and thus it should g
Because the scope of the supported API is limited, it is much more practical for you to support them throughfunction-call marshaling, because you can
The biggest change you must make to support remote hosting is to maintain the state of your plug-in supportengine through function calls instead of va
●Create a communication thread in the helper host to transmit message entries from the buffer andstore the responses in some other part of the same m
Mach RPCMach RPC is not considered a public interface, and its direct use is not generally recommended. However, ifyou decide to use it, you can find
BSD socket API (described in socket)Each of these APIs implements the same underlying message, a bidirectional stream of bytes between bothends. Strea
Standard Input and OutputAnother common API for interprocess communication is standard input and output. This API provides a pairof unidirectional str
goto error_exit;}if (childpid) {/* Parent process */channel->in_fd = in_descriptors[0];close(in_descriptors[1]);channel->out_fd = out_descriptor
}Note: If you use a function like this one, you should always specify an absolute path to your helperapplication.Message QueuesMessage queues provide
Tables and ListingsMajor 64-Bit Changes 12Table 2-1 Size and alignment of base data types in OS X 13Making Code 64-Bit Clean 16Table 3-1 Standard form
/* Create the map file and fill it with bytes. */char *create_shm_file(char *progname, int length){int fd, i;char *filename=malloc(MAXNAMLEN+1);char *
If you intend to work with page-sized regions, you should also take note of the functions described in thempool manual page. However, for most purpose
the writepos must not be allowed to overtake the readposition, so subtract one from the final value.*/#define BYTES_TO_WRITE(ringbuffer) (ringbuffer-&
The next step is to execute the helper host, choosing the appropriate architecture in the process. In OS X v10.5and later, the recommended way to laun
When transitioning your application, kernel extension, or other code to 64-bit, you may notice a performancedecrease, depending on your code. While in
Because member_two is a pointer, it must be aligned on an 8-byte boundary. Thus, its address must be divisibleby 8. Because 4 is not divisible by 8, t
Cache-Line MissesChanges in data structure alignment can cause differences in cache-line hits and misses. While this usuallydoes not have a significan
Avoiding Unaligned AccessesIf you create data structures with packed alignment, you may see a performance regression caused by unalignedaccess penalti
In OS X v10.8 and later, the kernel is 64-bit (and some hardware used a 64-bit kernel as far back as v10.6). Thischapter describes the rationale for t
For a computer with 64 GB of RAM, given a 4 KB page size, the OS must manage almost 17 million pages ofphysical RAM, each of which has a page table en
This document describes the 64-bit features that are available in OS X v10.4 and v10.5. You should read it tohelp you determine which of these feature
Update user-client codeDevice drivers that talk directly to a user-space application without using I/O Kit families (such as userclients and the I/O K
First, these changes affect format strings for printf and IOLog calls. When printing these values, you caneither modify your code to use %ld when comp
Use the Large Zero Page FlagTo help debug pointer truncation issues, pass the -no_shared_cr3 flag as part of your boot arguments.(See Building and Deb
running in v10.6, this includes 32-bit PowerPC (Rosetta). For apps running in older versions of OS X, thismay even include 64-bit PowerPC.Here are som
If you are communicating in some way other than a user client, you can determine the byte orderof the remote application using a magic number, and wit
// Application is built for the same// architecture as this code, but may// be either 32-bit or 64-bit on Intel.magic++if (*magic == 0x00000000) {// r
struct mystruct mystruct_instance;mystruct_instance.order = HOST_ORDER;This still puts the burden of reading the field squarely on the code receiving
This table describes the changes to 64-Bit Transition Guide .NotesDateMade minor editorial revisions.2012-12-13Revised to update positioning of 64-bit
Apple Inc.Copyright © 2004, 2012 Apple Inc.All rights reserved.No part of this publication may be reproduced,stored in a retrieval system, or transmit
●Making Code 64-Bit Clean (page 16)—explains the general changes needed to make an application 64-bitclean. ●Compiling 64-Bit Code (page 31)—explains
As a general rule, in OS X v10.7 and later, the answer is probably yes. A 64-bit executable can provide manybenefits to users and to programmers, depe
I/O Kit Drivers and Other Kernel ExtensionsBecause a 64-bit kernel cannot load 32-bit kernel extensions, it is imperative that all kernel extensions b
Comments to this Manuals