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/
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/






Cocoa mail archive

