Skip to content

Commit

Permalink
Use mach utils when available
Browse files Browse the repository at this point in the history
  • Loading branch information
bamx23 committed May 6, 2024
1 parent 34f50c2 commit 5d45a2f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
27 changes: 22 additions & 5 deletions Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@


#import "KSCrashReportFilterAppleFmt.h"

#import "KSSystemCapabilities.h"

#import <inttypes.h>
#import <mach/machine.h>
#include <mach-o/arch.h>
#include <mach-o/utils.h>

#import "KSCrashReportFields.h"
#import "KSJSONCodecObjC.h"
Expand Down Expand Up @@ -264,12 +265,28 @@ - (NSString*) CPUType:(NSString*) CPUArch isSystemInfoHeader:(BOOL) isSystemInfo

- (NSString*) CPUArchForMajor:(cpu_type_t) majorCode minor:(cpu_subtype_t) minorCode
{
#ifdef __APPLE__
#if KSCRASH_HOST_APPLE
// In Apple platforms we can use this function to get the name of a particular architecture
const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode);
if (info && info->name) {
return [[NSString alloc] initWithUTF8String: info->name];
#if !KSCRASH_HOST_VISION
if(@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *))
#endif
{
const char *archName = macho_arch_name_for_cpu_type(majorCode, minorCode);
if(archName)
{
return [[NSString alloc] initWithUTF8String:archName];
}
}
#if !KSCRASH_HOST_VISION
else
{
const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode);
if (info && info->name)
{
return [[NSString alloc] initWithUTF8String:info->name];
}
}
#endif
#endif

switch(majorCode)
Expand Down
20 changes: 12 additions & 8 deletions Sources/KSCrashRecordingCore/KSCPU.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@

#include <mach/mach.h>
#include <mach-o/arch.h>

#if KSCRASH_HOST_VISION
#include <mach-o/utils.h>
#endif

//#define KSLogger_LocalLevel TRACE
#include "KSLogger.h"


const char* kscpu_currentArch(void)
{
#if KSCRASH_HOST_VISION
return macho_arch_name_for_mach_header(NULL);
#else
const NXArchInfo* archInfo = NXGetLocalArchInfo();
return archInfo == NULL ? NULL : archInfo->name;
#if !KSCRASH_HOST_VISION
if(__builtin_available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *))
#endif
{
return macho_arch_name_for_mach_header(NULL);
}
#if !KSCRASH_HOST_VISION
else
{
const NXArchInfo* archInfo = NXGetLocalArchInfo();
return archInfo == NULL ? NULL : archInfo->name;
}
#endif
}

Expand Down

0 comments on commit 5d45a2f

Please sign in to comment.