@@ -18,12 +18,14 @@ #include #include #include +#include #include #include +#include #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" @@ -30,13 +32,15 @@ #import "OFLocalization.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFThread.h" #import "OFThread+Private.h" +#import "OFSandbox.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "OFSandboxActivationFailedException.h" #if defined(OF_MACOS) # include #elif defined(OF_WINDOWS) # include @@ -183,10 +187,17 @@ sceKernelExitGame(); OF_UNREACHABLE #endif } + +#ifdef OF_HAVE_SANDBOX ++ (void)activateSandbox: (OFSandbox*)sandbox +{ + [app activateSandbox: sandbox]; +} +#endif - init { self = [super init]; @@ -501,6 +512,24 @@ { [[self class] terminateWithStatus: status]; OF_UNREACHABLE } + +#ifdef OF_HAVE_SANDBOX +- (void)activateSandbox: (OFSandbox*)sandbox +{ +# ifdef OF_HAVE_PLEDGE + void *pool = objc_autoreleasePoolPush(); + const char *promises = [[sandbox pledgeString] + cStringWithEncoding: [OFLocalization encoding]]; + + if (pledge(promises, NULL) != 0) + @throw [OFSandboxActivationFailedException + exceptionWithSandbox: sandbox + errNo: errno]; + + objc_autoreleasePoolPop(pool); +# endif +} +#endif @end