diff options
author | Pwn20wnd <pwn20wndstuff@gmail.com> | 2019-03-09 23:30:26 +0300 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2019-03-20 23:27:12 -1000 |
commit | 7bca6ad19e54e2edc4ec9cfa10da20a26e294334 (patch) | |
tree | 9805a17e7d5ecdedc2aeb0a0328c6b2df1b26828 /kernel_call/platform.c | |
parent | 4abbd1f554d3f1a185fd7079ee84944f1b0a355b (diff) |
Merge pwn's changes to support arm64e via rebase
Diffstat (limited to 'kernel_call/platform.c')
-rwxr-xr-x | kernel_call/platform.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/kernel_call/platform.c b/kernel_call/platform.c new file mode 100755 index 0000000..6ced006 --- /dev/null +++ b/kernel_call/platform.c @@ -0,0 +1,54 @@ +/* + * platform.c + * Brandon Azad + */ +#define PLATFORM_EXTERN +#include "platform.h" + +#include <assert.h> +#include <mach/mach.h> +#include <sys/sysctl.h> +#include <sys/utsname.h> + +#include "log.h" + +// ---- Initialization ---------------------------------------------------------------------------- + +void +platform_init() { + // Only initialize once. + static bool initialized = false; + if (initialized) { + return; + } + initialized = true; + // Set the page size. + platform.page_size = vm_kernel_page_size; + page_size = platform.page_size; + // Get the machine name (e.g. iPhone11,8). + struct utsname u = {}; + int error = uname(&u); + assert(error == 0); + strncpy((char *)platform.machine, u.machine, sizeof(platform.machine)); + // Get the build (e.g. 16C50). + size_t osversion_size = sizeof(platform.osversion); + error = sysctlbyname("kern.osversion", + (void *)platform.osversion, &osversion_size, NULL, 0); + assert(error == 0); + // Get basic host info. + mach_port_t host = mach_host_self(); + assert(MACH_PORT_VALID(host)); + host_basic_info_data_t basic_info; + mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; + kern_return_t kr = host_info(host, HOST_BASIC_INFO, (host_info_t) &basic_info, &count); + assert(kr == KERN_SUCCESS); + platform.cpu_type = basic_info.cpu_type; + platform.cpu_subtype = basic_info.cpu_subtype; + platform.physical_cpu = basic_info.physical_cpu; + platform.logical_cpu = basic_info.logical_cpu; + platform.memory_size = basic_info.max_mem; + INFO("memory_size: %zu", platform.memory_size); + mach_port_deallocate(mach_task_self(), host); + // Log basic platform info. + DEBUG_TRACE(1, "platform: %s %s", platform.machine, platform.osversion); +} |