Skip to content

Commit

Permalink
SystemStats: Add helper function to detect app sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk committed Jan 25, 2023
1 parent 26a872b commit a9a95fe
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
57 changes: 34 additions & 23 deletions examples/Utilities/SystemInfoDemo.h
Expand Up @@ -120,6 +120,11 @@ static String getDisplayInfo()
return displayDesc;
}

static String boolString (bool b)
{
return b ? "yes" : "no";
}

static String getAllSystemInfo()
{
String systemInfo;
Expand Down Expand Up @@ -150,30 +155,36 @@ static String getAllSystemInfo()
<< "CPU vendor: " << SystemStats::getCpuVendor() << newLine
<< "CPU model: " << SystemStats::getCpuModel() << newLine
<< "CPU speed: " << SystemStats::getCpuSpeedInMegahertz() << " MHz" << newLine
<< "CPU has MMX: " << (SystemStats::hasMMX() ? "yes" : "no") << newLine
<< "CPU has FMA3: " << (SystemStats::hasFMA3() ? "yes" : "no") << newLine
<< "CPU has FMA4: " << (SystemStats::hasFMA4() ? "yes" : "no") << newLine
<< "CPU has SSE: " << (SystemStats::hasSSE() ? "yes" : "no") << newLine
<< "CPU has SSE2: " << (SystemStats::hasSSE2() ? "yes" : "no") << newLine
<< "CPU has SSE3: " << (SystemStats::hasSSE3() ? "yes" : "no") << newLine
<< "CPU has SSSE3: " << (SystemStats::hasSSSE3() ? "yes" : "no") << newLine
<< "CPU has SSE4.1: " << (SystemStats::hasSSE41() ? "yes" : "no") << newLine
<< "CPU has SSE4.2: " << (SystemStats::hasSSE42() ? "yes" : "no") << newLine
<< "CPU has 3DNOW: " << (SystemStats::has3DNow() ? "yes" : "no") << newLine
<< "CPU has AVX: " << (SystemStats::hasAVX() ? "yes" : "no") << newLine
<< "CPU has AVX2: " << (SystemStats::hasAVX2() ? "yes" : "no") << newLine
<< "CPU has AVX512F: " << (SystemStats::hasAVX512F() ? "yes" : "no") << newLine
<< "CPU has AVX512BW: " << (SystemStats::hasAVX512BW() ? "yes" : "no") << newLine
<< "CPU has AVX512CD: " << (SystemStats::hasAVX512CD() ? "yes" : "no") << newLine
<< "CPU has AVX512DQ: " << (SystemStats::hasAVX512DQ() ? "yes" : "no") << newLine
<< "CPU has AVX512ER: " << (SystemStats::hasAVX512ER() ? "yes" : "no") << newLine
<< "CPU has AVX512IFMA: " << (SystemStats::hasAVX512IFMA() ? "yes" : "no") << newLine
<< "CPU has AVX512PF: " << (SystemStats::hasAVX512PF() ? "yes" : "no") << newLine
<< "CPU has AVX512VBMI: " << (SystemStats::hasAVX512VBMI() ? "yes" : "no") << newLine
<< "CPU has AVX512VL: " << (SystemStats::hasAVX512VL() ? "yes" : "no") << newLine
<< "CPU has AVX512VPOPCNTDQ: " << (SystemStats::hasAVX512VPOPCNTDQ() ? "yes" : "no") << newLine
<< "CPU has Neon: " << (SystemStats::hasNeon() ? "yes" : "no") << newLine
<< "CPU has MMX: " << boolString (SystemStats::hasMMX() ) << newLine
<< "CPU has FMA3: " << boolString (SystemStats::hasFMA3() ) << newLine
<< "CPU has FMA4: " << boolString (SystemStats::hasFMA4() ) << newLine
<< "CPU has SSE: " << boolString (SystemStats::hasSSE() ) << newLine
<< "CPU has SSE2: " << boolString (SystemStats::hasSSE2() ) << newLine
<< "CPU has SSE3: " << boolString (SystemStats::hasSSE3() ) << newLine
<< "CPU has SSSE3: " << boolString (SystemStats::hasSSSE3() ) << newLine
<< "CPU has SSE4.1: " << boolString (SystemStats::hasSSE41() ) << newLine
<< "CPU has SSE4.2: " << boolString (SystemStats::hasSSE42() ) << newLine
<< "CPU has 3DNOW: " << boolString (SystemStats::has3DNow() ) << newLine
<< "CPU has AVX: " << boolString (SystemStats::hasAVX() ) << newLine
<< "CPU has AVX2: " << boolString (SystemStats::hasAVX2() ) << newLine
<< "CPU has AVX512F: " << boolString (SystemStats::hasAVX512F() ) << newLine
<< "CPU has AVX512BW: " << boolString (SystemStats::hasAVX512BW() ) << newLine
<< "CPU has AVX512CD: " << boolString (SystemStats::hasAVX512CD() ) << newLine
<< "CPU has AVX512DQ: " << boolString (SystemStats::hasAVX512DQ() ) << newLine
<< "CPU has AVX512ER: " << boolString (SystemStats::hasAVX512ER() ) << newLine
<< "CPU has AVX512IFMA: " << boolString (SystemStats::hasAVX512IFMA() ) << newLine
<< "CPU has AVX512PF: " << boolString (SystemStats::hasAVX512PF() ) << newLine
<< "CPU has AVX512VBMI: " << boolString (SystemStats::hasAVX512VBMI() ) << newLine
<< "CPU has AVX512VL: " << boolString (SystemStats::hasAVX512VL() ) << newLine
<< "CPU has AVX512VPOPCNTDQ: " << boolString (SystemStats::hasAVX512VPOPCNTDQ() ) << newLine
<< "CPU has Neon: " << boolString (SystemStats::hasNeon() ) << newLine
<< newLine;

#if JUCE_MAC
systemInfo
<< "Application sandbox enabled: " << boolString (SystemStats::isAppSandboxEnabled()) << newLine
<< newLine;
#endif

systemInfo
<< "Current working directory: " << File::getCurrentWorkingDirectory().getFullPathName() << newLine
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/juce_core.h
Expand Up @@ -40,7 +40,7 @@
minimumCppStandard: 17
dependencies:
OSXFrameworks: Cocoa Foundation IOKit
OSXFrameworks: Cocoa Foundation IOKit Security
iOSFrameworks: Foundation
linuxLibs: rt dl pthread
mingwLibs: uuid wsock32 wininet version ole32 ws2_32 oleaut32 imm32 comdlg32 shlwapi rpcrt4 winmm
Expand Down
34 changes: 34 additions & 0 deletions modules/juce_core/native/juce_mac_SystemStats.mm
Expand Up @@ -371,4 +371,38 @@ uint32 millisecondsSinceStartup() const noexcept
return deviceId;
}

