Skip to content

Commit

Permalink
Test3
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Dec 21, 2023
1 parent 120ce54 commit 353c73d
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/common/mac/arch_utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,28 @@

#include "common/mac/arch_utilities.h"

#include <Availability.h>
#include <AvailabilityMacros.h>

#include <mach/machine.h>
#include <mach-o/arch.h>
#include <mach-o/fat.h>
#include <stdio.h>
#include <string.h>

#include <TargetConditionals.h>

#ifdef __APPLE__
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000 || \
__IPHONE_OS_VERSION_MIN_REQUIRED >= 160000 || \
__TV_OS_VERSION_MIN_REQUIRED >= 160000
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && defined(__IPHONE_16_0) && \
__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_16_0) || \
(defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
defined(MAC_OS_X_VERSION_13_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_13_0) || \
(defined(__TV_OS_VERSION_MIN_REQUIRED) && \
defined(__TV_OS_VERSION_16_0) && \
__TV_OS_VERSION_MIN_REQUIRED >= __TVOS_16_0)
#define HAS_MACHO_UTILS 1
#include <mach-o/utils.h>
#else
#define HAS_MACHO_UTILS 0
#endif
#endif

Expand Down Expand Up @@ -101,40 +110,43 @@ ArchInfo GetLocalArchInfo(void) {
#ifdef __APPLE__

std::optional<ArchInfo> GetArchInfoFromName(const char* arch_name) {
#if HAS_MACHO_UTILS
if (__builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, *)) {
cpu_type_t type;
cpu_subtype_t subtype;
if (macho_cpu_type_for_arch_name(arch_name, &type, &subtype)) {
return ArchInfo{type, subtype};
}
} else {
return std::nullopt;
}
#endif
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
const NXArchInfo* info = NXGetArchInfoFromName(arch_name);
const NXArchInfo* info = NXGetArchInfoFromName(arch_name);
#pragma clang diagnostic pop
if (info) {
return ArchInfo{info->cputype, info->cpusubtype};
}
if (info) {
return ArchInfo{info->cputype, info->cpusubtype};
}
return std::nullopt;
}

const char* GetNameFromCPUType(cpu_type_t cpu_type, cpu_subtype_t cpu_subtype) {
#if HAS_MACHO_UTILS
if (__builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, *)) {
const char* name = macho_arch_name_for_cpu_type(cpu_type, cpu_subtype);
if (name) {
return name;
}
} else {
return kUnknownArchName;
}
#endif
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
const NXArchInfo* info = NXGetArchInfoFromCpuType(cpu_type, cpu_subtype);
const NXArchInfo* info = NXGetArchInfoFromCpuType(cpu_type, cpu_subtype);
#pragma clang diagnostic pop
if (info) {
return info->name;
}
if (info) {
return info->name;
}

return kUnknownArchName;
}

Expand Down

0 comments on commit 353c73d

Please sign in to comment.