X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/1a7e3f61d38d679bba59130891c2031b5a0092b6..bd6521f0fc816ab056bc71376f9706a69b3b52c1:/KDBG/Kernel.cpp diff --git a/KDBG/Kernel.cpp b/KDBG/Kernel.cpp new file mode 100644 index 0000000..8553f2e --- /dev/null +++ b/KDBG/Kernel.cpp @@ -0,0 +1,52 @@ +// +// Kernel.cpp +// KDBG +// +// Created by James McIlree on 4/17/13. +// Copyright (c) 2014 Apple. All rights reserved. +// + +#include "KDebug.h" + +using namespace util; + +bool Kernel::is_64_bit() +{ + int mib[4]; + size_t len; + struct kinfo_proc kp; + + /* Now determine if the kernel is running in 64-bit mode */ + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = 0; /* kernproc, pid 0 */ + len = sizeof(kp); + if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &kp, &len, NULL, 0) == -1) { + THROW("sysctl to get kernel size failed"); + } + + if (kp.kp_proc.p_flag & P_LP64) + return true; + + return false; +} + +uint32_t Kernel::active_cpu_count() +{ + int mib[4]; + size_t len; + int num_cpus; + + /* + * grab the number of cpus and scale the buffer size + */ + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + mib[2] = 0; + len = sizeof(num_cpus); + + sysctl(mib, 2, &num_cpus, &len, NULL, 0); + + return num_cpus; +}