#if JUCE_MAC
bool SystemStats::isAppSandboxEnabled()
{
static const auto result = [&]
{
SecCodeRef ref = nullptr;

if (const auto err = SecCodeCopySelf (kSecCSDefaultFlags, &ref); err != noErr)
return false;

const CFUniquePtr<SecCodeRef> managedRef (ref);
CFDictionaryRef infoDict = nullptr;

if (const auto err = SecCodeCopySigningInformation (managedRef.get(), kSecCSDynamicInformation, &infoDict); err != noErr)
return false;

const CFUniquePtr<CFDictionaryRef> managedInfoDict (infoDict);
const void* entitlementsDict = nullptr;

if (! CFDictionaryGetValueIfPresent (managedInfoDict.get(), kSecCodeInfoEntitlementsDict, &entitlementsDict))
return false;

const void* flag = nullptr;

if (! CFDictionaryGetValueIfPresent (static_cast<CFDictionaryRef> (entitlementsDict), @"com.apple.security.app-sandbox", &flag))
return false;

return static_cast<bool> (CFBooleanGetValue (static_cast<CFBooleanRef> (flag)));
}();

return result;
}
#endif

} // namespace juce
6 changes: 5 additions & 1 deletion modules/juce_core/system/juce_SystemStats.h
Expand Up @@ -228,7 +228,7 @@ class JUCE_API SystemStats final
/** A function type for use in setApplicationCrashHandler().
When called, its void* argument will contain platform-specific data about the crash.
*/
using CrashHandlerFunction = void(*)(void*);
using CrashHandlerFunction = void (*) (void*);

/** Sets up a global callback function that will be called if the application
executes some kind of illegal instruction.
Expand All @@ -243,6 +243,10 @@ class JUCE_API SystemStats final
*/
static bool isRunningInAppExtensionSandbox() noexcept;

#if JUCE_MAC
static bool isAppSandboxEnabled();
#endif

//==============================================================================
#ifndef DOXYGEN
[[deprecated ("This method was spelt wrong! Please change your code to use getCpuSpeedInMegahertz instead.")]]
Expand Down

0 comments on commit a9a95fe

Please sign in to comment.