@@ -44,6 +44,11 @@ static void mSDLDeinit(struct mSDLRenderer* renderer);
44
44
45
45
static int mSDLRun (struct mSDLRenderer * renderer , struct mArguments * args );
46
46
47
+ #ifdef USE_PLEDGE
48
+ static bool mPledgeBroad (struct mArguments * args );
49
+ static bool mPledgeNarrow (struct mArguments * args );
50
+ #endif
51
+
47
52
static struct VFile * _state = NULL ;
48
53
49
54
static void _loadState (struct mCoreThread * thread ) {
@@ -149,6 +154,15 @@ int main(int argc, char** argv) {
149
154
renderer .player .bindings = & renderer .core -> inputMap ;
150
155
mSDLInitBindingsGBA (& renderer .core -> inputMap );
151
156
mSDLInitEvents (& renderer .events );
157
+
158
+ #ifdef USE_PLEDGE
159
+ if (!mPledgeBroad (& args )) {
160
+ freeArguments (& args );
161
+ fprintf (stderr , "pledge\n" );
162
+ return 1 ;
163
+ }
164
+ #endif
165
+
152
166
mSDLEventsLoadConfig (& renderer .events , mCoreConfigGetInput (& renderer .core -> config ));
153
167
mSDLAttachPlayer (& renderer .events , & renderer .player );
154
168
mSDLPlayerLoadConfig (& renderer .player , mCoreConfigGetInput (& renderer .core -> config ));
@@ -264,6 +278,12 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
264
278
state -> close (state );
265
279
}
266
280
}
281
+ #ifdef USE_PLEDGE
282
+ if (!mPledgeNarrow (args )) {
283
+ didFail = true;
284
+ fprintf (stderr , "pledge\n" );
285
+ }
286
+ #endif
267
287
renderer -> runloop (renderer , & thread );
268
288
mSDLPauseAudio (& renderer -> audio );
269
289
if (mCoreThreadHasCrashed (& thread )) {
@@ -312,3 +332,43 @@ static void mSDLDeinit(struct mSDLRenderer* renderer) {
312
332
313
333
SDL_Quit ();
314
334
}
335
+
336
+ #ifdef USE_PLEDGE
337
+ static bool mPledgeBroad (struct mArguments * args ) {
338
+ if (args -> debuggerType == DEBUGGER_CLI ) {
339
+ if (pledge ("stdio rpath wpath cpath inet fattr unix dns sendfd prot_exec tty drm audio" , NULL ) == -1 ) {
340
+ return false;
341
+ }
342
+ #ifdef USE_GDB_STUB
343
+ } else if (args -> debuggerType == DEBUGGER_GDB ) {
344
+ if (pledge ("stdio rpath wpath cpath inet fattr unix dns sendfd prot_exec drm audio" , NULL ) == -1 ) {
345
+ return false;
346
+ }
347
+ #endif
348
+ } else {
349
+ if (pledge ("stdio rpath wpath cpath inet fattr unix dns sendfd prot_exec drm audio" , NULL ) == -1 ) {
350
+ return false;
351
+ }
352
+ }
353
+ return true;
354
+ }
355
+
356
+ static bool mPledgeNarrow (struct mArguments * args ) {
357
+ if (args -> debuggerType == DEBUGGER_CLI ) {
358
+ if (pledge ("stdio rpath wpath cpath fattr sendfd tty prot_exec drm audio" , NULL ) == -1 ) {
359
+ return false;
360
+ }
361
+ #ifdef USE_GDB_STUB
362
+ } else if (args -> debuggerType == DEBUGGER_GDB ) {
363
+ if (pledge ("stdio rpath wpath cpath inet fattr sendfd prot_exec drm audio" , NULL ) == -1 ) {
364
+ return false;
365
+ }
366
+ #endif
367
+ } else {
368
+ if (pledge ("stdio rpath wpath cpath fattr sendfd prot_exec drm audio" , NULL ) == -1 ) {
369
+ return false;
370
+ }
371
+ }
372
+ return true;
373
+ }
374
+ #endif
0 commit comments