]> git.saurik.com Git - apple/system_cmds.git/blob - KDBG/Kernel.cpp
system_cmds-671.10.3.tar.gz
[apple/system_cmds.git] / KDBG / Kernel.cpp
1 //
2 // Kernel.cpp
3 // KDBG
4 //
5 // Created by James McIlree on 4/17/13.
6 // Copyright (c) 2014 Apple. All rights reserved.
7 //
8
9 #include "KDebug.h"
10
11 using namespace util;
12
13 bool Kernel::is_64_bit()
14 {
15 int mib[4];
16 size_t len;
17 struct kinfo_proc kp;
18
19 /* Now determine if the kernel is running in 64-bit mode */
20 mib[0] = CTL_KERN;
21 mib[1] = KERN_PROC;
22 mib[2] = KERN_PROC_PID;
23 mib[3] = 0; /* kernproc, pid 0 */
24 len = sizeof(kp);
25 if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &kp, &len, NULL, 0) == -1) {
26 THROW("sysctl to get kernel size failed");
27 }
28
29 if (kp.kp_proc.p_flag & P_LP64)
30 return true;
31
32 return false;
33 }
34
35 uint32_t Kernel::active_cpu_count()
36 {
37 int mib[4];
38 size_t len;
39 int num_cpus;
40
41 /*
42 * grab the number of cpus and scale the buffer size
43 */
44 mib[0] = CTL_HW;
45 mib[1] = HW_NCPU;
46 mib[2] = 0;
47 len = sizeof(num_cpus);
48
49 sysctl(mib, 2, &num_cpus, &len, NULL, 0);
50
51 return num_cpus;
52 }