Skip to content

Commit 888668a

Browse files
authored
Merge pull request #70789 from al45tair/eng/PR-109667503
[Backtracing] Test Developer Mode before allowing interactivity.
2 parents f79dea2 + 7e4bfc9 commit 888668a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

stdlib/public/libexec/swift-backtrace/main.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#if (os(macOS) || os(Linux)) && (arch(x86_64) || arch(arm64))
1414

1515
#if canImport(Darwin)
16-
import Darwin.C
16+
import Darwin
1717
#elseif canImport(Glibc)
1818
import Glibc
1919
#elseif canImport(CRT)
@@ -511,6 +511,22 @@ Generate a backtrace for the parent process.
511511
writeln("Backtrace took \(formattedDuration)s")
512512
writeln("")
513513

514+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
515+
// On Darwin, if Developer Mode is turned off, or we can't tell if it's
516+
// on or not, disable interactivity
517+
var developerMode: Int32 = 0
518+
var developerModeSize: Int = MemoryLayout<Int32>.size
519+
if args.interactive
520+
&& (sysctlbyname("security.mac.amfi.developer_mode_status",
521+
&developerMode,
522+
&developerModeSize,
523+
nil,
524+
0) == -1
525+
|| developerMode == 0) {
526+
args.interactive = false
527+
}
528+
#endif
529+
514530
if args.interactive {
515531
// Make sure we're line buffered
516532
setvbuf(stdout, nil, _IOLBF, 0)

0 commit comments

Comments
 (0)