Skip to content

Commit 7a99bee

Browse files
committed
Add a field for checking if app started using Rosetta
1 parent 830d100 commit 7a99bee

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

Sources/KSCrashRecording/KSCrash.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ - (NSDictionary *)systemInfo
209209
COPY_STRING(kernelVersion);
210210
COPY_STRING(osVersion);
211211
COPY_PRIMITIVE(isJailbroken);
212+
COPY_PRIMITIVE(procTranslated);
212213
COPY_STRING(bootTime); // this field is populated in an optional monitor
213214
COPY_STRING(appStartTime);
214215
COPY_STRING(executablePath);

Sources/KSCrashRecording/KSCrashReportC.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@ static void writeSystemInfo(const KSCrashReportWriter *const writer, const char
15271527
writer->addStringElement(writer, KSCrashField_KernelVersion, monitorContext->System.kernelVersion);
15281528
writer->addStringElement(writer, KSCrashField_OSVersion, monitorContext->System.osVersion);
15291529
writer->addBooleanElement(writer, KSCrashField_Jailbroken, monitorContext->System.isJailbroken);
1530+
writer->addBooleanElement(writer, KSCrashField_ProcTranslated, monitorContext->System.procTranslated);
15301531
writer->addStringElement(writer, KSCrashField_BootTime, monitorContext->System.bootTime);
15311532
writer->addStringElement(writer, KSCrashField_AppStartTime, monitorContext->System.appStartTime);
15321533
writer->addStringElement(writer, KSCrashField_ExecutablePath, monitorContext->System.executablePath);

Sources/KSCrashRecording/Monitors/KSCrashMonitor_System.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
const char *kernelVersion;
5656
const char *osVersion;
5757
bool isJailbroken;
58+
bool procTranslated;
5859
const char *appStartTime;
5960
const char *executablePath;
6061
const char *executableName;
@@ -309,6 +310,24 @@ static bool isJailbroken(void)
309310
return sJailbroken;
310311
}
311312

313+
/** Check if the app is started using Rosetta translation environment
314+
*
315+
* @return true if app is translated using Rosetta
316+
*/
317+
static bool procTranslated(void)
318+
{
319+
#if KSCRASH_HOST_MAC
320+
// https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment
321+
int proc_translated = 0;
322+
size_t size = sizeof(proc_translated);
323+
if (!sysctlbyname("sysctl.proc_translated", &proc_translated, &size, NULL, 0) && proc_translated) {
324+
return true;
325+
}
326+
#endif
327+
328+
return false;
329+
}
330+
312331
/** Check if the current build is a debug build.
313332
*
314333
* @return YES if the app was built in debug mode.
@@ -472,6 +491,7 @@ static void initialize(void)
472491
if (isSimulatorBuild()) {
473492
g_systemData.machine = cString([NSProcessInfo processInfo].environment[@"SIMULATOR_MODEL_IDENTIFIER"]);
474493
g_systemData.model = "simulator";
494+
g_systemData.systemVersion = cString([NSProcessInfo processInfo].environment[@"SIMULATOR_RUNTIME_VERSION"]);
475495
} else {
476496
#if KSCRASH_HOST_MAC
477497
// MacOS has the machine in the model field, and no model
@@ -485,6 +505,7 @@ static void initialize(void)
485505
g_systemData.kernelVersion = stringSysctl("kern.version");
486506
g_systemData.osVersion = stringSysctl("kern.osversion");
487507
g_systemData.isJailbroken = isJailbroken();
508+
g_systemData.procTranslated = procTranslated();
488509
g_systemData.appStartTime = dateString(time(NULL));
489510
g_systemData.executablePath = cString(getExecutablePath());
490511
g_systemData.executableName = cString(infoDict[@"CFBundleExecutable"]);
@@ -543,6 +564,7 @@ static void addContextualInfoToEvent(KSCrash_MonitorContext *eventContext)
543564
COPY_REFERENCE(kernelVersion);
544565
COPY_REFERENCE(osVersion);
545566
COPY_REFERENCE(isJailbroken);
567+
COPY_REFERENCE(procTranslated);
546568
COPY_REFERENCE(appStartTime);
547569
COPY_REFERENCE(executablePath);
548570
COPY_REFERENCE(executableName);

Sources/KSCrashRecording/include/KSCrashReportFields.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ KSCRF_DEFINE_CONSTANT(KSCrashField, DeviceAppHash, deviceAppHash, "device_app_ha
230230
KSCRF_DEFINE_CONSTANT(KSCrashField, Executable, executable, "CFBundleExecutable")
231231
KSCRF_DEFINE_CONSTANT(KSCrashField, ExecutablePath, executablePath, "CFBundleExecutablePath")
232232
KSCRF_DEFINE_CONSTANT(KSCrashField, Jailbroken, jailbroken, "jailbroken")
233+
KSCRF_DEFINE_CONSTANT(KSCrashField, ProcTranslated, procTranslated, "proc_translated")
233234
KSCRF_DEFINE_CONSTANT(KSCrashField, KernelVersion, kernelVersion, "kernel_version")
234235
KSCRF_DEFINE_CONSTANT(KSCrashField, Machine, machine, "machine")
235236
KSCRF_DEFINE_CONSTANT(KSCrashField, Model, model, "model")

Sources/KSCrashRecordingCore/include/KSCrashMonitorContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ typedef struct KSCrash_MonitorContext {
198198
const char *kernelVersion;
199199
const char *osVersion;
200200
bool isJailbroken;
201+
bool procTranslated;
201202
const char *bootTime;
202203
const char *appStartTime;
203204
const char *executablePath;

0 commit comments

Comments
 (0)