Skip navigation.
 
mlSolved: How to tell when app will run in 64-bit mode?
FROM : Jon Gotow
DATE : Wed Feb 06 20:41:09 2008

At 12:20 PM -0500 2/6/08, Jon Gotow wrote:
>The crux of the matter is really that NXGetLocalArchInfo() returns a
>cputype of CPU_TYPE_X86 on both Core Duo and Core 2 Duo machines.
>Shouldn't it return CPU_TYPE_X86_64 on Core 2 Duo?


As is often the case, discussing the problem with you smart folks
here (thanks Ben :-) led me to reassess what I was doing.  Given that
NXGetLocalArchInfo() wasn't giving me what I thought it should, I
looked for a different way to do the same thing.

Digging through some darwin code, I found the "sysctl.proc_cputype"
sysctl token.  THAT gives the right results.  On my Core 2 Duo, when
I check a running process, I now get a cpu type of:

   cpu_type = (CPU_TYPE_X86 | CPU_ARCH_ABI64)

if the process is running in 64 bit mode.

- Jon



For those that can benefit from it, here's the code, which uses the
sysctlbyname_with_pid() function in Apple's Universal Binary
Programming Guidelines:

cpu_type_t GetProcessArchitecture(pid_t pid)
{
    cpu_type_t cputype;
    size_t cpusz = sizeof(cputype);
   
    // Default values
#if __i386__
    cputype = CPU_TYPE_X86;
#else
    cputype = CPU_TYPE_POWERPC;
#endif

    if (sysctlbyname_with_pid("sysctl.proc_cputype", pid,
                              &cputype, &cpusz, NULL, 0) == -1)
    {
        fprintf(stderr, "proc_cputype: sysctlbyname_with_pid failed:"
                "%s\n", strerror(errno));
    }
    return cputype;
}
--
________________________________________________________________________
        Jon Gotow                    <email_removed>
    St. Clair Software              http://www.stclairsoft.com/
    Fax (540)552-5898              ftp://ftp.stclairsoft.com/

Related mailsAuthorDate
mlHow to tell when app will run in 64-bit mode? Jon Gotow Feb 6, 17:30
mlRe: How to tell when app will run in 64-bit mode? Ben Allison Feb 6, 18:01
mlRe: How to tell when app will run in 64-bit mode? Ben Allison Feb 6, 18:03
mlRe: How to tell when app will run in 64-bit mode? Ben Allison Feb 6, 18:12
mlRe: How to tell when app will run in 64-bit mode? Jon Gotow Feb 6, 18:20
mlRe: How to tell when app will run in 64-bit mode? Jon Gotow Feb 6, 18:25
mlRe: How to tell when app will run in 64-bit mode? Ben Allison Feb 6, 18:40
mlRe: How to tell when app will run in 64-bit mode? Jon Gotow Feb 6, 18:48
mlSolved: How to tell when app will run in 64-bit mode? Jon Gotow Feb 6, 20:41
mlRe: How to tell when app will run in 64-bit mode? Jon Gotow Feb 6, 21:26
mlRe: Solved: How to tell when app will run in 64-bit mode? Douglas Davidson Feb 6, 21:34
mlRe: How to tell when app will run in 64-bit mode? Markus Hitter Feb 6, 22:04
mlRe: How to tell when app will run in 64-bit mode? Helge Hess Feb 7, 01:39
mlRe: How to tell when app will run in 64-bit mode? Jon Gotow Feb 7, 16:17