c - Getting cpu_subtype_t in process that runs under i386 arch -
i'm using c code generate coredump file out of mach-o based process.
however, i'm getting parsing corruption while loading lldb debugger after generating coredump 32bits process :
(lldb) target create --core "/tmp/core_pid_1354" core file '/tmp/x/core.1354' (unknown-mach-32) loaded.
this, unknown 32 architecture issue, derived wrong cpu_subtype in struct mach_header.
in order cpu_type + cpu_subtype in following method :
struct current_arch cpuarch = {0}; int mib[ctl_maxname]; size_t miblen; size_t cputypesize; pid_t pid = getpid(); miblen = ctl_maxname; int err = sysctlnametomib("sysctl.proc_cputype", mib, &miblen); if (err) { log_error("coultn't mib cpu type using sysctlnametomib. err = %d ", err); return kern_failure; } mib[miblen] = pid; miblen += 0x1; cputypesize = sizeof(cpuarch.type); err = sysctl(mib, (u_int)miblen, &(cpuarch.type), &cputypesize, 0x0, 0x0); if (err) { log_error("coultn't cpu_type+cpu_subtype mib using syctl. err = %d ", err); return kern_failure; } *cpu_type = cpuarch.type; *cpu_subtype = cpuarch.subtype; return kern_success;
i've compiled core dumper tool under universal format (both 32/64 bits). , and when trying under arch=i386, cpu_subtype=0, non valid subtype i386. expect value of macro cpu_subtype_386 defined in machine.h file (=3):
#define cpu_subtype_intel(f, m) ((cpu_subtype_t) (f) + ((m) << 4)) #define cpu_subtype_386 cpu_subtype_intel(3, 0)
any idea what's wrong in code getting cpu_subtype_t?
Comments
Post a Comment